Skip to content
Snippets Groups Projects
.gitlab-ci.yml 4.59 KiB
.release-rules: &release-rules
  # rule to run job on a tag-reference which has the form number.number.number (semantic versioning)
  # or number.number.number-text (semantic versioning + release-name)
  # and where a Dockerfile exists
  - if: $CI_COMMIT_TAG =~ /^\d+[.]\d+[.]\d+$/ || $CI_COMMIT_TAG =~ /^\d+[.]\d+[.]\d+[-]\S+$/
    exists:
      - Dockerfile

stages:
  - build
  - deploy
  - release


build-openapi-scheme:
  stage: build
  image: python:3.10-slim
  variables:
    OPENAPI_JSON: ./public/api.json
  before_script:
    - apt-get update
    - apt-get install -y gcc libldap2-dev libsasl2-dev libmagic-dev
    - pip install --upgrade pip
    - pip install poetry==1.5.1
    - poetry install --without dev,test --no-root
  script:
    - mkdir public
    - mkdir logs
    - poetry run python manage.py spectacular --validate --lang en --format openapi-json --file $OPENAPI_JSON
  artifacts:
    paths:
      - $OPENAPI_JSON


deploy_spec:
  stage: deploy
  image: node:18-alpine
  needs:
    - build-openapi-scheme
  before_script:
    - apk update
    - apk add nodejs npm lftp
    - node -v
    - npm i -g npm@latest
    - npm install swagger-ui-dist@3.52.5
  script:
    - cp -rp node_modules/swagger-ui-dist/* ./public
    - 'sed -i "s@.*url.*@url: \"api.json\",@" ./public/index.html'
    - echo "Deploying AURA Steering API Spec..."
    - lftp -c "set ftp:ssl-allow no; open -u $FTP_AURA_RADIO_USER,$FTP_AURA_RADIO_PWD $FTP_AURA_RADIO_HOST; mirror -Rnev ./public/ ./api.aura.radio/steering --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
    - echo "AURA Steering API Spec successfully deployed."
  artifacts:
    paths:
      - public
    expire_in: 2 days
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: always


docker-push:
  # Use the official docker image.
  image: docker:latest
  stage: release
  variables:
    # the name of the image without version
    AURA_IMAGE_NAME: "autoradio/steering"
  services:
    - docker:dind
  before_script: