Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and publish frontend Docker container #18

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
Loading