Skip to content

Commit e6eb5f2

Browse files
committed
create dockerfile for dev environment
1 parent 41eb605 commit e6eb5f2

File tree

4 files changed

+125
-47
lines changed

4 files changed

+125
-47
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Frontend - Build and Deploy on Azure
2+
3+
on:
4+
push:
5+
branches: [ development ]
6+
paths:
7+
- 'frontend/**'
8+
- '.github/workflows/azure-deploy-frontend-dev.yml'
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
FRONTEND_IMAGE_NAME: ${{ github.repository }}-frontend-dev
14+
15+
jobs:
16+
build-and-push:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
packages: write
21+
outputs:
22+
short_sha: ${{ steps.extract-sha.outputs.short_sha }}
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Extract short SHA
29+
id: extract-sha
30+
run: |
31+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
32+
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
33+
echo "Using short SHA: $SHORT_SHA"
34+
35+
- name: Log in to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract Docker metadata
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}
47+
tags: |
48+
type=sha,format=short
49+
type=ref,event=branch
50+
latest
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: ./frontend
56+
file: ./frontend/Dockerfile
57+
push: true
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
61+
deploy:
62+
needs: build-and-push
63+
runs-on: ubuntu-latest
64+
environment: production
65+
66+
steps:
67+
- name: Azure login
68+
uses: azure/login@v2
69+
with:
70+
creds: ${{ secrets.AZURE_CREDENTIALS }}
71+
72+
- name: Deploy to Azure Container Apps
73+
id: deploy
74+
uses: azure/container-apps-deploy-action@v2
75+
with:
76+
registryUrl: ${{ env.REGISTRY }}
77+
registryUsername: ${{ github.actor }}
78+
registryPassword: ${{ secrets.GHCR_PASS }}
79+
containerAppName: mploy-frontend-dev
80+
resourceGroup: ${{ secrets.AZURE_RESOURCE_GROUP }}
81+
imageToDeploy: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:sha-${{ needs.build-and-push.outputs.short_sha }}
82+
targetPort: 3000

.github/workflows/azure-static-web-apps-lively-desert-03e284d00.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

frontend/Dockerfile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frontend/Dockerfile
2+
FROM node:20-alpine AS base
3+
4+
# Install dependencies only when needed
5+
FROM base AS deps
6+
WORKDIR /app
7+
8+
# Copy package files
9+
COPY package.json package-lock.json* ./
10+
RUN npm ci
11+
12+
# Rebuild the source code only when needed
13+
FROM base AS builder
14+
WORKDIR /app
15+
COPY --from=deps /app/node_modules ./node_modules
16+
COPY . .
17+
18+
# Build the application
19+
RUN npm run build
20+
21+
# Production image, copy all the files and run next
22+
FROM base AS runner
23+
WORKDIR /app
24+
25+
ENV NODE_ENV production
26+
27+
# Create a non-root user and give them ownership
28+
RUN addgroup --system --gid 1001 nodejs
29+
RUN adduser --system --uid 1001 nextjs
30+
USER nextjs
31+
32+
# Copy built assets from builder stage
33+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
34+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
35+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
36+
37+
EXPOSE 3000
38+
39+
ENV PORT 3000
40+
ENV HOSTNAME "0.0.0.0"
41+
42+
CMD ["node", "server.js"]

frontend/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4-
/* config options here */
4+
output: 'standalone',
55
};
66

77
export default nextConfig;

0 commit comments

Comments
 (0)