Skip to content

Commit a371e38

Browse files
authored
Update to node 24 (#314)
Upgrade project to Node 24 & Update Dockerfiles to multi-stage build
1 parent 5d5821c commit a371e38

File tree

6 files changed

+3570
-21529
lines changed

6 files changed

+3570
-21529
lines changed

.github/workflows/build_main.yml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,38 @@ name: Deploy Live
66
on:
77
push:
88
branches: [main]
9-
# pull_request:
10-
# branches: [ main ]
9+
workflow_dispatch:
1110

1211
jobs:
1312
build:
1413
runs-on: ubuntu-latest
1514

1615
steps:
1716
- uses: actions/checkout@v4
18-
- name: Setup Node.js 16
19-
uses: actions/setup-node@v4
20-
with:
21-
node-version: "16"
22-
cache: "npm"
23-
- run: npm i -g @quasar/cli@latest
24-
- run: npm ci
2517

2618
- name: Create env file
2719
run: |
2820
cat << EOF >> .env.production.local
2921
${{ secrets.ENV_FILE }}
3022
EOF
3123
32-
- run: quasar build -m ssr --if-present
33-
3424
- # Login against GitHub Container Registry
3525
name: Log in to GitHub Container Registry
36-
uses: docker/login-action@v3
26+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
3727
with:
3828
registry: ghcr.io
3929
username: ${{ github.actor }}
4030
password: ${{ secrets.GITHUB_TOKEN }}
4131

32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
34+
4235
- # Build and push Docker image
4336
name: Build and push
44-
uses: docker/build-push-action@v6
37+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
4538
with:
4639
context: .
4740
push: true
4841
tags: ghcr.io/harmlesskey/harmlesskey
42+
cache-from: type=gha,scope=live
43+
cache-to: type=gha,scope=live,mode=max

.github/workflows/build_staging.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,30 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v4
19-
- name: Setup Node.js 16
20-
uses: actions/setup-node@v4
21-
with:
22-
node-version: "16"
23-
cache: "npm"
24-
- run: npm i -g @quasar/cli@latest
25-
- run: npm ci
2619

27-
- name: Create public env file
20+
- name: Create env file
2821
run: |
2922
cat << EOF >> .env.production.local
3023
${{ secrets.STAGING_ENV_FILE }}
3124
EOF
3225
33-
- run: quasar build -m ssr -d --if-present
34-
3526
- # Login against GitHub Container Registry
3627
name: Log in to GitHub Container Registry
37-
uses: docker/login-action@v3
28+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
3829
with:
3930
registry: ghcr.io
4031
username: ${{ github.actor }}
4132
password: ${{ secrets.GITHUB_TOKEN }}
4233

34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
36+
4337
- # Build and push Docker image
4438
name: Build and push
45-
uses: docker/build-push-action@v6
39+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
4640
with:
4741
context: .
4842
push: true
4943
tags: ghcr.io/harmlesskey/harmlesskey_staging
44+
cache-from: type=gha,scope=staging
45+
cache-to: type=gha,scope=staging,mode=max

Dockerfile

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
FROM node:16
1+
# --------- Build Stage ---------
2+
FROM node:24-slim AS build
23

34
WORKDIR /app
45

5-
COPY ./dist/ssr .
6-
COPY .env.production.local .
6+
# Install deps first (for better caching)
7+
COPY package*.json ./
8+
RUN npm ci
79

8-
RUN npm i
9-
RUN npm install pm2 -g
10+
# Copy source and env
11+
COPY . .
12+
13+
# Build Quasar SSR
14+
RUN npx quasar build -m ssr
15+
16+
# --------- Runtime Stage ---------
17+
FROM node:24-slim AS runtime
18+
19+
WORKDIR /app
20+
21+
# Copy SSR dist from build stage
22+
COPY --from=build /app/dist/ssr ./
23+
24+
# Install only production dependencies
25+
RUN npm install --ignore-scripts
26+
27+
# Install PM2 globally
28+
RUN npm install -g pm2
29+
30+
# Set PM2 home to app directory
31+
ENV PM2_HOME=/app/.pm2
32+
33+
# Create non-root user and set ownership
34+
RUN groupadd -r nodeuser && useradd -r -g nodeuser nodeuser \
35+
&& mkdir -p /app/.pm2 \
36+
&& chown -R nodeuser:nodeuser /app
37+
38+
USER nodeuser
39+
40+
EXPOSE 3000
41+
42+
ENV UV_THREADPOOL_SIZE=1
1043

1144
ENTRYPOINT ["pm2-runtime", "index.js"]

0 commit comments

Comments
 (0)