|
1 | | -# Use an official Node runtime as the base image |
2 | | -FROM node:24-slim AS base |
| 1 | +# === builder stage === |
| 2 | +FROM node:24-slim AS builder |
| 3 | +WORKDIR /app |
3 | 4 |
|
4 | | -# Create dependency layer |
5 | | -FROM base AS dependencies |
6 | | -RUN apt-get update && apt-get install -y \ |
7 | | - nginx \ |
8 | | - supervisor \ |
9 | | - git \ |
10 | | - curl \ |
11 | | - jq \ |
12 | | - wget \ |
13 | | - apache2-utils \ |
14 | | - && rm -rf /var/lib/apt/lists/* |
15 | | - |
16 | | -RUN curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb > cloudflared.deb \ |
17 | | - && dpkg -i cloudflared.deb \ |
18 | | - && rm cloudflared.deb |
19 | | - |
20 | | -# Final image |
21 | | -FROM base |
22 | | - |
23 | | -# Copy installed packages from dependencies stage |
24 | | -COPY --from=dependencies / / |
25 | | - |
26 | | -ARG GIT_COMMIT=unknown |
27 | | -ENV GIT_COMMIT=$GIT_COMMIT |
28 | | - |
29 | | -# Set the working directory in the container |
30 | | -WORKDIR /usr/src/app |
31 | | - |
32 | | -# Copy package.json and package-lock.json |
| 5 | +# 1) Install dependencies and prepare the environment |
33 | 6 | COPY package*.json ./ |
34 | | - |
35 | | -# Install dependencies while bypassing Husky hooks |
36 | | -ENV HUSKY=0 |
37 | 7 | ENV NPM_CONFIG_IGNORE_SCRIPTS=1 |
38 | | -RUN mkdir -p .git && npm install |
| 8 | +RUN npm ci |
39 | 9 |
|
40 | | -# Copy the rest of the application code |
| 10 | +# 2) Copy all source files and build the app |
41 | 11 | COPY . . |
42 | | - |
43 | | -# Build the client-side application |
44 | 12 | RUN npm run build-prod |
45 | 13 |
|
46 | | -# So we can see which commit was used to build the container |
47 | | -# https://openfront.io/commit.txt |
48 | | -RUN echo $GIT_COMMIT > static/commit.txt |
49 | | - |
50 | | -# Copy Nginx configuration and ensure it's used instead of the default |
51 | | -COPY nginx.conf /etc/nginx/conf.d/default.conf |
52 | | -RUN rm -f /etc/nginx/sites-enabled/default |
| 14 | +# === runtime stage === |
| 15 | +FROM node:24-slim AS runner |
| 16 | +WORKDIR /app |
53 | 17 |
|
54 | | -# Setup supervisor configuration |
55 | | -RUN mkdir -p /var/log/supervisor |
56 | | -COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf |
| 18 | +# 3) Copy built files and necessary configurations from the builder stage |
| 19 | +COPY --from=builder /app/dist ./dist |
| 20 | +COPY --from=builder /app/out ./out |
| 21 | +COPY --from=builder /app/package*.json ./ |
57 | 22 |
|
58 | | -# Copy and make executable the startup script |
59 | | -COPY startup.sh /usr/local/bin/ |
60 | | -RUN chmod +x /usr/local/bin/startup.sh |
| 23 | +# 4) Install production dependencies only |
| 24 | +RUN npm ci --production |
61 | 25 |
|
62 | | -RUN mkdir -p /tmp/.cloudflared && chmod 777 /tmp/.cloudflared |
63 | | -ENV CF_CONFIG_DIR=/tmp/.cloudflared |
| 26 | +# 5) Config environment variables |
| 27 | +ENV PORT=3000 |
| 28 | +EXPOSE 3000 |
64 | 29 |
|
65 | | -# Use the startup script as the entrypoint |
66 | | -ENTRYPOINT ["/usr/local/bin/startup.sh"] |
| 30 | +# 6) Launch the application |
| 31 | +CMD ["node", "dist/server/Server.js"] |
0 commit comments