Files
Aut.ManagementFaculty/.github/workflows/deploy.yml
T

109 lines
2.9 KiB
YAML

name: Build & Deploy (Self-Hosted)
on:
push:
branches:
- master
- main
workflow_dispatch:
env:
IMAGE_NAME: aut-management-faculty:latest
CONTAINER_NAME: aut-management-faculty
NETWORK_NAME: shared_web_network
PUBLIC_HOST: aut.insaight.net
# Self-hosted runner has no docker-buildx; force classic builder
DOCKER_BUILDKIT: "0"
jobs:
# Heavy Next.js compile on GitHub-hosted runners (not the InsAIght box)
build:
name: Build (ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
- name: Install & build
env:
DISABLE_REACT_COMPILER: "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 from prebuilt
run: |
test -f prebuilt/standalone/server.js
docker build -f Dockerfile.prebuilt -t "$IMAGE_NAME" .
- name: Restart container
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: |
set -euo pipefail
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
RUN_ARGS=(
-d
--name "$CONTAINER_NAME"
--restart unless-stopped
--network "$NETWORK_NAME"
-e NODE_ENV=production
-e PORT=3000
-e HOSTNAME=0.0.0.0
--expose 3000
)
if [ -n "${DATABASE_URL:-}" ]; then
RUN_ARGS+=(-e "DATABASE_URL=${DATABASE_URL}")
fi
docker run "${RUN_ARGS[@]}" "$IMAGE_NAME"
echo "Deployed ${CONTAINER_NAME} on ${NETWORK_NAME}"
echo "Point Nginx Proxy Manager: ${PUBLIC_HOST} → http://${CONTAINER_NAME}:3000"
- name: Prune dangling images
run: docker image prune -f