ci: streamline and unify pipelines with parallelized QA and optimized Docker builds
Some checks failed
Some checks failed
This commit is contained in:
@@ -32,11 +32,9 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
NPM_TOKEN: ${{ secrets.REGISTRY_PASS }}
|
NPM_TOKEN: ${{ secrets.REGISTRY_PASS }}
|
||||||
|
|
||||||
- name: 🔍 Lint
|
- name: 🧪 Parallel Checks
|
||||||
run: pnpm lint
|
run: |
|
||||||
|
pnpm lint &
|
||||||
- name: 🏗️ Typecheck
|
pnpm typecheck &
|
||||||
run: pnpm typecheck
|
pnpm test &
|
||||||
|
wait
|
||||||
- name: 🧪 Test
|
|
||||||
run: pnpm test
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Build & Deploy KLZ Cables
|
name: Build & Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -8,136 +8,80 @@ on:
|
|||||||
- 'v*'
|
- 'v*'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
skip_long_checks:
|
skip_checks:
|
||||||
description: 'Skip tests? (true/false)'
|
description: 'Skip tests? (true/false)'
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ (github.ref_type == 'tag' && !contains(github.ref_name, '-')) && 'prod' || (github.ref_type == 'tag' && 'staging' || (github.ref_name == 'main' && 'testing' || github.ref_name)) }}
|
group: ${{ github.workflow }}-${{ (github.ref_type == 'tag' && !contains(github.ref_name, '-')) && 'prod' || (github.ref_name == 'main' && 'testing' || github.ref_name) }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 1: Prepare & Determine Environment
|
# JOB 1: Prepare Environment
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
prepare:
|
prepare:
|
||||||
name: 🔍 Prepare Environment
|
name: 🔍 Prepare
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
outputs:
|
outputs:
|
||||||
target: ${{ steps.determine.outputs.target }}
|
target: ${{ steps.determine.outputs.target }}
|
||||||
image_tag: ${{ steps.determine.outputs.image_tag }}
|
image_tag: ${{ steps.determine.outputs.image_tag }}
|
||||||
env_file: ${{ steps.determine.outputs.env_file }}
|
env_file: ${{ steps.determine.outputs.env_file }}
|
||||||
traefik_host: ${{ steps.determine.outputs.traefik_host }}
|
traefik_host: ${{ steps.determine.outputs.traefik_host }}
|
||||||
traefik_host_rule: ${{ steps.determine.outputs.traefik_host_rule }}
|
traefik_rule: ${{ steps.determine.outputs.traefik_rule }}
|
||||||
primary_host: ${{ steps.determine.outputs.primary_host }}
|
next_public_url: ${{ steps.determine.outputs.next_public_url }}
|
||||||
next_public_base_url: ${{ steps.determine.outputs.next_public_base_url }}
|
|
||||||
directus_url: ${{ steps.determine.outputs.directus_url }}
|
directus_url: ${{ steps.determine.outputs.directus_url }}
|
||||||
directus_host: ${{ steps.determine.outputs.directus_host }}
|
|
||||||
project_name: ${{ steps.determine.outputs.project_name }}
|
project_name: ${{ steps.determine.outputs.project_name }}
|
||||||
is_prod: ${{ steps.determine.outputs.is_prod }}
|
|
||||||
gotify_title: ${{ steps.determine.outputs.gotify_title }}
|
|
||||||
gotify_priority: ${{ steps.determine.outputs.gotify_priority }}
|
|
||||||
short_sha: ${{ steps.determine.outputs.short_sha }}
|
short_sha: ${{ steps.determine.outputs.short_sha }}
|
||||||
commit_msg: ${{ steps.determine.outputs.commit_msg }}
|
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 🧹 Maintenance (High Density Cleanup)
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "Purging old build layers and dangling images..."
|
|
||||||
docker image prune -f
|
|
||||||
docker builder prune -f --filter "until=6h"
|
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: 🔍 Environment ermitteln
|
||||||
- name: 🔍 Environment & Version ermitteln
|
|
||||||
id: determine
|
id: determine
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
TAG="${{ github.ref_name }}"
|
REF="${{ github.ref_name }}"
|
||||||
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-9)
|
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
|
||||||
IMAGE_TAG="sha-${SHORT_SHA}"
|
DOMAIN="klz-cables.com"
|
||||||
COMMIT_MSG=$(git log -1 --pretty=%s || echo "No commit message available")
|
PRJ="klz"
|
||||||
|
|
||||||
if [[ "${{ github.ref_type }}" == "branch" && "$TAG" == "main" ]]; then
|
if [[ "${{ github.ref_type }}" == "branch" && "$REF" == "main" ]]; then
|
||||||
if [[ "$COMMIT_MSG" =~ ^chore: ]]; then
|
TARGET="testing"
|
||||||
TARGET="skip"
|
IMAGE_TAG="main-${SHORT_SHA}"
|
||||||
GOTIFY_TITLE="ℹ️ Skip Deploy (Chore)"
|
ENV_FILE=".env.testing"
|
||||||
GOTIFY_PRIORITY=2
|
TRAEFIK_HOST="testing.${DOMAIN}"
|
||||||
else
|
|
||||||
TARGET="testing"
|
|
||||||
IMAGE_TAG="main-${SHORT_SHA}"
|
|
||||||
ENV_FILE=".env.testing"
|
|
||||||
TRAEFIK_HOST="testing.klz-cables.com"
|
|
||||||
NEXT_PUBLIC_BASE_URL="https://testing.klz-cables.com"
|
|
||||||
DIRECTUS_URL="https://cms.testing.klz-cables.com"
|
|
||||||
DIRECTUS_HOST="cms.testing.klz-cables.com"
|
|
||||||
PROJECT_NAME="klz-cables-testing"
|
|
||||||
IS_PROD="false"
|
|
||||||
GOTIFY_TITLE="🧪 Testing-Deploy"
|
|
||||||
GOTIFY_PRIORITY=4
|
|
||||||
fi
|
|
||||||
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
|
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
|
||||||
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
if [[ "$REF" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
TARGET="production"
|
TARGET="production"
|
||||||
IMAGE_TAG="$TAG"
|
IMAGE_TAG="$REF"
|
||||||
ENV_FILE=".env.prod"
|
ENV_FILE=".env.prod"
|
||||||
TRAEFIK_HOST="klz-cables.com, www.klz-cables.com"
|
TRAEFIK_HOST="${DOMAIN}, www.${DOMAIN}"
|
||||||
NEXT_PUBLIC_BASE_URL="https://klz-cables.com"
|
|
||||||
DIRECTUS_URL="https://cms.klz-cables.com"
|
|
||||||
DIRECTUS_HOST="cms.klz-cables.com"
|
|
||||||
PROJECT_NAME="klz-cables-prod"
|
|
||||||
IS_PROD="true"
|
|
||||||
GOTIFY_TITLE="🚀 Production-Release"
|
|
||||||
GOTIFY_PRIORITY=6
|
|
||||||
elif [[ "$TAG" =~ -rc || "$TAG" =~ -beta || "$TAG" =~ -alpha ]]; then
|
|
||||||
TARGET="staging"
|
|
||||||
IMAGE_TAG="$TAG"
|
|
||||||
ENV_FILE=".env.staging"
|
|
||||||
TRAEFIK_HOST="staging.klz-cables.com"
|
|
||||||
NEXT_PUBLIC_BASE_URL="https://staging.klz-cables.com"
|
|
||||||
DIRECTUS_URL="https://cms.staging.klz-cables.com"
|
|
||||||
DIRECTUS_HOST="cms.staging.klz-cables.com"
|
|
||||||
PROJECT_NAME="klz-cables-staging"
|
|
||||||
IS_PROD="false"
|
|
||||||
GOTIFY_TITLE="🧪 Staging-Deploy (Pre-Release)"
|
|
||||||
GOTIFY_PRIORITY=5
|
|
||||||
else
|
else
|
||||||
TARGET="skip"
|
TARGET="staging"
|
||||||
GOTIFY_TITLE="❓ Unbekannter Tag"
|
IMAGE_TAG="$REF"
|
||||||
GOTIFY_PRIORITY=3
|
ENV_FILE=".env.staging"
|
||||||
|
TRAEFIK_HOST="staging.${DOMAIN}"
|
||||||
fi
|
fi
|
||||||
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
|
else
|
||||||
TARGET="branch"
|
TARGET="branch"
|
||||||
# Slugify branch name: lowercase, replace non-alphanumeric with -, remove leading/trailing -
|
SLUG=$(echo "$REF" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
||||||
SLUG=$(echo "$TAG" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
|
|
||||||
IMAGE_TAG="branch-${SLUG}-${SHORT_SHA}"
|
IMAGE_TAG="branch-${SLUG}-${SHORT_SHA}"
|
||||||
ENV_FILE=".env.branch-${SLUG}"
|
ENV_FILE=".env.branch-${SLUG}"
|
||||||
TRAEFIK_HOST="${SLUG}.branch.mintel.me"
|
TRAEFIK_HOST="${SLUG}.branch.mintel.me"
|
||||||
NEXT_PUBLIC_BASE_URL="https://${SLUG}.branch.mintel.me"
|
|
||||||
DIRECTUS_URL="https://cms.${SLUG}.branch.mintel.me"
|
|
||||||
DIRECTUS_HOST="cms.${SLUG}.branch.mintel.me"
|
|
||||||
PROJECT_NAME="klz-cables-br-${SLUG}"
|
|
||||||
IS_PROD="false"
|
|
||||||
GOTIFY_TITLE="🌿 Branch-Deploy ($TAG)"
|
|
||||||
GOTIFY_PRIORITY=4
|
|
||||||
else
|
|
||||||
TARGET="skip"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Standardize Traefik Rule
|
||||||
if [[ "$TRAEFIK_HOST" == *","* ]]; then
|
if [[ "$TRAEFIK_HOST" == *","* ]]; then
|
||||||
# Multi-domain: Host(`a.com`) || Host(`b.com`)
|
TRAEFIK_RULE=$(echo "$TRAEFIK_HOST" | sed 's/,/ /g' | awk '{for(i=1;i<=NF;i++) printf "Host(`%s`)%s", $i, (i==NF?"":" || ")}')
|
||||||
TRAEFIK_HOST_RULE=$(echo "$TRAEFIK_HOST" | sed 's/,/ /g' | awk '{for(i=1;i<=NF;i++) printf "Host(`%s`)%s", $i, (i==NF?"":" || ")}')
|
|
||||||
PRIMARY_HOST=$(echo "$TRAEFIK_HOST" | cut -d',' -f1 | sed 's/ //g')
|
PRIMARY_HOST=$(echo "$TRAEFIK_HOST" | cut -d',' -f1 | sed 's/ //g')
|
||||||
else
|
else
|
||||||
# Single domain: Host(`domain.com`)
|
TRAEFIK_RULE="Host(\`$TRAEFIK_HOST\`)"
|
||||||
TRAEFIK_HOST_RULE="Host(\`$TRAEFIK_HOST\`)"
|
|
||||||
PRIMARY_HOST="$TRAEFIK_HOST"
|
PRIMARY_HOST="$TRAEFIK_HOST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -145,25 +89,19 @@ jobs:
|
|||||||
echo "target=$TARGET"
|
echo "target=$TARGET"
|
||||||
echo "image_tag=$IMAGE_TAG"
|
echo "image_tag=$IMAGE_TAG"
|
||||||
echo "env_file=$ENV_FILE"
|
echo "env_file=$ENV_FILE"
|
||||||
echo "traefik_host=$TRAEFIK_HOST"
|
echo "traefik_host=$PRIMARY_HOST"
|
||||||
echo "traefik_host_rule=$TRAEFIK_HOST_RULE"
|
echo "traefik_rule=$TRAEFIK_RULE"
|
||||||
echo "primary_host=$PRIMARY_HOST"
|
echo "next_public_url=https://$PRIMARY_HOST"
|
||||||
echo "next_public_base_url=$NEXT_PUBLIC_BASE_URL"
|
echo "directus_url=https://cms.$PRIMARY_HOST"
|
||||||
echo "directus_url=$DIRECTUS_URL"
|
echo "project_name=$PRJ-$TARGET"
|
||||||
echo "directus_host=$DIRECTUS_HOST"
|
|
||||||
echo "project_name=$PROJECT_NAME"
|
|
||||||
echo "is_prod=$IS_PROD"
|
|
||||||
echo "gotify_title=$GOTIFY_TITLE"
|
|
||||||
echo "gotify_priority=$GOTIFY_PRIORITY"
|
|
||||||
echo "short_sha=$SHORT_SHA"
|
echo "short_sha=$SHORT_SHA"
|
||||||
echo "commit_msg=$COMMIT_MSG"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 2: Quality Assurance (Lint & Test)
|
# JOB 2: QA (Lint, Typecheck, Test)
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
qa:
|
qa:
|
||||||
name: 🧪 Quality Assurance
|
name: 🧪 QA
|
||||||
needs: prepare
|
needs: prepare
|
||||||
if: needs.prepare.outputs.target != 'skip'
|
if: needs.prepare.outputs.target != 'skip'
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
@@ -172,412 +110,133 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
run_install: false
|
- name: 🔐 Registry Auth
|
||||||
|
|
||||||
- name: 🔐 Configure Private Registry
|
|
||||||
run: |
|
run: |
|
||||||
REGISTRY="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}"
|
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
||||||
echo "@mintel:registry=https://$REGISTRY" > .npmrc
|
echo "//${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}/:_authToken=${{ secrets.REGISTRY_PASS }}" >> .npmrc
|
||||||
echo "//$REGISTRY/:_authToken=${{ secrets.REGISTRY_PASS }}" >> .npmrc
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install --frozen-lockfile
|
||||||
env:
|
- name: 🧪 Parallel Checks
|
||||||
NPM_TOKEN: ${{ secrets.REGISTRY_PASS }}
|
if: github.event.inputs.skip_checks != 'true'
|
||||||
|
|
||||||
- name: 🧪 Run Checks in Parallel
|
|
||||||
if: github.event.inputs.skip_long_checks != 'true'
|
|
||||||
run: |
|
run: |
|
||||||
pnpm lint &
|
pnpm lint &
|
||||||
LINT_PID=$!
|
|
||||||
pnpm typecheck &
|
pnpm typecheck &
|
||||||
TYPE_PID=$!
|
|
||||||
pnpm test &
|
pnpm test &
|
||||||
TEST_PID=$!
|
wait
|
||||||
|
|
||||||
# Wait for all and fail if any fail
|
|
||||||
wait $LINT_PID || exit 1
|
|
||||||
wait $TYPE_PID || exit 1
|
|
||||||
wait $TEST_PID || exit 1
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 3: Build & Push Docker Image
|
# JOB 3: Build & Push
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
build-app:
|
build:
|
||||||
name: 🏗️ Build App
|
name: 🏗️ Build
|
||||||
needs: prepare
|
needs: prepare
|
||||||
if: ${{ needs.prepare.outputs.target != 'skip' }}
|
if: needs.prepare.outputs.target != 'skip'
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: 🐳 Set up Docker Buildx
|
- name: 🐳 Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: 🔐 Registry Login
|
- name: 🔐 Registry Login
|
||||||
run: |
|
run: echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
||||||
echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
- name: 🏗️ Build and Push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
- name: 🏗️ App bauen & pushen
|
with:
|
||||||
env:
|
context: .
|
||||||
IMAGE_TAG: ${{ needs.prepare.outputs.image_tag }}
|
push: true
|
||||||
TARGET: ${{ needs.prepare.outputs.target }}
|
platforms: linux/arm64
|
||||||
NEXT_PUBLIC_BASE_URL: ${{ needs.prepare.outputs.next_public_base_url }}
|
build-args: |
|
||||||
DIRECTUS_URL: ${{ needs.prepare.outputs.directus_url }}
|
NEXT_PUBLIC_BASE_URL=${{ needs.prepare.outputs.next_public_url }}
|
||||||
run: |
|
NEXT_PUBLIC_TARGET=${{ needs.prepare.outputs.target }}
|
||||||
docker buildx build \
|
DIRECTUS_URL=${{ needs.prepare.outputs.directus_url }}
|
||||||
--pull \
|
NPM_TOKEN=${{ secrets.REGISTRY_PASS }}
|
||||||
--platform linux/arm64 \
|
tags: registry.infra.mintel.me/mintel/klz-cables.com:${{ needs.prepare.outputs.image_tag }}
|
||||||
--build-arg NEXT_PUBLIC_BASE_URL="$NEXT_PUBLIC_BASE_URL" \
|
cache-from: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache
|
||||||
--build-arg NEXT_PUBLIC_TARGET="$TARGET" \
|
cache-to: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache,mode=max
|
||||||
--build-arg DIRECTUS_URL="$DIRECTUS_URL" \
|
secrets: |
|
||||||
--build-arg REGISTRY_HOST="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" \
|
"NPM_TOKEN=${{ secrets.REGISTRY_PASS }}"
|
||||||
--build-arg NPM_TOKEN="${{ secrets.REGISTRY_PASS }}" \
|
|
||||||
-t registry.infra.mintel.me/mintel/klz-cables.com:$IMAGE_TAG \
|
|
||||||
--cache-from type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache \
|
|
||||||
--cache-to type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache,mode=max \
|
|
||||||
--push .
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 4: Deploy via SSH
|
# JOB 4: Deploy
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
deploy:
|
deploy:
|
||||||
name: 🚀 Deploy
|
name: 🚀 Deploy
|
||||||
needs: [prepare, build-app, qa]
|
needs: [prepare, build, qa]
|
||||||
if: ${{ needs.prepare.outputs.target != 'skip' }}
|
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
env:
|
|
||||||
TARGET: ${{ needs.prepare.outputs.target }}
|
|
||||||
IMAGE_TAG: ${{ needs.prepare.outputs.image_tag }}
|
|
||||||
ENV_FILE: ${{ needs.prepare.outputs.env_file }}
|
|
||||||
TRAEFIK_HOST: ${{ needs.prepare.outputs.primary_host }}
|
|
||||||
NEXT_PUBLIC_BASE_URL: ${{ needs.prepare.outputs.next_public_base_url }}
|
|
||||||
UMAMI_WEBSITE_ID: ${{ needs.prepare.outputs.target == 'production' && secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_NEXT_PUBLIC_UMAMI_WEBSITE_ID || secrets.TESTING_NEXT_PUBLIC_UMAMI_WEBSITE_ID || secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID) }}
|
|
||||||
UMAMI_API_ENDPOINT: ${{ needs.prepare.outputs.target == 'production' && secrets.NEXT_PUBLIC_UMAMI_SCRIPT_URL || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_NEXT_PUBLIC_UMAMI_SCRIPT_URL || secrets.TESTING_NEXT_PUBLIC_UMAMI_SCRIPT_URL || secrets.NEXT_PUBLIC_UMAMI_SCRIPT_URL) }}
|
|
||||||
SENTRY_DSN: ${{ secrets.SENTRY_DSN || vars.SENTRY_DSN }}
|
|
||||||
MAIL_HOST: ${{ secrets.MAIL_HOST || vars.MAIL_HOST || (needs.prepare.outputs.target == 'production' && (secrets.MAIL_HOST || vars.MAIL_HOST) || (needs.prepare.outputs.target == 'staging' && (secrets.STAGING_MAIL_HOST || vars.STAGING_MAIL_HOST) || (secrets.TESTING_MAIL_HOST || vars.TESTING_MAIL_HOST) || (secrets.MAIL_HOST || vars.MAIL_HOST))) }}
|
|
||||||
MAIL_PORT: ${{ secrets.MAIL_PORT || vars.MAIL_PORT || (needs.prepare.outputs.target == 'production' && (secrets.MAIL_PORT || vars.MAIL_PORT) || (needs.prepare.outputs.target == 'staging' && (secrets.STAGING_MAIL_PORT || vars.STAGING_MAIL_PORT) || (secrets.TESTING_MAIL_PORT || vars.TESTING_MAIL_PORT) || (secrets.MAIL_PORT || vars.MAIL_PORT))) }}
|
|
||||||
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME || vars.MAIL_USERNAME || (needs.prepare.outputs.target == 'production' && (secrets.MAIL_USERNAME || vars.MAIL_USERNAME) || (needs.prepare.outputs.target == 'staging' && (secrets.STAGING_MAIL_USERNAME || vars.STAGING_MAIL_USERNAME) || (secrets.TESTING_MAIL_USERNAME || vars.TESTING_MAIL_USERNAME) || (secrets.MAIL_USERNAME || vars.MAIL_USERNAME))) }}
|
|
||||||
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD || (needs.prepare.outputs.target == 'production' && secrets.MAIL_PASSWORD || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_MAIL_PASSWORD || secrets.TESTING_MAIL_PASSWORD || secrets.MAIL_PASSWORD)) }}
|
|
||||||
MAIL_FROM: ${{ secrets.MAIL_FROM || vars.MAIL_FROM || (needs.prepare.outputs.target == 'production' && (secrets.MAIL_FROM || vars.MAIL_FROM) || (needs.prepare.outputs.target == 'staging' && (secrets.STAGING_MAIL_FROM || vars.STAGING_MAIL_FROM) || (secrets.TESTING_MAIL_FROM || vars.TESTING_MAIL_FROM) || (secrets.MAIL_FROM || vars.MAIL_FROM))) }}
|
|
||||||
MAIL_RECIPIENTS: ${{ secrets.MAIL_RECIPIENTS || vars.MAIL_RECIPIENTS || (needs.prepare.outputs.target == 'production' && (secrets.MAIL_RECIPIENTS || vars.MAIL_RECIPIENTS) || (needs.prepare.outputs.target == 'staging' && (secrets.STAGING_MAIL_RECIPIENTS || vars.STAGING_MAIL_RECIPIENTS) || (secrets.TESTING_MAIL_RECIPIENTS || vars.TESTING_MAIL_RECIPIENTS) || (secrets.MAIL_RECIPIENTS || vars.MAIL_RECIPIENTS))) }}
|
|
||||||
DIRECTUS_URL: ${{ needs.prepare.outputs.directus_url }}
|
|
||||||
DIRECTUS_HOST: ${{ needs.prepare.outputs.directus_host }}
|
|
||||||
PROJECT_NAME: ${{ needs.prepare.outputs.project_name }}
|
|
||||||
DIRECTUS_KEY: ${{ secrets.DIRECTUS_KEY || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_KEY || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_KEY || secrets.TESTING_DIRECTUS_KEY || secrets.DIRECTUS_KEY)) }}
|
|
||||||
DIRECTUS_SECRET: ${{ secrets.DIRECTUS_SECRET || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_SECRET || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_SECRET || secrets.TESTING_DIRECTUS_SECRET || secrets.DIRECTUS_SECRET)) }}
|
|
||||||
DIRECTUS_ADMIN_EMAIL: ${{ secrets.DIRECTUS_ADMIN_EMAIL || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_ADMIN_EMAIL || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_ADMIN_EMAIL || secrets.TESTING_DIRECTUS_ADMIN_EMAIL || secrets.DIRECTUS_ADMIN_EMAIL)) }}
|
|
||||||
DIRECTUS_ADMIN_PASSWORD: ${{ secrets.DIRECTUS_ADMIN_PASSWORD || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_ADMIN_PASSWORD || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_ADMIN_PASSWORD || secrets.TESTING_DIRECTUS_ADMIN_PASSWORD || secrets.DIRECTUS_ADMIN_PASSWORD)) }}
|
|
||||||
DIRECTUS_DB_NAME: ${{ secrets.DIRECTUS_DB_NAME || 'directus' }}
|
|
||||||
DIRECTUS_DB_USER: ${{ secrets.DIRECTUS_DB_USER || 'directus' }}
|
|
||||||
DIRECTUS_DB_PASSWORD: ${{ secrets.DIRECTUS_DB_PASSWORD || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_DB_PASSWORD || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_DB_PASSWORD || secrets.TESTING_DIRECTUS_DB_PASSWORD || secrets.DIRECTUS_DB_PASSWORD)) }}
|
|
||||||
DIRECTUS_API_TOKEN: ${{ secrets.DIRECTUS_API_TOKEN || (needs.prepare.outputs.target == 'production' && secrets.DIRECTUS_API_TOKEN || (needs.prepare.outputs.target == 'staging' && secrets.STAGING_DIRECTUS_API_TOKEN || secrets.TESTING_DIRECTUS_API_TOKEN || secrets.DIRECTUS_API_TOKEN)) }}
|
|
||||||
GATEKEEPER_PASSWORD: ${{ secrets.GATEKEEPER_PASSWORD || 'klz2026' }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
- name: 🚀 SSH Deploy
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: 🚀 Deploy to ${{ env.TARGET }}
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
TARGET: ${{ needs.prepare.outputs.target }}
|
||||||
|
IMAGE_TAG: ${{ needs.prepare.outputs.image_tag }}
|
||||||
|
PROJECT_NAME: ${{ needs.prepare.outputs.project_name }}
|
||||||
|
ENV_FILE: ${{ needs.prepare.outputs.env_file }}
|
||||||
|
TRAEFIK_RULE: ${{ needs.prepare.outputs.traefik_rule }}
|
||||||
run: |
|
run: |
|
||||||
echo "Deploying $TARGET → $IMAGE_TAG"
|
|
||||||
|
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519
|
echo "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
# Generated by CI - $TARGET - $(date -u)
|
# Generate Environment File
|
||||||
# Determine dynamic values before writing the file
|
cat > .env.deploy << EOF
|
||||||
LOG_LEVEL=$( [[ "$TARGET" == "testing" || "$TARGET" == "development" ]] && echo "debug" || echo "info" )
|
|
||||||
COOKIE_DOMAIN=.$(echo $NEXT_PUBLIC_BASE_URL | sed 's|https://||')
|
|
||||||
|
|
||||||
cat > /tmp/klz-cables.env << EOF
|
|
||||||
# Generated by CI - $TARGET - $(date -u)
|
|
||||||
IMAGE_TAG=$IMAGE_TAG
|
IMAGE_TAG=$IMAGE_TAG
|
||||||
NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
NEXT_PUBLIC_BASE_URL=${{ needs.prepare.outputs.next_public_url }}
|
||||||
UMAMI_WEBSITE_ID=$UMAMI_WEBSITE_ID
|
DIRECTUS_URL=${{ needs.prepare.outputs.directus_url }}
|
||||||
UMAMI_API_ENDPOINT=$UMAMI_API_ENDPOINT
|
DIRECTUS_HOST=cms.${{ needs.prepare.outputs.traefik_host }}
|
||||||
SENTRY_DSN=$SENTRY_DSN
|
|
||||||
LOG_LEVEL=$LOG_LEVEL
|
|
||||||
MAIL_HOST=$MAIL_HOST
|
|
||||||
MAIL_PORT=$MAIL_PORT
|
|
||||||
MAIL_USERNAME=$MAIL_USERNAME
|
|
||||||
MAIL_PASSWORD=$MAIL_PASSWORD
|
|
||||||
MAIL_FROM=$MAIL_FROM
|
|
||||||
MAIL_RECIPIENTS=$MAIL_RECIPIENTS
|
|
||||||
|
|
||||||
# Directus
|
|
||||||
DIRECTUS_URL=$DIRECTUS_URL
|
|
||||||
DIRECTUS_HOST=$DIRECTUS_HOST
|
|
||||||
DIRECTUS_KEY=$DIRECTUS_KEY
|
|
||||||
DIRECTUS_SECRET=$DIRECTUS_SECRET
|
|
||||||
DIRECTUS_ADMIN_EMAIL=$DIRECTUS_ADMIN_EMAIL
|
|
||||||
DIRECTUS_ADMIN_PASSWORD=$DIRECTUS_ADMIN_PASSWORD
|
|
||||||
DIRECTUS_DB_NAME=$DIRECTUS_DB_NAME
|
|
||||||
DIRECTUS_DB_USER=$DIRECTUS_DB_USER
|
|
||||||
DIRECTUS_DB_PASSWORD=$DIRECTUS_DB_PASSWORD
|
|
||||||
DIRECTUS_API_TOKEN=$DIRECTUS_API_TOKEN
|
|
||||||
INTERNAL_DIRECTUS_URL=http://directus:8055
|
INTERNAL_DIRECTUS_URL=http://directus:8055
|
||||||
GATEKEEPER_PASSWORD=$GATEKEEPER_PASSWORD
|
TRAEFIK_HOST_RULE='$TRAEFIK_RULE'
|
||||||
|
PROJECT_NAME=$PROJECT_NAME
|
||||||
TARGET=$TARGET
|
TARGET=$TARGET
|
||||||
SENTRY_ENVIRONMENT=$TARGET
|
SENTRY_ENVIRONMENT=$TARGET
|
||||||
PROJECT_NAME=$PROJECT_NAME
|
SENTRY_DSN=${{ secrets.SENTRY_DSN || vars.SENTRY_DSN }}
|
||||||
COOKIE_DOMAIN=$COOKIE_DOMAIN
|
GATEKEEPER_PASSWORD=${{ secrets.GATEKEEPER_PASSWORD || 'klz2026' }}
|
||||||
TRAEFIK_HOST=$TRAEFIK_HOST
|
AUTH_MIDDLEWARE=$( [[ "$TARGET" == "production" ]] && echo "${PROJECT_NAME}-compress" || echo "${PROJECT_NAME}-auth,${PROJECT_NAME}-compress" )
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Append complex variables that contain backticks using printf to avoid shell expansion hits
|
# Transfer and Restart
|
||||||
printf "AUTH_MIDDLEWARE=%s\n" "$( [[ "$TARGET" == "production" ]] && echo "${PROJECT_NAME}-compress" || echo "${PROJECT_NAME}-auth,${PROJECT_NAME}-compress" )" >> /tmp/klz-cables.env
|
SITE_DIR="/home/deploy/sites/klz-cables.com"
|
||||||
printf "TRAEFIK_HOST_RULE='%s'\n" '${{ needs.prepare.outputs.traefik_host_rule }}' >> /tmp/klz-cables.env
|
ssh root@alpha.mintel.me "mkdir -p $SITE_DIR"
|
||||||
|
scp .env.deploy root@alpha.mintel.me:$SITE_DIR/$ENV_FILE
|
||||||
# 1. Cleanup and Create Directories on server BEFORE SCP
|
scp docker-compose.yml root@alpha.mintel.me:$SITE_DIR/docker-compose.yml
|
||||||
ssh -o StrictHostKeyChecking=accept-new root@alpha.mintel.me bash << 'EOF'
|
|
||||||
set -e
|
ssh root@alpha.mintel.me "cd $SITE_DIR && \
|
||||||
mkdir -p /home/deploy/sites/klz-cables.com/directus/uploads \
|
echo '${{ secrets.REGISTRY_PASS }}' | docker login registry.infra.mintel.me -u '${{ secrets.REGISTRY_USER }}' --password-stdin && \
|
||||||
/home/deploy/sites/klz-cables.com/directus/extensions \
|
docker compose -p '$PROJECT_NAME' --env-file '$ENV_FILE' pull && \
|
||||||
/home/deploy/sites/klz-cables.com/directus/schema
|
docker compose -p '$PROJECT_NAME' --env-file '$ENV_FILE' up -d --wait --remove-orphans"
|
||||||
chown -R deploy:deploy /home/deploy/sites/klz-cables.com/directus
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# 2. Transfer files
|
|
||||||
scp -o StrictHostKeyChecking=accept-new /tmp/klz-cables.env root@alpha.mintel.me:/home/deploy/sites/klz-cables.com/$ENV_FILE
|
|
||||||
scp -o StrictHostKeyChecking=accept-new docker-compose.yml root@alpha.mintel.me:/home/deploy/sites/klz-cables.com/docker-compose.yml
|
|
||||||
scp -r -o StrictHostKeyChecking=accept-new directus/schema root@alpha.mintel.me:/home/deploy/sites/klz-cables.com/directus/
|
|
||||||
|
|
||||||
ssh -o StrictHostKeyChecking=accept-new root@alpha.mintel.me IMAGE_TAG="$IMAGE_TAG" ENV_FILE="$ENV_FILE" PROJECT_NAME="$PROJECT_NAME" bash << 'EOF'
|
|
||||||
set -e
|
|
||||||
cd /home/deploy/sites/klz-cables.com
|
|
||||||
chmod 600 "$ENV_FILE"
|
|
||||||
chown deploy:deploy "$ENV_FILE"
|
|
||||||
|
|
||||||
echo "${{ secrets.REGISTRY_PASS }}" | docker login registry.infra.mintel.me -u "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
||||||
|
|
||||||
echo "→ Pulling image: $IMAGE_TAG"
|
|
||||||
docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" pull
|
|
||||||
|
|
||||||
echo "→ Starting containers (Waiting for Health)..."
|
|
||||||
# Uses --wait to ensure containers are healthy before proceeding
|
|
||||||
# This replaces the brittle 'sleep 15' and manual check
|
|
||||||
docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" up -d --wait --remove-orphans
|
|
||||||
|
|
||||||
docker system prune -f --filter "until=24h"
|
|
||||||
|
|
||||||
echo "✅ Deployment successful. Containers are Healthy."
|
|
||||||
docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" ps
|
|
||||||
echo "→ Applying Directus Schema Snapshot..."
|
|
||||||
# Note: We check if snapshot exists first to avoid failing if no snapshot is committed yet
|
|
||||||
if docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" exec -T directus ls /directus/schema/snapshot.yaml >/dev/null 2>&1; then
|
|
||||||
docker compose -p "$PROJECT_NAME" --env-file "$ENV_FILE" exec -T directus npx directus schema apply /directus/schema/snapshot.yaml --yes
|
|
||||||
else
|
|
||||||
echo "ℹ️ No snapshot.yaml found, skipping schema apply."
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "ℹ️ No snapshot.yaml found, skipping schema apply."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "✅ Deployment successful."
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 5: PageSpeed Test
|
# JOB 5: Notifications
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
|
||||||
pagespeed:
|
|
||||||
name: ⚡ PageSpeed
|
|
||||||
needs: [prepare, deploy]
|
|
||||||
if: |
|
|
||||||
always() &&
|
|
||||||
needs.prepare.outputs.target != 'skip' &&
|
|
||||||
needs.deploy.result == 'success' &&
|
|
||||||
github.event.inputs.skip_long_checks != 'true'
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: catthehacker/ubuntu:act-latest
|
|
||||||
# outputs:
|
|
||||||
# report_url: ${{ steps.save.outputs.report_url }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Setup pnpm
|
|
||||||
uses: pnpm/action-setup@v3
|
|
||||||
with:
|
|
||||||
version: 10
|
|
||||||
run_install: false
|
|
||||||
|
|
||||||
- name: 🔐 Configure Private Registry
|
|
||||||
run: |
|
|
||||||
REGISTRY="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}"
|
|
||||||
echo "@mintel:registry=https://$REGISTRY" > .npmrc
|
|
||||||
echo "//$REGISTRY/:_authToken=${{ secrets.REGISTRY_PASS }}" >> .npmrc
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: pnpm install
|
|
||||||
|
|
||||||
- name: 🏥 Health Check (Wait for 200 OK)
|
|
||||||
env:
|
|
||||||
URL: ${{ needs.prepare.outputs.next_public_base_url }}
|
|
||||||
run: |
|
|
||||||
echo "Waiting for $URL to be ready..."
|
|
||||||
timeout=300
|
|
||||||
interval=5
|
|
||||||
elapsed=0
|
|
||||||
|
|
||||||
while [ $elapsed -lt $timeout ]; do
|
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL" || echo "000")
|
|
||||||
echo "Attempt $((elapsed/interval+1)): Status $STATUS"
|
|
||||||
|
|
||||||
if [ "$STATUS" = "200" ]; then
|
|
||||||
echo "✅ Site is healthy!"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep $interval
|
|
||||||
elapsed=$((elapsed + interval))
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "❌ Timeout waiting for site to be healthy."
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: 🔍 Install Chromium (Native & ARM64)
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y gnupg wget ca-certificates
|
|
||||||
|
|
||||||
# Detect OS
|
|
||||||
OS_ID=$(. /etc/os-release && echo $ID)
|
|
||||||
CODENAME=$(. /etc/os-release && echo $VERSION_CODENAME)
|
|
||||||
|
|
||||||
if [ "$OS_ID" = "debian" ]; then
|
|
||||||
echo "🎯 Debian detected - installing native chromium"
|
|
||||||
apt-get install -y chromium
|
|
||||||
else
|
|
||||||
echo "🎯 Ubuntu detected - adding xtradeb PPA"
|
|
||||||
mkdir -p /etc/apt/keyrings
|
|
||||||
KEY_ID="82BB6851C64F6880"
|
|
||||||
|
|
||||||
# Multi-method Key Fetch
|
|
||||||
SUCCESS=false
|
|
||||||
echo "Fetching key $KEY_ID..."
|
|
||||||
|
|
||||||
# Method 1: gpg --recv-keys (standard)
|
|
||||||
for server in "hkp://keyserver.ubuntu.com:80" "hkp://keyserver.ubuntu.com:11371"; do
|
|
||||||
if gpg --no-default-keyring --keyring /tmp/xtradeb.gpg --keyserver "$server" --recv-keys "$KEY_ID"; then
|
|
||||||
gpg --no-default-keyring --keyring /tmp/xtradeb.gpg --export > /etc/apt/keyrings/xtradeb.gpg
|
|
||||||
SUCCESS=true && break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Method 2: Direct wget (fallback)
|
|
||||||
if [ "$SUCCESS" = false ]; then
|
|
||||||
wget -qO- "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x$KEY_ID" | gpg --dearmor > /etc/apt/keyrings/xtradeb.gpg && SUCCESS=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$SUCCESS" = true ]; then
|
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/xtradeb.gpg] http://ppa.launchpad.net/xtradeb/apps/ubuntu $CODENAME main" > /etc/apt/sources.list.d/xtradeb-ppa.list
|
|
||||||
else
|
|
||||||
echo "⚠️ GPG fetch failed, using legacy apt-key as last resort..."
|
|
||||||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$KEY_ID" || true
|
|
||||||
echo "deb http://ppa.launchpad.net/xtradeb/apps/ubuntu $CODENAME main" > /etc/apt/sources.list.d/xtradeb-ppa.list
|
|
||||||
fi
|
|
||||||
|
|
||||||
# PRIORITY PINNING: Force PPA over Snap-dummy
|
|
||||||
printf "Package: *\nPin: release o=LP-PPA-xtradeb-apps\nPin-Priority: 1001\n" > /etc/apt/preferences.d/xtradeb
|
|
||||||
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y --allow-downgrades chromium || apt-get install -y chromium-browser
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Force clean paths (remove existing dead links/files if they are snap wrappers)
|
|
||||||
rm -f /usr/bin/google-chrome /usr/bin/chromium-browser
|
|
||||||
[ -f /usr/bin/chromium ] && ln -sf /usr/bin/chromium /usr/bin/google-chrome
|
|
||||||
[ -f /usr/bin/chromium ] && ln -sf /usr/bin/chromium /usr/bin/chromium-browser
|
|
||||||
|
|
||||||
echo "✅ Binary check:"
|
|
||||||
ls -l /usr/bin/chromium* /usr/bin/google-chrome || true
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: 🧪 Run PageSpeed (Lighthouse)
|
|
||||||
env:
|
|
||||||
NEXT_PUBLIC_BASE_URL: ${{ needs.prepare.outputs.next_public_base_url }}
|
|
||||||
GATEKEEPER_PASSWORD: ${{ secrets.GATEKEEPER_PASSWORD || 'klz2026' }}
|
|
||||||
PAGESPEED_LIMIT: 8
|
|
||||||
PUPPETEER_EXECUTABLE_PATH: /usr/bin/chromium
|
|
||||||
CHROME_PATH: /usr/bin/chromium
|
|
||||||
run: pnpm pagespeed:test
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
|
||||||
# JOB 6: Notifications
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
notifications:
|
notifications:
|
||||||
name: 🔔 Notifications
|
name: 🔔 Notify
|
||||||
needs: [prepare, qa, build-app, deploy, pagespeed]
|
needs: [prepare, deploy]
|
||||||
if: always()
|
if: always()
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
steps:
|
steps:
|
||||||
- name: 📊 Deployment Summary
|
- name: 🔔 Gotify
|
||||||
run: |
|
|
||||||
echo "┌──────────────────────────────┐"
|
|
||||||
echo "│ Deployment Summary │"
|
|
||||||
echo "├──────────────────────────────┤"
|
|
||||||
echo "│ Status: ${{ needs.deploy.result }} │"
|
|
||||||
echo "│ Umgebung: ${{ needs.prepare.outputs.target || 'skipped' }} │"
|
|
||||||
echo "│ Version: ${{ needs.prepare.outputs.image_tag }} │"
|
|
||||||
echo "│ Commit: ${{ needs.prepare.outputs.short_sha }} │"
|
|
||||||
echo "│ Message: ${{ needs.prepare.outputs.commit_msg }} │"
|
|
||||||
echo "└──────────────────────────────┘"
|
|
||||||
|
|
||||||
- name: 🔔 Gotify - Success
|
|
||||||
if: needs.deploy.result == 'success'
|
|
||||||
run: |
|
run: |
|
||||||
|
STATUS="${{ needs.deploy.result }}"
|
||||||
|
TITLE="klz-cables.com: $STATUS"
|
||||||
|
[[ "$STATUS" == "success" ]] && PRIORITY=5 || PRIORITY=8
|
||||||
|
|
||||||
curl -s -k -X POST "${{ secrets.GOTIFY_URL }}/message?token=${{ secrets.GOTIFY_TOKEN }}" \
|
curl -s -k -X POST "${{ secrets.GOTIFY_URL }}/message?token=${{ secrets.GOTIFY_TOKEN }}" \
|
||||||
-F "title=${{ needs.prepare.outputs.gotify_title }}" \
|
-F "title=$TITLE" \
|
||||||
-F "message=Erfolgreich deployt auf **${{ needs.prepare.outputs.target }}**\n\nVersion: **${{ needs.prepare.outputs.image_tag }}**\nCommit: ${{ needs.prepare.outputs.short_sha }} (${{ needs.prepare.outputs.commit_msg }})\nVon: ${{ github.actor }}\nRun: ${{ github.run_id }}" \
|
-F "message=Deploy to ${{ needs.prepare.outputs.target }} finished with status $STATUS.\nVersion: ${{ needs.prepare.outputs.image_tag }}" \
|
||||||
-F "priority=4" || true
|
-F "priority=$PRIORITY" || true
|
||||||
|
|
||||||
- name: 🔔 Gotify - Failure
|
|
||||||
if: |
|
|
||||||
needs.prepare.result == 'failure' ||
|
|
||||||
needs.qa.result == 'failure' ||
|
|
||||||
needs.build-app.result == 'failure' ||
|
|
||||||
needs.deploy.result == 'failure' ||
|
|
||||||
needs.pagespeed.result == 'failure'
|
|
||||||
run: |
|
|
||||||
curl -s -k -X POST "${{ secrets.GOTIFY_URL }}/message?token=${{ secrets.GOTIFY_TOKEN }}" \
|
|
||||||
-F "title=❌ Deployment FEHLGESCHLAGEN – ${{ needs.prepare.outputs.target || 'unknown' }}" \
|
|
||||||
-F "message=**Fehler beim Deploy auf ${{ needs.prepare.outputs.target }}**\n\nVersion: ${{ needs.prepare.outputs.image_tag || '?' }}\nCommit: ${{ needs.prepare.outputs.short_sha || '?' }}\nVon: ${{ github.actor }}\nRun: ${{ github.run_id }}\n\nBitte Logs prüfen!" \
|
|
||||||
-F "priority=8" || true
|
|
||||||
|
|||||||
46
Dockerfile
46
Dockerfile
@@ -1,50 +1,42 @@
|
|||||||
# Start from the pre-built Nextjs Base image
|
# Stage 1: Builder
|
||||||
FROM registry.infra.mintel.me/mintel/nextjs:latest AS builder
|
FROM registry.infra.mintel.me/mintel/nextjs:latest AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Ensure we are in a clean, standalone environment
|
# Arguments for build-time configuration
|
||||||
RUN rm -rf packages apps pnpm-workspace.yaml 2>/dev/null || true
|
|
||||||
|
|
||||||
# Build-time environment variables for Next.js
|
|
||||||
ARG NEXT_PUBLIC_BASE_URL
|
ARG NEXT_PUBLIC_BASE_URL
|
||||||
ARG DIRECTUS_URL
|
|
||||||
ARG NEXT_PUBLIC_TARGET
|
ARG NEXT_PUBLIC_TARGET
|
||||||
|
ARG DIRECTUS_URL
|
||||||
ARG NPM_TOKEN
|
ARG NPM_TOKEN
|
||||||
ARG REGISTRY_HOST
|
|
||||||
|
|
||||||
|
# Environment variables for Next.js build
|
||||||
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
||||||
ENV DIRECTUS_URL=$DIRECTUS_URL
|
|
||||||
ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
|
ENV NEXT_PUBLIC_TARGET=$NEXT_PUBLIC_TARGET
|
||||||
ENV NPM_TOKEN=$NPM_TOKEN
|
ENV DIRECTUS_URL=$DIRECTUS_URL
|
||||||
ENV SKIP_RUNTIME_ENV_VALIDATION=true
|
ENV SKIP_RUNTIME_ENV_VALIDATION=true
|
||||||
|
ENV CI=true
|
||||||
|
|
||||||
# Enable corepack (pnpm is already in base image)
|
# Enable pnpm
|
||||||
RUN corepack enable
|
RUN corepack enable
|
||||||
|
|
||||||
# Copy package files
|
# Copy lockfile and manifest for dependency installation caching
|
||||||
COPY package.json pnpm-lock.yaml* ./
|
COPY pnpm-lock.yaml package.json .npmrc* ./
|
||||||
|
|
||||||
# Install dependencies based on the preferred package manager
|
# Install dependencies with cache mount
|
||||||
# Create .npmrc for private registry access if token is present
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
||||||
RUN if [ -n "$NPM_TOKEN" ]; then \
|
--mount=type=secret,id=NPM_TOKEN \
|
||||||
REGISTRY="${REGISTRY_HOST:-npm.infra.mintel.me}" && \
|
export NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN 2>/dev/null || echo $NPM_TOKEN) && \
|
||||||
echo "@mintel:registry=https://$REGISTRY" > .npmrc && \
|
pnpm install --frozen-lockfile
|
||||||
echo "//$REGISTRY/:_authToken=$NPM_TOKEN" >> .npmrc; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
RUN pnpm install --frozen-lockfile
|
# Copy source code
|
||||||
|
|
||||||
# Copy local files
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the specific application
|
# Build application
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
|
|
||||||
# Production runner image
|
# Stage 2: Runner
|
||||||
FROM registry.infra.mintel.me/mintel/runtime:latest AS runner
|
FROM registry.infra.mintel.me/mintel/runtime:latest AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
# Production environment configuration
|
|
||||||
ENV HOSTNAME="0.0.0.0"
|
ENV HOSTNAME="0.0.0.0"
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
@@ -53,8 +45,6 @@ ENV NODE_ENV=production
|
|||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
# Ensure the cache directory specifically is writeable (Mintel Standard #16)
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/cache ./.next/cache
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|||||||
Reference in New Issue
Block a user