Skip to content

Commit e23d267

Browse files
committed
Change dockerfile and fly.toml
1 parent 55fa9ad commit e23d267

4 files changed

Lines changed: 88 additions & 60 deletions

File tree

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
node_modules
2-
Dockerfile*
2+
.old.Dockerfile
33
docker-compose*
44
.dockerignore
55
.git

.old.Dockerfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Use an official Node runtime as the base image
2+
FROM node:24-slim AS base
3+
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
33+
COPY package*.json ./
34+
35+
# Install dependencies while bypassing Husky hooks
36+
ENV HUSKY=0
37+
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
38+
RUN mkdir -p .git && npm install
39+
40+
# Copy the rest of the application code
41+
COPY . .
42+
43+
# Build the client-side application
44+
RUN npm run build-prod
45+
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
53+
54+
# Setup supervisor configuration
55+
RUN mkdir -p /var/log/supervisor
56+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
57+
58+
# Copy and make executable the startup script
59+
COPY startup.sh /usr/local/bin/
60+
RUN chmod +x /usr/local/bin/startup.sh
61+
62+
RUN mkdir -p /tmp/.cloudflared && chmod 777 /tmp/.cloudflared
63+
ENV CF_CONFIG_DIR=/tmp/.cloudflared
64+
65+
# Use the startup script as the entrypoint
66+
ENTRYPOINT ["/usr/local/bin/startup.sh"]

Dockerfile

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,31 @@
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
34

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
336
COPY package*.json ./
34-
35-
# Install dependencies while bypassing Husky hooks
36-
ENV HUSKY=0
377
ENV NPM_CONFIG_IGNORE_SCRIPTS=1
38-
RUN mkdir -p .git && npm install
8+
RUN npm ci
399

40-
# Copy the rest of the application code
10+
# 2) Copy all source files and build the app
4111
COPY . .
42-
43-
# Build the client-side application
4412
RUN npm run build-prod
4513

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
5317

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 ./
5722

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
6125

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
6429

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"]

fly.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ primary_region = "cdg"
1212
[[services]]
1313
internal_port = 3000
1414
protocol = "tcp"
15-
16-
# HTTP public on 80 → redirect to 443 TLS
1715
[[services.ports]]
1816
port = 80
1917
handlers = ["http"]
20-
2118
[[services.ports]]
2219
port = 443
23-
handlers = ["tls", "http"]
20+
handlers = ["tls","http"]

0 commit comments

Comments
 (0)