Skip to content

Commit 8528a22

Browse files
committed
feat: serve frontend from backend
1 parent b12af4a commit 8528a22

32 files changed

Lines changed: 4382 additions & 57942 deletions

.dockerignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.classpath
8+
**/.dockerignore
9+
**/.env
10+
**/.git
11+
**/.gitignore
12+
**/.project
13+
**/.settings
14+
**/.toolstarget
15+
**/.vs
16+
**/.vscode
17+
**/.next
18+
**/.cache
19+
**/*.*proj.user
20+
**/*.dbmdl
21+
**/*.jfm
22+
**/charts
23+
**/docker-compose*
24+
**/compose.y*ml
25+
**/Dockerfile*
26+
**/node_modules
27+
**/npm-debug.log
28+
**/obj
29+
**/secrets.dev.yaml
30+
**/values.dev.yaml
31+
**/build
32+
**/dist
33+
LICENSE
34+
README.md

.github/workflows/docker-build-manual.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ jobs:
7070
- name: Build & Push Backend
7171
uses: docker/build-push-action@v5
7272
with:
73-
context: ./backend
74-
file: backend/Dockerfile
73+
context: .
74+
file: ./Dockerfile.app
7575
platforms: linux/arm64
7676
push: true
77-
tags: sunjay195/cron-job-backend:latest
77+
tags: sunjay195/cron-job-app:latest
7878
cache-from: type=gha
7979
cache-to: type=gha,mode=max
8080
labels: |

.github/workflows/docker-build-push.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,22 @@ jobs:
7575
- name: Set up Docker Buildx
7676
uses: docker/setup-buildx-action@v3
7777

78-
- name: Prepare metadata
79-
id: meta
80-
run: |
81-
msg=$(echo "${{ github.event.head_commit.message }}" | head -n1)
82-
msg=${msg// /_}
83-
echo "short_msg=$msg" >> $GITHUB_OUTPUT
84-
echo "short_sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
85-
8678
- name: Docker Hub Login
87-
uses: docker/login-action@v3
79+
uses: docker/login-action@v4
8880
with:
8981
username: ${{ secrets.DOCKER_USERNAME }}
9082
password: ${{ secrets.DOCKER_PASSWORD }}
9183

9284
- name: Build & Push Backend
9385
uses: docker/build-push-action@v5
9486
with:
95-
context: ./backend
87+
context: .
88+
file: ./Dockerfile.app
9689
platforms: linux/arm64
9790
push: true
98-
tags: sunjay195/cron-job-backend:latest
91+
tags: sunjay195/cron-job-app:latest
9992
cache-from: type=gha
10093
cache-to: type=gha,mode=max
101-
labels: |
102-
git_commit_sha=${{ github.sha }}
103-
git_commit_short=${{ steps.meta.outputs.short_sha }}
104-
git_commit_msg=${{ steps.meta.outputs.short_msg }}
10594

10695
job-runner:
10796
needs: changes

Dockerfile.app

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
ARG NODE_VERSION=24.11.0-alpine
2+
ARG PNPM_VERSION=10.32.1
3+
4+
# --------------------- Base Stage ----------------
5+
FROM node:${NODE_VERSION} AS base
6+
7+
ARG PNPM_VERSION
8+
9+
RUN corepack enable
10+
RUN corepack prepare pnpm@${PNPM_VERSION} --activate
11+
12+
WORKDIR /app
13+
14+
# --------------------- Client Builder Stage ----------------
15+
FROM base AS client-builder
16+
17+
COPY frontend/package.json frontend/pnpm-lock.yaml ./
18+
RUN pnpm install --frozen-lockfile --ignore-scripts
19+
20+
COPY frontend/ ./
21+
RUN pnpm build
22+
23+
# --------------------- Server Builder Stage ----------------
24+
FROM base AS server-builder
25+
26+
WORKDIR /app
27+
COPY backend/package.json backend/pnpm-lock.yaml ./
28+
RUN pnpm install --frozen-lockfile --ignore-scripts
29+
30+
COPY backend/ ./
31+
RUN pnpm build
32+
33+
# --------------------- Prod Deps Stage ---------------------
34+
FROM base AS prod-deps
35+
36+
WORKDIR /app
37+
COPY backend/package.json backend/pnpm-lock.yaml ./
38+
39+
RUN pnpm install --prod --frozen-lockfile --ignore-scripts
40+
41+
# --------------------- Runner Stage ----------------
42+
FROM node:${NODE_VERSION} AS runner
43+
44+
WORKDIR /app
45+
46+
COPY --from=prod-deps /app/node_modules ./node_modules
47+
COPY --from=server-builder /app/dist ./dist
48+
COPY --from=client-builder /app/dist ./dist/public
49+
50+
ENV NODE_ENV=production
51+
ENV PORT=3000
52+
53+
EXPOSE 3000
54+
55+
# Run server
56+
CMD ["node", "./dist/src/server.js"]

backend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG NODE_VERSION=24.11.0
2-
ARG PNPM_VERSION=10.32.1
2+
ARG PNPM_VERSION=10.33.1
33

44
# =================== base stage ============================================
55
FROM node:${NODE_VERSION}-alpine AS base

0 commit comments

Comments
 (0)