86 lines
2.5 KiB
YAML
86 lines
2.5 KiB
YAML
# ---------------------------------------------------------
|
|
# GLOBAL SETTINGS
|
|
# ---------------------------------------------------------
|
|
image: oven/bun:alpine
|
|
|
|
stages:
|
|
- build
|
|
- test
|
|
- deploy
|
|
|
|
# Global cache used by default for Node/Bun jobs
|
|
cache:
|
|
key:
|
|
files:
|
|
- bun.lock
|
|
paths:
|
|
- .next/cache/
|
|
- node_modules/
|
|
|
|
# ---------------------------------------------------------
|
|
# STAGE 1: Build
|
|
# ---------------------------------------------------------
|
|
build_job:
|
|
stage: build
|
|
tags:
|
|
- nextjs
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
|
- if: $CI_COMMIT_BRANCH == 'main'
|
|
script:
|
|
- echo "Installing dependencies..."
|
|
- bun install --frozen-lockfile
|
|
- echo "Building the Next.js application..."
|
|
- bun run build
|
|
artifacts:
|
|
paths:
|
|
- .next/
|
|
- public/
|
|
- package.json
|
|
expire_in: 1 week
|
|
|
|
# ---------------------------------------------------------
|
|
# STAGE 2: SonarQube Code Analysis
|
|
# ---------------------------------------------------------
|
|
sonarqube_check:
|
|
stage: test
|
|
# Override the image just for this job, including the blank entrypoint Sonar requires
|
|
image:
|
|
name: sonarsource/sonar-scanner-cli:11
|
|
entrypoint: [""]
|
|
tags:
|
|
- nextjs
|
|
variables:
|
|
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines location of the analysis task cache
|
|
GIT_DEPTH: "0" # Required for accurate blame/issue assignment
|
|
# Override the global cache so Sonar can cache its own plugins separately
|
|
cache:
|
|
key: "sonar-cache-$CI_COMMIT_REF_SLUG"
|
|
paths:
|
|
- "${SONAR_USER_HOME}/cache"
|
|
|
|
needs: ["build_job"]
|
|
# allow_failure means if your code has "code smells", it won't stop your deployment to Portainer
|
|
allow_failure: true
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
|
|
- if: $CI_COMMIT_BRANCH == 'main'
|
|
script:
|
|
# Notice we don't need to specify the token here, the scanner automatically looks for $SONAR_TOKEN in GitLab CI/CD variables
|
|
- sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
|
|
|
|
# ---------------------------------------------------------
|
|
# STAGE 3: Deploy via Portainer GitOps
|
|
# ---------------------------------------------------------
|
|
deploy_production:
|
|
stage: deploy
|
|
image: curlimages/curl:latest
|
|
tags:
|
|
- nextjs
|
|
needs: ["build_job"] # We only explicitly wait for the build to succeed to deploy
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == "main"
|
|
script:
|
|
- echo "Triggering Portainer GitOps Webhook..."
|
|
- curl -X POST "https://portainer.vpn.pascalyazid.com/api/stacks/webhooks/YOUR-UUID"
|