1# ---  Siconos ci templates ---
2#
3# This file contains common definitions and templates for
4# continuous integration job of siconos project.
5#
6# Usage :
7# add in .gitlab-ci.yml :
8# include: <path-to-this-file>/gitlab-ci-siconos-templates.yml
9
10variables:
11  # Default ctest model. Warning : overwritten if set in schedules variables (as we expect)
12  ctest_build_model: Continuous
13  # Default behavior regarding cdash submission
14  cdash_submit: 0
15  # Default path to siconos conf. files
16  siconos_confs: ci_gitlab/siconos_confs
17  # By default we allow builds to run in parallel, but certain
18  # configurations may require non-parallel builds (cf. swig +
19  # serialization requires too much memory)
20  allow_parallel_build: 1
21  GIT_DEPTH: 1
22  #GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_NAME
23
24
25
26stages:
27  # --- Docker build stage ---
28  # The first stage contains jobs used to build
29  # docker images 'ready to use' for a Siconos build/install.
30  # Requirement for jobs in this stage :
31  # - should build and push a docker image to siconos project registry
32  # - should be allowed to failed (in order to avoid blocking of last stage jobs)
33  # - should run only when commit message contains [docker build]
34  # - use Dockerfile from ci_gitlab/dockerfiles/<image-name>
35  #
36  # Templates for these jobs : .docker-build (see below).
37  # We use different layers because some of the generated images are used
38  # as a starting point for other images.
39  - docker-build
40  - docker-build-layer2
41  - docker-build-layer3
42  # --- Build stage ---
43  # jobs run on images generated in previous stage, available in siconos registry:
44  # https://gricad-gitlab.univ-grenoble-alpes.fr/nonsmooth/siconos/container_registry
45  # - configure : run cmake
46  # - run tests
47  # - submit to cdash
48  # To execute cmake and configure the project
49  - configure
50  # To execute make and build the project
51  - build
52  # To run all tests
53  - test
54  # To install software, generate a "siconos-ready" docker image and asave it in the registry.
55  - install
56  # To build and run all examples
57  - examples
58  # Templates for these jobs : .siconos-build (see below).
59  # --- Doc stages ---
60  # Build documentation (run doxygen, sphinx, ...)
61  - doc-build
62  # Publish html pages
63  - doc-deploy
64
65
66# Define rules used to create (or not) CI jobs
67# Each rule is checked and if the condition is not true, the next one is checked, until the end.
68workflow:
69  rules:
70    # No CI when commit message starts with wip
71    - if: $CI_COMMIT_MESSAGE =~ /^wip.*$/
72      when: never
73    # Other cases: delegates the choice of the behavior to each job (see templates)
74    - if: '$CI_COMMIT_BRANCH'
75
76# --- Templates definitions ---
77# Each template can be used in CI jobs, with the keyword 'extends'.
78
79.docker-rules:
80   rules:
81    - if: $CI_COMMIT_MESSAGE =~ /^\[docker-build\]/
82      when: always
83#    - if: $CI_COMMIT_BRANCH == "master"
84#      when: always
85    - if: $CI_COMMIT_TAG
86      when: always
87    - when: never
88
89.docker-manual-rules:
90    rules:
91    - if: $CI_COMMIT_MESSAGE =~ /^\[docker-build\]/
92      when: manual
93    - when: never
94
95# A rule to automatically start CI in child project siconos-tutorials.
96# Rule: commit message must contain [with examples]
97.examples-rules:
98  rules:
99    - if: $CI_COMMIT_MESSAGE =~ /\[with examples\]/
100      when: always
101    - when: never
102
103
104
105# -- Template used to describe docker-build jobs --
106#
107# - build and push a docker image into siconos project registry
108#   image name : $CI_REGISTRY_IMAGE/$IMAGE_NAME
109# - should be allowed to failed (in order to avoid blocking of the jobs in the next stages)
110# - should run only when commit message starts with [docker build]
111# - use Dockerfile from ci_gitlab/dockerfiles/<IMAGE_NAME>
112# - will be tagged <IMAGE_NAME>:latest.
113# Based on Kaniko stuff. For details, see https://docs.gitlab.com/ee/ci/docker/using_kaniko.html.
114.docker-create-image:
115  # Created if the commit message starts with [docker-build] or
116  # when the master branch is updated.
117  image:
118    name: gcr.io/kaniko-project/executor:debug
119    entrypoint: [""]
120  variables:
121    GIT_STRATEGY: clone
122  stage: docker-build
123  script:
124    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
125    - sed -i "s|REGISTRY_PATH|$CI_PROJECT_PATH|g" $CI_PROJECT_DIR/ci_gitlab/dockerfiles/$IMAGE_NAME/Dockerfile
126    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile ci_gitlab/dockerfiles/$IMAGE_NAME/Dockerfile --destination $CI_REGISTRY_IMAGE/sources/$IMAGE_NAME:latest
127
128.docker-build:
129  extends:
130    - .docker-rules
131    - .docker-create-image
132
133.docker-manual:
134  extends:
135    - .docker-manual-rules
136    - .docker-create-image
137
138.siconos-next:
139  image: gricad-registry.univ-grenoble-alpes.fr/nonsmooth/siconos/sources/ubuntu20.04
140  script:
141    - echo "bonjour"
142  #needs: []
143
144# Use these rules for jobs that must be created:
145# - when updating master branch
146# - when the commit message starts with [all-jobs]
147# - when commiting a tag
148.full-ci-rules:
149  rules:
150    - if: '$CI_COMMIT_BRANCH == "master"'
151      when: always
152    - if: $CI_COMMIT_TAG
153      when: always
154    - if: $CI_COMMIT_MESSAGE =~ /^\[all-jobs\]/
155      when: always
156    - when: never
157
158# -- Template used for siconos configure-build-test-install jobs  --
159# .siconos-ctest must be overloaded by a specific template like
160# .siconos-configure, .siconos-build ...
161# 1. Pulls an image (possibly from siconos registry)
162#   named  IMAGE_NAME
163# 2. executes ctest script. The specific case (configure, build ...) is determined
164
165.siconos-ctest:
166  image: $IMAGE_NAME
167  script:
168    - "sh ci_gitlab/ctest_siconos.sh $ctest_mode $user_file"
169
170# - Template to complete .siconos-ctest
171# Configure (cmake) step.
172# Keeps build directory for next stages (build/install/test)
173.siconos-configure:
174  extends: .siconos-ctest
175  variables:
176    #GIT_STRATEGY: clone
177    ctest_mode: Configure
178  stage: configure
179  artifacts:
180    paths:
181      - build
182    expire_in: 2 days
183
184# - Template to complete .siconos-ctest
185# build (make) step.
186# Gets artifacts from .siconos-configure and keep build dir. as artifact for next stages.
187.siconos-build:
188  extends: .siconos-ctest
189  variables:
190    ctest_mode: Build
191    #GIT_STRATEGY: none
192  stage: build
193  artifacts:
194    paths:
195      - build
196    expire_in: 2 days
197
198# - Template to complete .siconos-ctest
199# test step.
200# Gets artifacts from .siconos-build
201.siconos-test:
202  extends: .siconos-ctest
203  variables:
204    OPENBLAS_NUM_THREADS: 1
205    ctest_mode: Test
206    #GIT_STRATEGY: none
207  stage: test
208
209# -- Template to execute a the full pipeline (configure/build/test)
210# Keeps build directory for next stage (install) as artifact.
211.siconos-full:
212  extends: .siconos-ctest
213  variables:
214    ctest_mode: all
215    #GIT_STRATEGY: clone
216  stage: configure
217  artifacts:
218    paths:
219      - build
220    expire_in: 2 days
221
222.siconos-full-with-examples:
223  image: $IMAGE_NAME
224  variables:
225    ctest_mode: all
226  stage: configure
227  script:
228    - "sh ci_gitlab/ctest_siconos.sh $ctest_mode $user_file"
229    - cd $HOME; git clone https://gricad-gitlab.univ-grenoble-alpes.fr/nonsmooth/siconos-tutorials.git
230  artifacts:
231    paths:
232      - build
233    expire_in: 2 days
234
235
236# Installs siconos and generates a docker image with a full/uptodate install of siconos
237# Uses output (build from artifacts) from a previous job (e.g. debian:build or similar).
238# The docker image is saved in the project registries.
239.siconos-install:
240  image:
241    name: gcr.io/kaniko-project/executor:debug
242    entrypoint: [""]
243  variables:
244    #GIT_STRATEGY: none
245    #REG_NAME: $CI_REGISTRY_IMAGE
246  stage: install
247  script:
248    - cp $CI_PROJECT_DIR/ci_gitlab/dockerfiles/requirements.txt build/
249    - cat $CI_PROJECT_DIR/ci_gitlab/dockerfiles/install_template| sed -e "s|IMAGENAME|$IMAGE_NAME|g" >> build/Dockerfile
250    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_DEPLOY_USER\",\"password\":\"$CI_DEPLOY_PASSWORD\"}}}" > /kaniko/.docker/config.json
251    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/build/Dockerfile --destination $CI_REGISTRY/nonsmooth/siconos-tutorials/$siconos_docker_name:$CI_COMMIT_SHORT_SHA --destination $CI_REGISTRY/nonsmooth/siconos-tutorials/$siconos_docker_name:latest --cleanup
252
253# Installs siconos and generates a docker image with a full/uptodate install of siconos
254# Uses output (build from artifacts) from a previous job (e.g. debian:build or similar).
255# The docker image is saved in the project registries.
256# It uses a jupyter image and contains siconos-tutorials with its notebooks.
257# Source : ci_gitlab/dockerfiles/siconoslab/Dockerfile
258.siconos-jupyterlab-install:
259  image:
260    name: gcr.io/kaniko-project/executor:debug
261    entrypoint: [""]
262  variables:
263    #GIT_STRATEGY: none
264    #REG_NAME: $CI_REGISTRY_IMAGE
265  stage: install
266  script:
267    - cp $CI_PROJECT_DIR/ci_gitlab/dockerfiles/requirements.txt build/
268    - cat $CI_PROJECT_DIR/ci_gitlab/dockerfiles/siconoslab/Dockerfile| sed -e "s|IMAGENAME|$IMAGE_NAME|g" >> build/Dockerfile
269    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_DEPLOY_USER\",\"password\":\"$CI_DEPLOY_PASSWORD\"}}}" > /kaniko/.docker/config.json
270    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/build/Dockerfile --destination $CI_REGISTRY/nonsmooth/siconos-tutorials/$siconos_docker_name:$CI_COMMIT_SHORT_SHA --destination $CI_REGISTRY/nonsmooth/siconos-tutorials/$siconos_docker_name:latest --cleanup
271