diff --git a/.github/workflows/build-web.yaml b/.github/workflows/build-web.yaml new file mode 100644 index 0000000..3b2dc1e --- /dev/null +++ b/.github/workflows/build-web.yaml @@ -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 }} diff --git a/web/.env.production b/web/.env.production new file mode 100644 index 0000000..6330581 --- /dev/null +++ b/web/.env.production @@ -0,0 +1 @@ +API_ENDPOINT=http://lnf-api:8080 \ No newline at end of file diff --git a/web/Dockerfile b/web/Dockerfile new file mode 100644 index 0000000..6530328 --- /dev/null +++ b/web/Dockerfile @@ -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"] \ No newline at end of file diff --git a/web/next.config.mjs b/web/next.config.mjs index 4678774..4ce46f8 100644 --- a/web/next.config.mjs +++ b/web/next.config.mjs @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: 'standalone', +} -export default nextConfig; +export default nextConfig