Update Docker Compose, Next.js config, and GitHub Actions for optimized CI/CD. Added local build notes, skipped ESLint during CI builds, and modified deployment to use prebuilt artifacts for faster image creation.
This commit is contained in:
1 parent
648777c649
commit
19b75671a0
4 files changed
+84
-11
No files matched your search
@@ -11,27 +11,72 @@ env:
|
||||
IMAGE_NAME: aut-management-faculty:latest
|
||||
CONTAINER_NAME: aut-management-faculty
|
||||
NETWORK_NAME: shared_web_network
|
||||
# Public hostname (Nginx Proxy Manager → this container:3000)
|
||||
PUBLIC_HOST: aut.insaight.net
|
||||
# Self-hosted runner has no docker-buildx; force classic builder
|
||||
DOCKER_BUILDKIT: "0"
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Build and run on server
|
||||
runs-on: [self-hosted, linux]
|
||||
|
||||
# Heavy Next.js compile on GitHub-hosted runners (not the InsAIght box)
|
||||
build:
|
||||
name: Build (ubuntu)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: npm
|
||||
|
||||
- name: Install & build
|
||||
env:
|
||||
DISABLE_REACT_COMPILER: "1"
|
||||
CI_FAST_BUILD: "1"
|
||||
NEXT_TELEMETRY_DISABLED: "1"
|
||||
run: |
|
||||
set -euo pipefail
|
||||
npm ci --no-audit --no-fund
|
||||
npm run build
|
||||
test -f .next/standalone/server.js
|
||||
|
||||
- name: Stage standalone artifact
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p prebuilt
|
||||
cp -a .next/standalone prebuilt/standalone
|
||||
cp -a .next/static prebuilt/static
|
||||
cp -a public prebuilt/public
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: next-standalone
|
||||
path: prebuilt/
|
||||
retention-days: 1
|
||||
|
||||
# Server only packs a tiny image + restarts the container
|
||||
deploy:
|
||||
name: Deploy (self-hosted)
|
||||
runs-on: [self-hosted, linux]
|
||||
needs: build
|
||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: next-standalone
|
||||
path: prebuilt
|
||||
|
||||
- name: Ensure shared_web_network exists
|
||||
run: |
|
||||
docker network inspect "$NETWORK_NAME" >/dev/null 2>&1 \
|
||||
|| docker network create "$NETWORK_NAME"
|
||||
|
||||
- name: Build image
|
||||
run: docker build -t "$IMAGE_NAME" .
|
||||
- name: Build image from prebuilt
|
||||
run: |
|
||||
test -f prebuilt/standalone/server.js
|
||||
docker build -f Dockerfile.prebuilt -t "$IMAGE_NAME" .
|
||||
|
||||
- name: Restart container
|
||||
env:
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Packs a pre-built Next.js standalone output — no npm / next build on the server.
|
||||
# Expects build context:
|
||||
# prebuilt/standalone/ ← contents of .next/standalone
|
||||
# prebuilt/static/ ← contents of .next/static
|
||||
# prebuilt/public/ ← public/
|
||||
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs \
|
||||
&& adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --chown=nextjs:nodejs prebuilt/standalone/ ./
|
||||
COPY --chown=nextjs:nodejs prebuilt/public ./public
|
||||
COPY --chown=nextjs:nodejs prebuilt/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
+1
-2
@@ -1,5 +1,6 @@
|
||||
services:
|
||||
web:
|
||||
# Local full build (slow). CI uses Dockerfile.prebuilt instead.
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
@@ -10,9 +11,7 @@ services:
|
||||
- NODE_ENV=production
|
||||
- PORT=3000
|
||||
- HOSTNAME=0.0.0.0
|
||||
# Optional override; falls back to DATABASE_URL in src/lib/db.ts
|
||||
- DATABASE_URL=${DATABASE_URL:-}
|
||||
# No published ports. Reachable only on shared_web_network
|
||||
# Nginx Proxy Manager: aut.insaight.net → http://aut-management-faculty:3000
|
||||
expose:
|
||||
- "3000"
|
||||
|
||||
@@ -7,6 +7,10 @@ const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
// Babel React Compiler is heavy in Docker/CI; keep it for local `next dev`.
|
||||
reactCompiler: process.env.DISABLE_REACT_COMPILER !== "1",
|
||||
// Skip lint during CI image builds (lint can still run in a separate job later).
|
||||
eslint: {
|
||||
ignoreDuringBuilds: process.env.CI_FAST_BUILD === "1",
|
||||
},
|
||||
experimental: {
|
||||
optimizePackageImports: ["lucide-react"],
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user