Skip to content

Commit 741f665

Browse files
committed
fix dockerfile
1 parent e6dd4f4 commit 741f665

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Using hexpm/elixir:1.11.4-erlang-23.2.7.2-alpine-3.13.3 as the base image
2-
FROM hexpm/elixir:1.11.4-erlang-23.2.7.2-alpine-3.13.3 AS base
1+
# Using elixir:1.18.3-otp-27-slim as the base image
2+
FROM elixir:1.18.3-otp-27-slim AS base
33

44
# Set the working directory in the container
55
WORKDIR /code_comparison
@@ -8,7 +8,10 @@ WORKDIR /code_comparison
88
# npm is needed for asset building.
99
# inotify-tools is often for development (auto-reload), might not be strictly needed for a prod build,
1010
# but keeping it as per original Dockerfile's intent for now.
11-
RUN apk add --no-cache npm inotify-tools
11+
RUN apt-get update && \
12+
apt-get install -y npm inotify-tools && \
13+
apt-get clean && \
14+
rm -rf /var/lib/apt/lists/*
1215

1316
# Set environment variables for production
1417
ENV MIX_ENV=prod
@@ -18,16 +21,15 @@ ENV PORT=4000
1821
# This includes the 'topics/' directory, mix files, config, lib, assets, etc.
1922
COPY . .
2023

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+
# Generate a temporary SECRET_KEY_BASE for build time
25+
RUN mix phx.gen.secret > /tmp/secret_key_base
2426

2527
# Install Elixir dependencies
2628
# --force is used to ensure local hex and rebar are up-to-date
2729
RUN mix local.hex --force && \
2830
mix local.rebar --force && \
2931
mix deps.get --only prod && \
30-
mix deps.compile
32+
SECRET_KEY_BASE=$(cat /tmp/secret_key_base) mix deps.compile
3133

3234
# Build frontend assets
3335
# This assumes your assets/package.json has a "deploy" script.
@@ -42,8 +44,11 @@ RUN npm install --prefix ./assets && \
4244

4345
# Compile the Phoenix application and digest assets
4446
# phx.digest prepares static assets (CSS, JS, images) for production.
45-
RUN mix phx.digest && \
46-
mix compile
47+
RUN SECRET_KEY_BASE=$(cat /tmp/secret_key_base) mix phx.digest && \
48+
SECRET_KEY_BASE=$(cat /tmp/secret_key_base) mix compile
49+
50+
# Clean up the temporary secret key
51+
RUN rm /tmp/secret_key_base
4752

4853
# Expose the port the application will run on
4954
EXPOSE ${PORT}

0 commit comments

Comments
 (0)