Skip to content

Commit

Permalink
Merge pull request #18 from buildbarn/docker
Browse files Browse the repository at this point in the history
Build and publish frontend Docker container
  • Loading branch information
mortenmj authored Oct 11, 2024
2 parents 3726f34 + 2e6fe03 commit 51d7004
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/frontend-master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish frontend

on:
push:
branches: ["main"]

jobs:
publish:
name: Publish frontend
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Install Docker credentials
run: echo "${GITHUB_TOKEN}" | docker login ghcr.io -u $ --password-stdin
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Build and push
uses: docker/build-push-action@v4
with:
context: frontend
file: ./frontend/Dockerfile
push: true
tags: ghcr.io/buildbarn/bb-portal-frontend:${{ github.sha }}
20 changes: 20 additions & 0 deletions .github/workflows/frontend-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build frontend

on:
pull_request:
branches: ["main"]

jobs:
publish:
name: Build frontend
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Build
uses: docker/build-push-action@v4
with:
context: frontend
file: ./frontend/Dockerfile
push: false
tags: ghcr.io/buildbarn/bb-portal-frontend:${{ github.sha }}
46 changes: 46 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FROM node:22-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm i --frozen-lockfile

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN corepack enable pnpm && pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

0 comments on commit 51d7004

Please # to comment.