Skip to content

Commit 4fb717b

Browse files
committed
fix: update frontend image names and improve Dockerfile formatting
1 parent 3c26df4 commit 4fb717b

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ on:
66

77
env:
88
BACKEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-backend
9-
FRONTEND_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend
9+
FRONTEND_STAGING_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend-staging
10+
FRONTEND_PROD_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/mern-chat-app-frontend-prod
1011

1112
jobs:
1213
build:
1314
runs-on: ubuntu-latest
1415
steps:
1516
- name: Checkout code
1617
uses: actions/checkout@v4
18+
1719
- name: Set up Docker Buildx
1820
uses: docker/setup-buildx-action@v3
21+
1922
- name: Log in to Docker Hub
2023
uses: docker/login-action@v3
2124
with:
2225
username: ${{ secrets.DOCKERHUB_USERNAME }}
2326
password: ${{ secrets.DOCKERHUB_TOKEN }}
27+
2428
- name: Build and push backend
2529
uses: docker/build-push-action@v5
2630
with:
@@ -29,12 +33,26 @@ jobs:
2933
tags: ${{ env.BACKEND_IMAGE }}:latest
3034
cache-from: type=gha
3135
cache-to: type=gha,mode=max
32-
- name: Build and push frontend
36+
37+
- name: Build and push frontend (staging)
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: ./Front-end
41+
push: true
42+
tags: ${{ env.FRONTEND_STAGING_IMAGE }}:latest
43+
build-args: |
44+
VITE_SERVER=${{ secrets.STG_VITE_SERVER }}
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max
47+
48+
- name: Build and push frontend (prod)
3349
uses: docker/build-push-action@v5
3450
with:
3551
context: ./Front-end
3652
push: true
37-
tags: ${{ env.FRONTEND_IMAGE }}:latest
53+
tags: ${{ env.FRONTEND_PROD_IMAGE }}:latest
54+
build-args: |
55+
VITE_SERVER=${{ secrets.PROD_VITE_SERVER }}
3856
cache-from: type=gha
3957
cache-to: type=gha,mode=max
4058

@@ -52,9 +70,9 @@ jobs:
5270
timeout: 60s
5371
script: |
5472
cd ~/MERN-CHAT-APP
55-
docker-compose pull
73+
docker compose pull
5674
sleep 5
57-
docker-compose up -d --remove-orphans
75+
docker compose up -d --remove-orphans
5876
docker image prune -f
5977
echo "Staging deployed"
6078
@@ -72,8 +90,8 @@ jobs:
7290
timeout: 60s
7391
script: |
7492
cd ~/MERN-CHAT-APP
75-
docker-compose pull
93+
docker compose pull
7694
sleep 5
77-
docker-compose up -d --remove-orphans
95+
docker compose up -d --remove-orphans
7896
docker image prune -f
7997
echo "Production deployed"

Front-end/Dockerfile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
# ---- Build Stage ----
22
FROM node:24-slim AS build
3-
43
WORKDIR /app
5-
64
# pnpm setup
75
ENV PNPM_HOME="/pnpm"
86
ENV PATH="$PNPM_HOME:$PATH"
97
RUN corepack enable
10-
118
# Copy dependency files first (cache optimization)
129
COPY package.json pnpm-lock.yaml ./
13-
1410
RUN pnpm install --frozen-lockfile
15-
1611
# Copy source code
1712
COPY . .
18-
13+
# Inject build-time env var
14+
ARG VITE_SERVER
15+
ENV VITE_SERVER=$VITE_SERVER
1916
# Build (Vite to /dist)
2017
RUN pnpm build
21-
2218
# ---- Production Stage ----
2319
FROM nginx:alpine
24-
2520
COPY --from=build /app/dist /usr/share/nginx/html
26-
2721
COPY nginx.conf /etc/nginx/conf.d/default.conf
28-
2922
EXPOSE 80
30-
3123
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)