Skip to content

Commit 7f7dda1

Browse files
committed
Build and publish frontend Docker container
1 parent 3726f34 commit 7f7dda1

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish frontend
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
publish:
9+
name: Publish frontend
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out the repo
13+
uses: actions/checkout@v4
14+
- name: Install Docker credentials
15+
run: echo "${GITHUB_TOKEN}" | docker login ghcr.io -u $ --password-stdin
16+
env:
17+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18+
- name: Build and push
19+
uses: docker/build-push-action@v4
20+
with:
21+
context: frontend
22+
file: ./frontend/Dockerfile
23+
push: true
24+
tags: ghcr.io/buildbarn/bb-portal-frontend:${{ github.sha }}

.github/workflows/frontend-pr.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build frontend
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
7+
jobs:
8+
publish:
9+
name: Build frontend
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out the repo
13+
uses: actions/checkout@v4
14+
- name: Install Docker credentials
15+
run: echo "${GITHUB_TOKEN}" | docker login ghcr.io -u $ --password-stdin
16+
env:
17+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
18+
- name: Build
19+
uses: docker/build-push-action@v4
20+
with:
21+
context: frontend
22+
file: ./frontend/Dockerfile
23+
push: false
24+
tags: ghcr.io/buildbarn/bb-portal-frontend:${{ github.sha }}

frontend/Dockerfile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
FROM node:22-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
COPY package.json pnpm-lock.yaml ./
10+
RUN corepack enable pnpm && pnpm i --frozen-lockfile
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+
RUN corepack enable pnpm && pnpm run build
19+
20+
# Production image, copy all the files and run next
21+
FROM base AS runner
22+
WORKDIR /app
23+
24+
ENV NODE_ENV=production
25+
26+
RUN addgroup --system --gid 1001 nodejs
27+
RUN adduser --system --uid 1001 nextjs
28+
29+
RUN mkdir .next
30+
RUN chown nextjs:nodejs .next
31+
32+
# Automatically leverage output traces to reduce image size
33+
# https://nextjs.org/docs/advanced-features/output-file-tracing
34+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
35+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
36+
37+
USER nextjs
38+
39+
EXPOSE 3000
40+
41+
ENV PORT=3000
42+
43+
# server.js is created by next build from the standalone output
44+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
45+
ENV HOSTNAME="0.0.0.0"
46+
CMD ["node", "server.js"]

0 commit comments

Comments
 (0)