Skip to content

Commit

Permalink
[ci] Add docker workflow for web
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjooiopa committed Apr 21, 2024
1 parent e7f4b1b commit efbd0a8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build-web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Web Docker Image

on:
release:
branches: [main]
types: [published]
paths:
- web/**
- .github/workflows/build-web.yaml

env:
REGISTRY: ghcr.io/dnjooiopa

jobs:
build_web:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
context: ./web
file: ./web/Dockerfile
tags: ${{ env.REGISTRY }}/lnf-web:latest,${{ env.REGISTRY }}/lnf-web:${{ github.event.release.tag_name }}
1 change: 1 addition & 0 deletions web/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_ENDPOINT=http://lnf-api:8080
43 changes: 43 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM node:18-alpine AS base

# 1. Install dependencies
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci

# 2. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build

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

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

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

COPY --from=builder /app/public ./public

RUN mkdir .next
RUN chown nextjs:nodejs .next

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
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
6 changes: 4 additions & 2 deletions web/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
output: 'standalone',
}

export default nextConfig;
export default nextConfig

0 comments on commit efbd0a8

Please sign in to comment.