# SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
# SPDX-License-Identifier: CC0-1.0

# ! PLEASE NOTE THAT THIS IS ONLY FOR INTERNAL USE AND THE FILE IS UPLOADED ON GITHUB FOR CONVENIENCE  

# The bellow pipeline allows to build and deploy the website automatically, whenever developer pushes code to the application.
# The building stage uses a predefined docker image to improve performance. 

stages:
  - docker
  - build
  - deploy

ubuntu:publish-docker-image:
  stage: docker
  tags:
    - shell
  script:
    - cd .docker/ubuntu-gcc
    - docker image build -t esid:ubuntu-gcc .
  artifacts:
    expire_in: 1 hour
    paths:
      - .docker/ubuntu-gcc

ubuntu:build:
  stage: build
  image: esid:ubuntu-gcc
  tags:
    - docker
  before_script:
    - cd frontend
  script:
    - npm set cache .npm
    - npm ci
    - npm run build
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - frontend/.npm
  artifacts:
    expire_in: 1 hour
    paths:
      - frontend/build

pages:
  stage: deploy
  image: esid:ubuntu-gcc
  tags:
    - docker
  script:
    - folderName=$(echo "${CI_COMMIT_REF_NAME}" | tr / -)
    - rm -rf public/$folderName/
    - mkdir -p public/$folderName/
    - cp -rv frontend/build/* public/$folderName
    - cd public
    - tree -H '.' -L 1 -d --noreport --charset utf-8 > index.html
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - public
  artifacts:
    expire_in: 1 hour
    paths:
      - public