Prod releases do not work

#8 · closed · 5 comments

View on GitHub ↗

joseph-lozano

Hi, First off thanks for the awesome template. I am running into an issue with releasing to prod. From a fresh clone and copying over the .env, and .override files, change `MIX_ENV` and `NODE_ENV` in `.env` to `prod` and `production` respectively, then run `docker compose up --build` I see this error: ``` web_1 | /app/bin/docker-entrypoint-web: line 9: /app/bin/hello: No such file or directory ``` Currently spinning my wheels trying to figure this out.

Comments

nickjj

Hi, The binary name should be `/app/bin/rename-project`. I'm not sure how it got named to be `hello`? But that might not be the source of this issue since a new `hello` binary should have been created when creating a new release. That gets called at the bottom of the Dockerfile `CMD ["bin/hello", "start"]` when you run a release. Also what happens if you `build` it then `up` it separately?

joseph-lozano

thanks @nickjj . Same error when I run `build` and `up` separately. I changed the file line of the `Dockerfile` to `CMD [ "ls", "bin"]`, and it showed. ``` web_1 | docker-entrypoint-web rename-project ``` Somehow the line `COPY --chown=elixir:elixir --from=dev /mix/_build/prod/rel/hello ./` isn't copying. The release is being build in the `dev ` stage though...

joseph-lozano

solved.... ish? changing the `WORKDIR` of the `prod` stage to something other than `app` seems to do the trick. I guess there is some kind of collision happening between the stages? Not really sure what is going on. here is the end of the new dockerfile that seems to work ``` ############################################################################### FROM elixir:1.13.3-slim AS prod LABEL maintainer="Nick Janetakis <[email protected]>" WORKDIR /prod RUN apt-get update \ && apt-get install -y --no-install-recommends curl \ && rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \ && apt-get clean \ && useradd --create-home elixir \ && chown elixir:elixir -R /prod USER elixir ENV USER=elixir COPY --chown=elixir:elixir --from=dev /public /public COPY --chown=elixir:elixir --from=dev /mix/_build/prod/rel/hello ./ COPY --chown=elixir:elixir bin/docker-entrypoint-web bin/ ENTRYPOINT ["/prod/bin/docker-entrypoint-web"] EXPOSE 8000 CMD ["bin/hello", "start"] ``` This is pretty unsatisfying though, and I would love to know what is going on, and why there is a collision with the `/app` workdir

nickjj

I'm not able to reproduce your issue but I tested things here and it all worked with the code directly from the repo. I have a hunch the second part of step 1 below is causing your issue. If you volume mount everything the release isn't going to exist because the release only exists in the Docker image, it was never volume mounted out (this is normal / expected) which means your dev box's file system doesn't have the release which overrides what's in the image at runtime. Changing the `WORKDIR` allowed the release to exist in a non-volume mounted location. Here's the steps I took: #### 1. In `.env`, make sure the prod related env vars are set and you disabled the main app volume: We need to set things to production because it bundles and digests our static files and the Dockerfile is configured to create a release when `MIX_ENV` is set to prod. We don't want to volume mount everything in prod because we wouldn't have live reloading in prod, it also conflicts with our built release that only exists in the Docker image. We only need to volume mount the `./public` directory which is set up by default (check the `docker-compose.yml` file). ```sh export MIX_ENV=prod export NODE_ENV=production #export DOCKER_WEB_VOLUME=.:/app ``` #### 2. Make sure esbuild and tailwind's watchers don't run: Both of these containers don't need run because static files will already be bundled and digested. ```sh mv docker-compose.override.yml docker-compose.override.yml.bak ``` #### 3. Build and start everything: We need to rebuild because `MIX_ENV` and `NODE_ENV` change the behavior of what gets built based on the Dockerfile. ```sh docker-compose build docker-compose up ``` #### Confirm it works: Head over to http://localhost:8000 and you should see it's running in "release" mode and all static files are digested. You can also run `./run prod:remote` to connect to IEX remotely and `./run prod:migrate` to migrate the DB.

joseph-lozano

brilliant! the volumes:/app being the source of the problem (in prod makes a lot a sense) Commenting out that line fixed it and makes a lot of sense 🙇