.gitlab-ci.yml 3.25 KB
Newer Older
Enrique Garcia's avatar
Enrique Garcia committed
1
stages:
Enrique Garcia's avatar
Enrique Garcia committed
2
 - install
3
 - test
Vuillaume's avatar
Vuillaume committed
4
 - build_container
Enrique Garcia's avatar
Enrique Garcia committed
5 6
 - deploy

Enrique Garcia's avatar
Enrique Garcia committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
install_project:
  stage: install
  # Please notice that we are using a different image just for easier syntax in the testing of the building and
  #  testing of the repository
  image: continuumio/miniconda3:latest
  script:
    - . /opt/conda/etc/profile.d/conda.sh
    - conda env create -f environment.yml
    - conda activate escape_template
    - pip install .
    - square_number -h
    - square_number -i -12.5
  only:
    - branches

test_project:
  stage: test
  image: python:3.6-buster
  script:
    - pip install pytest
    - pip install .
    - pytest .
  only:
    - branches
31

Enrique Garcia's avatar
Enrique Garcia committed
32
test_docker_registry:
Enrique Garcia's avatar
Enrique Garcia committed
33 34
  # Test of last container in registry
  stage: test
Enrique Garcia's avatar
Enrique Garcia committed
35
  image: gitlab-registry.in2p3.fr/escape2020/wp3/template_project_escape:latest
Enrique Garcia's avatar
Enrique Garcia committed
36 37 38 39 40 41
  script:
    - source activate escape_template
    - square_number -i -12.5
  except:
    - master
    - tags
Enrique Garcia's avatar
Enrique Garcia committed
42

Vuillaume's avatar
Vuillaume committed
43

Enrique Garcia's avatar
Enrique Garcia committed
44
build_singularity_image:
Vuillaume's avatar
Vuillaume committed
45
  stage: build_container
Enrique Garcia's avatar
Enrique Garcia committed
46 47
  image: singularityware/singularity:gitlab-2.6
  script:
Vuillaume's avatar
Vuillaume committed
48 49 50
    # You should have added before your Singularity recipe in a Singularity dir
    - export IMAGE_NAME=$CI_PROJECT_NAME
    - singularity build $IMAGE_NAME.simg Singularity/Singularity
Enrique Garcia's avatar
Enrique Garcia committed
51

Vuillaume's avatar
Vuillaume committed
52
    - mkdir -p singularity_build && cp *.simg singularity_build
Enrique Garcia's avatar
Enrique Garcia committed
53
    #- mkdir -p singularity_build && cp Singularity/Singularity singularity_build
Vuillaume's avatar
Vuillaume committed
54
    - ls singularity_build
Enrique Garcia's avatar
Enrique Garcia committed
55 56
  artifacts:
    paths:
Enrique Garcia's avatar
Enrique Garcia committed
57
      - singularity_build/*.simg
Enrique Garcia's avatar
Enrique Garcia committed
58
      #- singularity_build/Singularity
Enrique Garcia's avatar
Enrique Garcia committed
59 60
  only:
    - tags
Enrique Garcia's avatar
Enrique Garcia committed
61

Enrique Garcia's avatar
Enrique Garcia committed
62
build_docker_image:
Vuillaume's avatar
Vuillaume committed
63
  stage: build_container
Enrique Garcia's avatar
Enrique Garcia committed
64 65 66 67 68
  image: docker:19.03.12
  services:
    - docker:19.03.12-dind
  before_script:
    - cat /etc/os-release  # "Alpine Linux v3.12"
Enrique Garcia's avatar
Enrique Garcia committed
69
    - apk add --no-cache git
Enrique Garcia's avatar
Enrique Garcia committed
70 71 72 73
    - export LAST_RELEASE=`git ls-remote --tags --refs --sort="v:refname" $CI_PROJECT_URL.git | tail -n1 | sed 's/.*\///'`
    - echo $LAST_RELEASE
  script:
    - cd Docker
Vuillaume's avatar
Vuillaume committed
74
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
Enrique Garcia's avatar
Enrique Garcia committed
75 76
    - docker build -t $CI_REGISTRY_IMAGE:$LAST_RELEASE .
    - docker push $CI_REGISTRY_IMAGE:$LAST_RELEASE
Enrique Garcia's avatar
Enrique Garcia committed
77 78
    - docker tag $CI_REGISTRY_IMAGE:$LAST_RELEASE $CI_REGISTRY_IMAGE:latest
    - docker push $CI_REGISTRY_IMAGE:latest
79

80
    # Save docker image into a file to be uploaded in next stage
Vuillaume's avatar
Vuillaume committed
81
    - docker save -o Docker_${CI_PROJECT_NAME}_$LAST_RELEASE.tar $CI_REGISTRY_IMAGE:$LAST_RELEASE
Enrique Garcia's avatar
Enrique Garcia committed
82 83
    - cd .. && mkdir -p docker_build && cp Docker/*.tar docker_build
    - ls docker_build
84 85
  artifacts:
    paths:
Enrique Garcia's avatar
Enrique Garcia committed
86
      - docker_build/Docker_*.tar
Enrique Garcia's avatar
Enrique Garcia committed
87 88
  only:
    - tags
89

Vuillaume's avatar
Vuillaume committed
90

Enrique Garcia's avatar
Enrique Garcia committed
91
deploy_zenodo:
Enrique Garcia's avatar
Enrique Garcia committed
92
  stage: deploy
Vuillaume's avatar
Vuillaume committed
93 94 95
  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
Enrique Garcia's avatar
Enrique Garcia committed
96 97
  dependencies:
    - build_singularity_image
98
    - build_docker_image
Enrique Garcia's avatar
Enrique Garcia committed
99
  before_script:
Enrique Garcia's avatar
Enrique Garcia committed
100
    - eossr-check-connection-zenodo --token $ZENODO_TOKEN --sandbox False -p $CI_PROJECT_DIR
Enrique Garcia's avatar
Enrique Garcia committed
101
    - mkdir -p zenodo_build
Enrique Garcia's avatar
fix CI  
Enrique Garcia committed
102 103
    - ls docker_build && cp docker_build/* zenodo_build
    - ls singularity_build && cp singularity_build/* zenodo_build
Enrique Garcia's avatar
Enrique Garcia committed
104
  script:
Vuillaume's avatar
Vuillaume committed
105 106
    - gitlab_prepare_upload_zenodo.sh $CI_PROJECT_NAME $CI_PROJECT_DIR zenodo_build
    - ls zenodo_build
Enrique Garcia's avatar
Enrique Garcia committed
107

Kay Graf's avatar
Kay Graf committed
108
    - eossr-upload-repository -t $ZENODO_TOKEN -s False -i zenodo_build -id $ZENODO_PROJECT_ID
Enrique Garcia's avatar
Enrique Garcia committed
109 110
  only:
    - tags