Skip to content

Commit fa947c1

Browse files
committed
Implement caching properly for both dev and prod workflows and dockerfiles
1 parent 3bdf5a2 commit fa947c1

File tree

9 files changed

+47
-43
lines changed

9 files changed

+47
-43
lines changed

.github/workflows/azure-acr-deploy-frontend-dev.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
with:
25+
driver-opts: |
26+
image=moby/buildkit:latest
27+
network=host
28+
2229
- name: Log in to Azure Container Registry
2330
uses: docker/login-action@v3
2431
with:

.github/workflows/azure-acr-deploy-frontend-prod.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
2121

22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
with:
25+
driver-opts: |
26+
image=moby/buildkit:latest
27+
network=host
28+
2229
- name: Log in to Azure Container Registry
2330
uses: docker/login-action@v3
2431
with:

frontend/Dockerfile

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
# frontend/Dockerfile
21
FROM node:20-alpine AS base
3-
4-
# Install dependencies only when needed
5-
FROM base AS deps
62
WORKDIR /app
73

8-
# Copy package files
4+
FROM base AS deps
95
COPY package.json package-lock.json* ./
10-
RUN npm ci
6+
RUN npm ci --omit=dev
117

12-
# Rebuild the source code only when needed
138
FROM base AS builder
14-
WORKDIR /app
159
COPY --from=deps /app/node_modules ./node_modules
16-
COPY . .
17-
18-
# Build the application
10+
COPY tsconfig.json next.config.ts ./
11+
COPY public ./public
12+
COPY src ./src
1913
RUN npm run build
2014

21-
# Production image, copy all the files and run next
2215
FROM base AS runner
2316
WORKDIR /app
17+
ENV NODE_ENV=production
2418

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
19+
# Create non-root user
20+
RUN addgroup --system --gid 1001 nodejs \
21+
&& adduser --system --uid 1001 nextjs
3022
USER nextjs
3123

32-
# Copy built assets from builder stage
24+
# Copy built assets
3325
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
3426
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
27+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
3528

3629
EXPOSE 3000
30+
ENV PORT=3000
31+
ENV HOSTNAME=0.0.0.0
3732

38-
ENV PORT 3000
39-
ENV HOSTNAME "0.0.0.0"
40-
41-
CMD ["node", "server.js"]
33+
CMD ["node", "server.js"]

frontend/Dockerfile.dev

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
FROM node:20-alpine AS base
2+
WORKDIR /app
23

3-
# Install dependencies only when needed
44
FROM base AS deps
5-
WORKDIR /app
65
COPY package.json package-lock.json* ./
76
RUN npm ci
87

9-
# Rebuild the source code only when needed
108
FROM base AS builder
11-
WORKDIR /app
129
COPY --from=deps /app/node_modules ./node_modules
13-
COPY . .
10+
COPY tsconfig.json next.config.ts ./
11+
COPY public ./public
12+
COPY src ./src
1413
RUN npm run build
1514

16-
# Dev/Staging image: Built app with dev logging
1715
FROM base AS runner
1816
WORKDIR /app
19-
2017
ENV NODE_ENV=development
2118

22-
# Install runtime deps (including pino-pretty for transport) - but not used now
23-
COPY package.json package-lock.json* ./
24-
RUN npm ci --only=production && npm install pino-pretty # Keep for potential future use
19+
# Copy runtime deps from deps stage (no double install!)
20+
COPY --from=deps /app/node_modules ./node_modules
21+
22+
# Optionally include dev tool
23+
RUN npm install --global pino-pretty
2524

26-
# Copy built assets from builder
25+
# Copy built assets
2726
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
2827
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
28+
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
2929

3030
# Create non-root user
31-
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
31+
RUN addgroup --system --gid 1001 nodejs \
32+
&& adduser --system --uid 1001 nextjs
3233
USER nextjs
3334

3435
EXPOSE 3000
35-
ENV PORT 3000
36-
ENV HOSTNAME "0.0.0.0"
36+
ENV PORT=3000
37+
ENV HOSTNAME=0.0.0.0
3738

38-
CMD ["npm", "start"]
39+
CMD ["npm", "start"]

frontend/src/app/jobs/[id]/page.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { notFound } from "next/navigation";
55
import { Job } from "@/types/job";
66
import JobDetailsWrapper from "@/components/jobs/job-details-wrapper";
77
import { Metadata } from "next";
8-
import OgImage from "@/assets/OgImage.png";
98

109
type Props = {
1110
params: Promise<{ id: string }>;
@@ -38,7 +37,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
3837
description,
3938
images: [
4039
{
41-
url: OgImage.src,
40+
url: "/OgImage.png",
4241
alt: title,
4342
},
4443
],

frontend/src/app/layout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { Metadata } from "next";
2121
import FeedbackButton from "@/components/ui/feedback-button";
2222
import { Notifications } from "@mantine/notifications";
2323

24-
import OgImage from "../assets/OgImage.png";
2524
import FirstVisitNotification from "@/components/ui/first-visit-notification";
2625

2726
export const metadata: Metadata = {
@@ -34,7 +33,7 @@ export const metadata: Metadata = {
3433
description: "Stay ahead with the job board that never sleeps.",
3534
images: [
3635
{
37-
url: OgImage.src,
36+
url: "/OgImage.png",
3837
alt: "MAC Jobs Board",
3938
},
4039
],

frontend/src/components/layout/logo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import MacLogo from "@/assets/mac.svg";
21
import Image from "next/image";
32
import Link from "next/link";
43

54
export default function Logo() {
65
return (
76
<Link href="/" className="flex space-x-3 items-center h-8 cursor-pointer">
8-
<Image src={MacLogo} className="h-10 w-10" alt="MAC Logo" />
7+
<Image src="/mac.svg" className="h-10 w-10" alt="MAC Logo" />
98
<span className="text-lg lg:text-xl">Jobs</span>
109
</Link>
1110
);

0 commit comments

Comments
 (0)