-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.prod
76 lines (60 loc) · 1.72 KB
/
Dockerfile.prod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Use the official Elixir image as the base image
FROM elixir:1.16-alpine as build
# Install build dependencies
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
build-base \
gcc \
git \
make \
libc-dev \
bash \
inotify-tools \
postgresql-client \
erlang-dev
# Set the working directory inside the container
WORKDIR /app
# Install Hex and Rebar
RUN mix local.hex --force && \
mix local.rebar --force
# Set environment to prod for building
ENV MIX_ENV=prod
# Copy over the necessary application files and directories
COPY config/ config/
COPY lib/ lib/
COPY priv/ priv/
COPY assets/ assets/
COPY mix.exs .
COPY mix.lock .
# Fetch the application dependencies and compile the app
RUN mix deps.get --only prod && \
mix deps.compile
# Compile assets and digest them (assuming esbuild or another tool is configured in your mix.exs)
RUN mix assets.deploy && \
mix phx.digest
# Build the release
RUN mix release
# Start a new build stage to create a cleaner final image
FROM alpine:latest
# Install runtime dependencies
RUN apk update && \
apk upgrade --no-cache && \
apk add --no-cache \
bash \
openssl \
ncurses-libs \
postgresql-client \
libstdc++
# Set the working directory inside the container
WORKDIR /app
# Copy the release from the build stage
COPY --from=build /app/_build/prod/rel/website_45s_v3 ./
# Copy the entrypoint script to the container
COPY prod_entrypoint.sh /app/entrypoint.sh
# Make the script executable
RUN chmod +x /app/entrypoint.sh
# Expose port 4000 for the app
EXPOSE 4000
# Use the entrypoint script to run migrations and then start the Phoenix server
ENTRYPOINT ["/app/entrypoint.sh"]