Skip to content

Commit 32fb720

Browse files
I've made a change to address a Docker build failure. Here's what I did:
**Fix: Provide build-time SECRET_KEY_BASE for Docker builds** This update resolves an issue where Docker builds were failing. This happened because the `SECRET_KEY_BASE` environment variable wasn't set when `MIX_ENV=prod`, which prevented `mix deps.compile` (and then `mix compile`) from succeeding. Here are the details of the changes: 1. **Dockerfile Modification**: - I added an `ENV SECRET_KEY_BASE="..."` line in the `Dockerfile` before any Elixir compilation steps. This sets a temporary, placeholder secret that's good enough for the build process. I made sure the key is long enough to satisfy Phoenix's requirements. 2. **Documentation**: - I updated the `README.md` in the "Deployment Notes" section. It now explains how `SECRET_KEY_BASE` is managed: a placeholder key is used during the build, and it's important for you to provide a strong, unique key through environment variables when you deploy (for example, in Render). This adjustment ensures that the Docker image can be built successfully when `MIX_ENV=prod` is set. This allows compilation tasks that rely on `SECRET_KEY_BASE` to finish. You will still need to provide the actual runtime `SECRET_KEY_BASE` through your deployment environment.
1 parent 852ec6f commit 32fb720

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ ENV PORT=4000
1818
# This includes the 'topics/' directory, mix files, config, lib, assets, etc.
1919
COPY . .
2020

21+
# Provide a dummy SECRET_KEY_BASE for compilation, must be at least 64 bytes long for prod.
22+
# This will be overridden by the runtime environment variable on Render.
23+
ENV SECRET_KEY_BASE="dummy_build_time_secret_key_base_must_be_at_least_64_bytes_long_for_prod_build_0123456789"
24+
2125
# Install Elixir dependencies
2226
# --force is used to ensure local hex and rebar are up-to-date
2327
RUN mix local.hex --force && \

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@
7070
## Deployment Notes
7171

7272
The `topics/` directory, which contains all the code examples, is crucial for the application's functionality. The provided `Dockerfile` ensures that this directory is copied into the Docker image during the build process. The application then locates this directory at runtime using application-aware path construction (specifically, `Path.join(Application.app_dir(:code_comparison), "topics")`), making its access reliable in containerized environments like Render.
73+
74+
### `SECRET_KEY_BASE` Handling
75+
76+
The `SECRET_KEY_BASE` environment variable is critical for Phoenix applications.
77+
- **Build Time**: The `Dockerfile` includes a temporary, dummy `SECRET_KEY_BASE` to ensure that asset compilation and other build tasks complete successfully when `MIX_ENV=prod`.
78+
- **Runtime**: For your actual deployment on Render (or any other hosting environment), you **must** set a unique and strong `SECRET_KEY_BASE` as an environment variable. This runtime variable will be used by the running application, overriding the temporary one used during the build. You can generate a new secret using `mix phx.gen.secret`.

0 commit comments

Comments
 (0)