Update .gitlab-ci.yml file

This commit is contained in:
2025-11-12 22:59:42 +01:00
parent c0aac9592a
commit b8706721d6

View File

@@ -1,52 +1,40 @@
# ------------------------------- stages: [install, build, deploy]
# USBcheck.it GitLab CI/CD Setup
# -------------------------------
# Features:
# - Build static site (Astro, Hugo, Next, etc.)
# - Deploys via SSH to all-inkl (staging + production)
# - Separate environments for safety
# -------------------------------
stages:
- install
- build
- deploy
variables: variables:
NODE_ENV: production NODE_ENV: production
# Directory where the static site is built
BUILD_DIR: dist BUILD_DIR: dist
# Cache node_modules for faster builds # Gemeinsames pnpm-Setup für alle Node-Jobs
.node_pnpm: &node_pnpm
image: node:20-bullseye
before_script:
- echo "🧩 Corepack/Pnpm aktivieren..."
- corepack enable
- corepack prepare pnpm@9.12.0 --activate
- pnpm -v
cache: cache:
key: ${CI_COMMIT_REF_SLUG} key: ${CI_COMMIT_REF_SLUG}
paths: paths:
- node_modules/ - node_modules/
# -------------------------------
# 1. Install dependencies
# -------------------------------
install: install:
stage: install stage: install
image: node:20-bullseye <<: *node_pnpm
script: script:
- echo "🧩 Installing dependencies..." - echo "📦 Installing deps..."
- corepack enable # Nutze --frozen-lockfile nur, wenn pnpm-lock.yaml im Repo committed ist
- corepack prepare pnpm@latest --activate - if [ -f pnpm-lock.yaml ]; then pnpm install --frozen-lockfile --reporter=append-only; else pnpm install --reporter=append-only; fi
- pnpm install --frozen-lockfile --reporter=append-only
artifacts: artifacts:
paths: paths:
- node_modules/ - node_modules/
expire_in: 1h expire_in: 1h
# -------------------------------
# 2. Build project
# -------------------------------
build: build:
stage: build stage: build
image: node:20-bullseye <<: *node_pnpm
script: script:
- echo "🏗️ Building project..." - echo "🏗️ Building..."
- pnpm build - pnpm build
- echo "✅ Build complete." - echo "✅ Build complete."
artifacts: artifacts:
@@ -54,28 +42,18 @@ build:
- ${BUILD_DIR}/ - ${BUILD_DIR}/
expire_in: 1 week expire_in: 1 week
# -------------------------------
# 3. Deployment template
# -------------------------------
.deploy_template: &deploy .deploy_template: &deploy
stage: deploy stage: deploy
image: alpine:3.20 image: alpine:3.20
before_script: before_script:
- echo "🚀 Preparing SSH..."
- apk add --no-cache openssh-client rsync - apk add --no-cache openssh-client rsync
- mkdir -p ~/.ssh - mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_ed25519 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_ed25519
- chmod 600 ~/.ssh/id_ed25519 - chmod 600 ~/.ssh/id_ed25519
- ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts - ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
script: script:
- echo "🔄 Deploying to $DEPLOY_PATH ..."
- rsync -az --delete ${BUILD_DIR}/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH - rsync -az --delete ${BUILD_DIR}/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH
- echo "✅ Deployment complete."
only: []
# -------------------------------
# 3a. Staging deployment
# -------------------------------
deploy:staging: deploy:staging:
<<: *deploy <<: *deploy
variables: variables:
@@ -87,9 +65,6 @@ deploy:staging:
- develop - develop
- merge_requests - merge_requests
# -------------------------------
# 3b. Production deployment
# -------------------------------
deploy:production: deploy:production:
<<: *deploy <<: *deploy
variables: variables: