Files
web2.0-frontend/.gitlab-ci.yml
2025-12-10 20:51:29 +02:00

154 lines
3.6 KiB
YAML

stages:
- setup
- audit
- lint
- build
- test
- publish
- deploy
install:
image: node:20
stage: setup
script:
- npm ci
after_script:
- node -v
- npm -v
artifacts:
paths:
- node_modules
expire_in: 1 week
audit:
image: node:20
needs: ["install"]
allow_failure: true
stage: audit
script:
- npm audit --audit-level=critical
es:lint:
image: node:20
needs: ["install"]
stage: lint
script:
- npm run lint:es
css:lint:
image: node:20
needs: ["install"]
stage: lint
script:
- npm run lint:css
# test:unit:
# image: node:20
# stage: test
# script:
# - npm run test:unit
build:
image: node:20
needs: ["install"]
stage: build
script:
- NODE_ENV=test npm run build
dependencies:
- install
artifacts:
paths:
- .next
expire_in: 1 week
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
- .next/cache/
test:e2e:
# Use a Cypress image which has Node 20 + Chrome and runs as root (solves permission issues)
image: cypress/browsers:latest
needs: ["install", "build"]
stage: test
script:
# No sudo needed if running as root.
# If permissions are still wrong, we CAN fix them because we are root.
# But usually, being root means we can overwrite/rm the files anyway.
# 1. Clean install to ensure native modules match this container's environment
- npm ci
# 2. Run TestCafe (using the CI script for headless mode)
- npm run testcafe:ci
artifacts:
paths:
- e2e-screenshots
expire_in: 1 week
when: on_failure
publish:dev:
stage: publish
image: docker:25-cli
needs: ["build", "test:e2e", "es:lint", "css:lint"]
services:
- docker:25-dind
only:
- master
script:
- docker build . -t "$IMAGE_NAME":latest --build-arg SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" --build-arg NEXT_PUBLIC_DEPLOY_ENV=development --build-arg NEXT_PUBLIC_API_URL=https://api.dev.sahkoinsinoorikilta.fi/api --build-arg NEXT_PUBLIC_SITE_URL=https://dev.sahkoinsinoorikilta.fi
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push "$IMAGE_NAME":latest
publish:prod:
stage: publish
image: docker:25-cli
services:
- docker:25-dind
only:
- production
script:
- docker build . -t "$IMAGE_NAME":prod --build-arg SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN"
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push "$IMAGE_NAME":prod
deploy:dev:
stage: deploy
image: docker:25-cli
only:
- master
environment:
name: dev
url: https://dev.sahkoinsinoorikilta.fi
variables:
DOCKER_HOST: $DEV_CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1
before_script:
- mkdir -p ~/.docker
- echo "$DEV_TLSCACERT" > ~/.docker/ca.pem
- echo "$DEV_TLSCERT" > ~/.docker/cert.pem
- echo "$DEV_TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker stack deploy --with-registry-auth -c stack-compose-dev.yml "$SERVICE_NAME"
deploy:prod:
stage: deploy
image: docker:25-cli
only:
- production
environment:
name: production
url: https://sahkoinsinoorikilta.fi
variables:
DOCKER_HOST: $CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1
before_script:
- mkdir -p ~/.docker
- echo "$TLSCACERT" > ~/.docker/ca.pem
- echo "$TLSCERT" > ~/.docker/cert.pem
- echo "$TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME"