Build a Singularity image, a Docker container and upload your project and images to the OSSR

This code snippet will:

  • Builds a Docker container during the CI process.

  • Builds a Singularity image during the CI process.

  • Makes available the created artifacts (both images) to be used in the next CI stages.

  • Uploads the next released version of the current project, together with both images, to the ESCAPE-OSSR (The ESCAPE2020 Zenodo community).

For details on each CI stage, have a look before to the examples in this same directory.

stages:
 - build_container
 - deploy

build_singularity_image:
  stage: build_container
  image: singularityware/singularity:gitlab-2.6
  script:
    - export IMAGE_NAME=$CI_PROJECT_NAME  # Choose the name of the image
    - singularity build $IMAGE_NAME.simg Singularity/Singularity

    - mkdir -p container_build && cp *.simg container_build
    - mkdir -p container_build && cp Singularity/Singularity container_build
    - ls container_build
  artifacts:
    paths:
      - container_build/Singularity.simg
      - container_build/Singularity
  only:
    - tags

build_docker_image:
  stage: build_container
  image: docker:19.03.12
  services:
    - docker:19.03.12-dind
  before_script:
    - cat /etc/os-release  # "Alpine Linux v3.12"
    - apk add git
    - export LAST_RELEASE=`git ls-remote --tags --refs --sort="v:refname" $CI_PROJECT_URL.git | tail -n1 | sed 's/.*\///'`
    - if [ -z "$LAST_RELEASE" ]; then export LAST_RELEASE="main"; fi;
    - echo $LAST_RELEASE
  script:
    - cd Docker
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
    - docker build -t $CI_REGISTRY_IMAGE:$LAST_RELEASE .
    - docker push $CI_REGISTRY_IMAGE:$LAST_RELEASE

    # Save docker image into a file to be uploaded in next stage
    - docker save -o Docker_${CI_PROJECT_NAME}_$LAST_RELEASE.tar $CI_REGISTRY_IMAGE:$LAST_RELEASE
    - cd .. && mkdir -p container_build && cp Docker/*.tar container_build
    - ls container_build
  artifacts:
    paths:
      - container_build/Docker_*.tar
  only:
    - tags


deploy_zenodo:
  stage: deploy
  image: gitlab-registry.in2p3.fr/escape2020/wp3/eossr:latest
  # The `dependencies` key (and field) is added to this stage ONLY because we have created 
  #  in previous stages some artifacts
  dependencies:
    - build_singularity_image
    - build_docker_image
  before_script:
    - eossr-check-connection-zenodo --token $ZENODO_TOKEN --sandbox False -p $CI_PROJECT_DIR
    - mkdir -p /zenodo_build && cp container_build/* /zenodo_build
    - rm -rf container_build
  script:
    - gitlab_prepare_upload_zenodo.sh $CI_PROJECT_NAME $CI_PROJECT_DIR /zenodo_build
    - ls /zenodo_build

    - eossr-upload-repository -t $ZENODO_TOKEN -s False -i /zenodo_build -id $ZENODO_RECORD_ID

  only:
    - tags