-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
102 lines (78 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
102 lines (78 loc) · 2.42 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# ============================================
# Stage 0: Common base (system dependencies)
# ============================================
FROM elixir:1.15.7-alpine AS base
RUN apk add --no-cache \
build-base \
git \
openssh-client \
postgresql-dev \
&& rm -rf /var/cache/apk/*
WORKDIR /app
RUN mix do local.hex --force, local.rebar --force
# ============================================
# Stage 1: Dependencies (better caching)
# ============================================
FROM base AS deps
# Copy only dependency files first
COPY mix.exs mix.lock ./
RUN --mount=type=ssh mix deps.get --only prod
# ============================================
# Stage 2: Development
# ============================================
FROM base AS dev
# Add only what is specific for development
RUN apk add --no-cache nodejs npm inotify-tools \
&& rm -rf /var/cache/apk/*
COPY mix.exs mix.lock ./
COPY config config
RUN --mount=type=ssh mix deps.get
# The rest will be set up via volume in Compose
# ============================================
# Stage 3: Build (production)
# ============================================
FROM base AS build
# Add only build-specific files
RUN apk add --no-cache nodejs npm \
&& rm -rf /var/cache/apk/*
ARG mix_env=prod
WORKDIR /app
# 1. Dependencies first (better caching)
COPY mix.exs mix.lock ./
RUN --mount=type=ssh mix deps.get --only $mix_env
# 2. Configurations
COPY config config
# 3. Source code
COPY lib lib
COPY priv priv
COPY scripts scripts
# 4. Assets
COPY assets assets
RUN if [ -f "assets/package.json" ]; then \
cd assets && npm ci --omit=dev && \
(npm run deploy || npm run build || true); \
fi
# 5. Compile and make release
RUN MIX_ENV=$mix_env mix compile
RUN MIX_ENV=$mix_env mix release
# ============================================
# Stage 4: Runtime (production – minimal image)
# ============================================
FROM alpine:3.20 AS app
RUN apk add --no-cache \
openssl \
ncurses-libs \
libstdc++ \
ca-certificates \
&& rm -rf /var/cache/apk/*
ARG mix_env=prod
WORKDIR /app
RUN addgroup -g 1000 -S appuser && \
adduser -u 1000 -S appuser -G appuser && \
chown -R appuser:appuser /app
USER appuser:appuser
COPY --from=build --chown=appuser:appuser /app/_build/${mix_env}/rel/sendwise ./
COPY --from=build --chown=appuser:appuser /app/scripts/start.sh ./start.sh
ENV HOME=/app \
PATH=/app/bin:$PATH
CMD ["sh", "./start.sh"]