Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.46 KiB
Newer Older
###############################################################################
# Global variables
###############################################################################
variables:
  DEBIAN_FRONTEND: "noninteractive"
  LC_ALL: "C.UTF-8"
  LANG: "C.UTF-8"
  REPOSITORY_URL: "https://osm.etsi.org/gerrit/osm/osmclient.git"
  SFTP_SERVER: "vnf-catalog.etsi.org"
  SFTP_PORT: "29419"
  SFTP_USER: "osmsupport"
  ONDEMAND_DESTINATION_FOLDER: "Stable"

###############################################################################
# Anchor definition with common commands
###############################################################################
.default-script: &default_script
  - apt update && apt install -y gcc git make python3 python3 python3-pip python3-pycurl python3-setuptools software-properties-common wget
  - git submodule init
  - git submodule update
  - git clone https://osm.etsi.org/gerrit/osm/osmclient.git
  - pip3 install -r osmclient/requirements.txt -r osmclient/requirements-dev.txt
  - pip3 install osmclient/
  - rm -rf osmclient/
  - ./generate-packages.sh
  - mkdir temp
  # - mv magma/* temp
  - mv *.tar.gz charm-packages/*.tar.gz temp
  - osm -vvv repo-index --origin temp --destination vnf-catalog
  - rm -rf temp
###############################################################################
# Job to build artifacts
###############################################################################
build-local-repository:
  # Builds the repository locally but does not push if this is a new MR that
  # is still in development
  script: *default_script
  artifacts:
    paths:
      - vnf-catalog/
  # rules:
  #   - if: '$CI_COMMIT_REF_PROTECTED == "false"'
  #     when: on_success

###############################################################################
# Job to publish artifacts on successful merge (publication to Testing)
###############################################################################
publish-testing-repository:
  # Builds the repository and pushes it to ftp site when a MR is accepted
  image: ubuntu:22.04
  stage: deploy
  dependencies:
    - build-local-repository  # Reuses artifacts generated in build los artefactos generados en build
    - apt update && apt install -y sshpass
    - |
        sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF
          put -r vnf-catalog/* Testing
        EOF
    - if: '$CI_COMMIT_REF_NAME == "master"'  # Only in master
    # - if: '$CI_COMMIT_REF_PROTECTED == "true"'
    #   when: on_success

###############################################################################
# Job to publish artifacts on demand (publication to Testing)
###############################################################################
publish-ondemand-repository:
  image: ubuntu:22.04
  stage: deploy
  dependencies:
    - build-local-repository
  script:
    - apt update && apt install -y sshpass
    - |
        DESTINATION_FOLDER="${ONDEMAND_DESTINATION_FOLDER:-Testing}"
        echo "Uploading files to folder $DESTINATION_FOLDER in FTP ..."
        sshpass -p "$VNF_CATALOG_CREDENTIALS" sftp -o "StrictHostKeyChecking no" -P $SFTP_PORT $SFTP_USER@$SFTP_SERVER << EOF
          put -r vnf-catalog/* $DESTINATION_FOLDER
        EOF
  when: manual  # This job is run on demand
  allow_failure: true
  environment:
    name: production
    url: "ftp://$SFTP_SERVER/$DESTINATION_FOLDER"