Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
182 lines (140 loc) · 5.1 KB
/
Copy pathDockerfile
File metadata and controls
182 lines (140 loc) · 5.1 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
################################################################################
# Stage 1: Build webapp assets
################################################################################
FROM node:22.21.1-trixie-slim AS webapp-builder
WORKDIR /opt/build
# Install only required dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
build-essential \
git \
python3 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy package files first to leverage Docker cache
COPY webapp/package*.json ./
# Install dependencies
RUN npm ci --no-audit --no-color
# Copy source and build
COPY webapp .
RUN npm run build-production
################################################################################
# Stage 2: Build jipt assets in parallel
################################################################################
FROM node:21.6.1-bullseye-slim AS jipt-builder
WORKDIR /opt/build
# Install only required dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
build-essential \
git \
python3 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy package files first to leverage Docker cache
COPY jipt/package*.json ./
# Install dependencies
RUN npm ci --no-audit --no-color
# Copy source and build
COPY jipt .
RUN npm run build-production
################################################################################
# Stage 3: Build language tool jar in parallel
################################################################################
FROM debian:trixie-slim AS languagetool-builder
WORKDIR /build
# Install only Java runtime
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
default-jre && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy language tool source and build
COPY vendor/language_tool/priv/ vendor/language_tool/priv/
RUN cd ./vendor/language_tool/priv/native/languagetool && ./gradlew shadowJar
# Prepare output directory for next stage
RUN mkdir -p /build/priv/native/ && \
cp ./vendor/language_tool/priv/native/languagetool/app/build/libs/language-tool.jar /build/priv/native/
################################################################################
# Stage 4: Build the OTP binary (Elixir app)
################################################################################
FROM hexpm/elixir:1.19.5-erlang-28.5.0.1-debian-trixie-20260518-slim AS builder
ENV MIX_ENV=prod
WORKDIR /build
# Install only needed build dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
build-essential \
git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Setup Elixir environment
RUN mix local.rebar --force && \
mix local.hex --force
# Copy dependency definitions first to leverage caching
COPY mix.* ./
COPY config config
# Get and compile dependencies
RUN mix deps.get --only prod && \
mix deps.compile --only prod
# Copy application source code
COPY vendor vendor
COPY lib lib
COPY priv priv
# Copy language tool from previous stage
COPY --from=languagetool-builder /build/priv/native/language-tool.jar priv/native/
# Compile the application
RUN mix compile --only prod
# Copy static assets from previous build stages
COPY --from=webapp-builder /opt/build/webapp-dist ./priv/static/webapp
COPY --from=jipt-builder /opt/build/jipt-dist ./priv/static/jipt
# Create the release
RUN mix release && \
mkdir -p /opt/build && \
cp -R _build/prod/rel/accent/* /opt/build
################################################################################
# Final Stage: Create lean runtime container
################################################################################
FROM debian:trixie-slim
# GitHub Container Registry labels
LABEL org.opencontainers.image.source=https://github.com/mirego/accent
LABEL org.opencontainers.image.description="Accent is a developer-oriented tool for translation management"
LABEL org.opencontainers.image.licenses=BSD-3-Clause
# Install only runtime dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
default-jre-headless \
openssl \
ca-certificates \
libncurses6 \
locales \
fontconfig \
hunspell \
hunspell-fr \
hunspell-en-ca \
hunspell-en-us \
hunspell-es && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Configure locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
# Set environment variables
ENV MIX_ENV="prod" \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
# Prepare application directory
WORKDIR /opt/accent
# Create a non-root user for security
RUN chown nobody /opt/accent
# Copy the release from builder stage
COPY --from=builder --chown=nobody:root /opt/build .
# Copy and prepare entrypoint script
COPY priv/scripts/docker-entrypoint.sh /usr/local/bin/
RUN chmod a+x /usr/local/bin/docker-entrypoint.sh
# Switch to non-root user
USER nobody
# Set the entrypoint and default command
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["start"]