Skip to content
Snippets Groups Projects
gitlab-ci.yml 3.12 KiB
.pre-deploy-uber-space-setup: &pre-deploy-uber-space-setup
  - apk add rsync openssh-client
  - eval $(ssh-agent -s)
  - echo "$CI_DEPLOYMENT_PRIVATE_KEY" | tr -d '\r' | ssh-add -
  - mkdir --mode 700 -p ~/.ssh
  - echo "$UBERSPACE_KNOWN_HOST" >> ~/.ssh/known_hosts

include:
  - project: "fit-connect/pipeline"
    ref: main
    file: "trivy.gitlab-ci.yml"
  - project: "fit-connect/pipeline"
    ref: main
    file: "workflows/no-duplicate-pipelines.gitlab-ci.yml"

stages:
  - lint
  - cve-scan
  - build
  - deploy

variables:
  DEPLOY_SERVER: fitko@dorado.uberspace.de

reuse:
  stage: lint
  variables:
    DOCKER_REGISTRY_READ: docker.fjd.de
  image:
    name: $DOCKER_REGISTRY_READ/fsfe/reuse:latest
    entrypoint: [""]
  script:
    - reuse lint
  cache: []

build:
  stage: build
  image: node:lts-alpine
  variables:
    GIT_BRANCH: $CI_COMMIT_REF_NAME
  before_script:
    - apk add git
    - yarn install
  script:
    - export NEXT_PUBLIC_BASE_PATH="" && [[ "$CI_COMMIT_REF_NAME" != "main" ]] && export NEXT_PUBLIC_BASE_PATH="/entwicklungsportal/$CI_COMMIT_REF_SLUG"
    - echo $NEXT_PUBLIC_BASE_PATH
    - yarn export
  artifacts:
    paths:
      - out/
    expire_in: 1 hour
  cache:
    paths:
      - node_modules/

deploy:preview:
  stage: deploy
  image: alpine:latest
  environment:
    name: preview/$CI_COMMIT_REF_NAME
    on_stop: undeploy:preview
    auto_stop_in: 1 week
    url: https://preview.docs.fitko.dev/entwicklungsportal/$CI_COMMIT_REF_SLUG/
  rules:
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
  before_script:
    - *pre-deploy-uber-space-setup
  script:
    - ssh $DEPLOY_SERVER mkdir -p preview.docs.fitko.dev/entwicklungsportal
    - rsync -rLvzc4 -e 'ssh -o CheckHostIP=no' --progress --delete ./out/. $DEPLOY_SERVER:preview.docs.fitko.dev/entwicklungsportal/$CI_COMMIT_REF_SLUG