Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (6)
...@@ -4,11 +4,11 @@ stages: ...@@ -4,11 +4,11 @@ stages:
- release - release
variables: variables:
CONTAINER_TEST_IMAGE: boileaum/rosen:$CI_COMMIT_REF_NAME CONTAINER_TEST_IMAGE: cvdiunistra/rosen:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: boileaum/rosen:latest CONTAINER_RELEASE_IMAGE: cvdiunistra/rosen:latest
before_script: before_script:
- echo $DOCKERHUB_PASSWD | docker login -u boileaum --password-stdin - echo $DOCKERHUB_PASSWD | docker login -u cvdiunistra --password-stdin
b:docker: b:docker:
stage: build stage: build
...@@ -43,5 +43,5 @@ r:docker: ...@@ -43,5 +43,5 @@ r:docker:
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE - docker push $CONTAINER_RELEASE_IMAGE
only: only:
- master - exo3
# TP GitLab CI
## Execution du notebook jupyter
- [Installer Anaconda](https://www.anaconda.com/download) pour disposer de `jupyter-notebook`
- Ajouter le support du noyau bash :
```
pip install bash_kernel
python -m bash_kernel.install
```
- Lancer le notebook :
```
jupyter notebook tp-gitlab-ci.ipynb
```
\ No newline at end of file
cicd_pipeline_infograph.png

31.7 KiB

FROM boileaum/pythran:latest FROM boileaum/pythran:latest
MAINTAINER Matthieu Boileau <matthieu.boileau@math.unistra.fr>
ENV HOME /home/euler ENV HOME /home/euler
ADD . $HOME/rosen ADD . $HOME/rosen
......
fork.png

53.1 KiB

%% Cell type:markdown id: tags:
### Journée X/Stra-Dev Intégration continue
21 novembre 2017
---
# L'intégration continue avec GitLab
![image.png](tanuki.png)
## *Session pratique*
- [Notebook](http://nbviewer.jupyter.org/urls/)
- [Slideshow]()
---
Matthieu Boileau - <matthieu.boileau@math.unistra.fr>
*Contenu sous licence [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0)*
%% Cell type:code id: tags:
``` bash
```
#!/bin/bash
set -x
nbfile="tp-gitlab-ci.ipynb"
jupyter-nbconvert $nbfile --to slides --post serve $2 --allow-errors
.PHONY: clean pythran all: helloworld pythran
all: C pythran helloworld:
gcc helloworld.c -o helloworld.e
C: test: helloworld
gcc helloworld.c -o helloworld.e python test_helloworld.py
pythran: pythran:
pythran rosenbrock.py -o rosenbrock_pythran.so pythran rosenbrock.py -o rosenbrock_pythran.so
clean: clean:
rm -rf *.o *.e *.so *.pyf *.pyc __pycache__ rm -rf *.o *.e *.so *.pyf *.pyc __pycache__
#!/bin/bash
docker run -ti --rm -v $(pwd):/home/euler boileaum/pythran:latest
tanuki.png

7.87 KiB

%% Cell type:markdown id: tags:
### Journée X/Stra-Dev Intégration continue
21 novembre 2017
---
# L'intégration continue avec GitLab
![image.png](tanuki.png)
## *Session pratique*
---
Matthieu Boileau - <matthieu.boileau@math.unistra.fr>
*Contenu sous licence [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0)*
%% Cell type:markdown id: tags:
# GitLab CI
GitLab CI propose une chaîne complète d'intégration continue intégrée à son système de forge logicielle.
![](cicd_pipeline_infograph.png)
<span style="font-size:0.7em;"><https://docs.gitlab.com/ee/ci/README.html></span>
**Les avantages :**
- la simplicité de mise en oeuvre
- la robustesse d'une solution intégrée
%% Cell type:markdown id: tags:
## Le gitlab runner
### Introduction
- `gitlab-runner` est un démon installé sur une machine destinée à exécuter les tâches d'intégration continue.
- Pour chaque *runner* enregistré, `gitlab-runner` écoute l'instance de gitlab correspondante dans l'attente d'une tâche
- Cette tâche est déclenchée par des évènements (`push`, `merge`, etc.) sur le projet avec lequel il est lié
- Ce lien est créé à l'enregistrement du *runner* par un token associé au projet.
[**Doc en ligne**](https://docs.gitlab.com/ce/ci/runners/#shared-vs-specific-runners)
%% Cell type:markdown id: tags:
### Runners : *shared* vs *specific*
- *shared* : n'importe quel projet peut s'en servir. Seul l'administrateur du GitLab peut enregistrer des runners partagés.
- *specific* : seul le créateur du runner peut s'en servir dans d'autres projets
> **Attention** : les runners partagés sont pratiques mais peuvent présenter des [problèmes de sécurité](https://docs.gitlab.com/ee/ci/runners/README.html#be-careful-with-sensitive-information).
### Runners : *locked* vs *unlocked runners*
- *locked* : le runner ne peut être utilisé que pour le projet avec lequel il est lié
- *unlocked* : le créateur du runner peut l'utiliser dans ses autres projets
%% Cell type:markdown id: tags:
### Installer `gitlab-runner`
La **[procédure](https://docs.gitlab.com/runner/install/)** dépend du système d'exploitation.
%% Cell type:markdown id: tags:
## Fork du TP
Faire un *fork* du projet sur votre compte GitLab en allant sur la page d'accueil du projet
![fork.png](fork.png)
ou en suivant [ce lien](https://git.unistra.fr/m.boileau/tp-gitlab-ci/forks/new).
%% Cell type:markdown id: tags:
## Clone du TP
%% Cell type:markdown id: tags:
- Pour paramétrer les commandes de ce notebook, positionner les variables d'environnement suivantes :
%% Cell type:code id: tags:
``` bash
export USERNAME="m.boileau" # votre login sur git.unistra.fr
export TPBASEDIR=$HOME # le répertoire où vous souhaitez installer le TP
export TPDIR=$TPBASEDIR/tp-gitlab-ci
```
%% Cell type:markdown id: tags:
- Cloner localement votre projet
%% Cell type:code id: tags:
``` bash
cd $TPBASEDIR
git clone git@git.unistra.fr:$USERNAME/tp-gitlab-ci.git
```
%% Cell type:markdown id: tags:
## Enregistrer un nouveau runner
> Si `gitlab-runner` n'est pas installé sur votre machine, rdv à la section **Exo1**
Engistrer un runner consiste à créer un nouveau runner associé à un projet.
Si vous n'êtes pas administrateur du GitLab, il s'agit forcément d'un runner spécifique. Celui-ci se trouve dans
votre projet, rubrique :
```
Settings > CI / CD > Runners settings
```
%% Cell type:markdown id: tags:
Dans le terminal, maintenant :
%% Cell type:code id: tags:
``` bash
export CI_SERVER_URL=https://git.unistra.fr/ # Do not change for this session
export RUNNER_NAME=a_runner_for_$USERNAME
export REGISTRATION_TOKEN=xxx # Replace by the value provided by the runner setting page
export REGISTER_NON_INTERACTIVE=true
#gitlab-runner register --executor shell # sous MacOS
#sudo gitlab-runner register --executor shell # sous Linux
```
%% Cell type:markdown id: tags:
Ou bien lancez la commande en mode interactif et en suivant pas à pas la [procédure](http://docs.gitlab.com/runner/register/#registering-runners):
```
gitlab-runner register # sous MacOS
sudo gitlab-runner register # sous Linux
```
%% Cell type:markdown id: tags:
- Retournez sur la page de paramètrage des runners
- Repérez votre nouveau runner
- Editez-le et ajouter les tags `specific, shell`
Votre runner est maintenant prêt à travailler. Nous allons le tester en lui soumettant une tâche GitLab CI déclenchée par un `git push` sur votre projet.
%% Cell type:markdown id: tags:
## Exo1 : helloworld en bash
### Mettre en place une action d'intégration continue
Allez dans le répertoire racine du clone local de votre projet et basculez sur la branche `exo1`
%% Cell type:code id: tags:
``` bash
cd $TPDIR
cd tp-gitlab-ci
```
%% Cell type:code id: tags:
``` bash
git pull
git checkout exo1
```
%% Cell type:markdown id: tags:
Repérer le fichier `.gitlab-ci.yml`
%% Cell type:code id: tags:
``` bash
ls -al
```
%% Cell type:markdown id: tags:
L'éditer avec l'éditeur de votre choix
%% Cell type:code id: tags:
``` bash
cat .gitlab-ci.yml
```
%% Cell type:markdown id: tags:
- `helloworld` indique le nom du job d'intégration continue
- `tags` permet de sélectionner des runners sur la base de mot-clés
- `scripts` correspond aux lignes de commande `bash` que vous souhaitez exécuter
%% Cell type:markdown id: tags:
### Si vous souhaitez utiliser un runner partagé
Dans la rubrique :
```
Settings > CI / CD > Runners settings
```
Notez la présence de plusieurs runners partagés dont `clu1-tp-gitlab-ci` qui porte les tags `shell` et `docker` mais pas `specific`. Pour cibler ce runner, retirer le tag `specific` du fichier `.gitlab-ci.yml`
%% Cell type:markdown id: tags:
### Déclenchez une action d'intégration continue
Modifiez la ligne de script, par exemple:
%% Cell type:code id: tags:
``` bash
echo ' - echo "bonjour, monde"' >> .gitlab-ci.yml
cat .gitlab-ci.yml
```
%% Cell type:markdown id: tags:
Enregistrez avec git
%% Cell type:code id: tags:
``` bash
git add .gitlab-ci.yml
git commit -m "Update .gitlab-ci.yml"
```
%% Cell type:markdown id: tags:
Pousser vos modifications
%% Cell type:code id: tags:
``` bash
git push
```
%% Cell type:markdown id: tags:
Sur GitLab, observez l'exécution de votre job dans la rubrique de votre projet :
```
CI / CD > Pipelines
```
%% Cell type:markdown id: tags:
### Provoquez une erreur
Dans `.gitlab-ci.yml`, introduisez une erreur dans une des lignes du script et observer l'effet dans `CI / CD > Pipelines` après avoir pousser les modifications.
> **Note :** les fichiers peuvent s'éditer directement dans GitLab.
%% Cell type:markdown id: tags:
## Exo2 : helloworld en C
### Description
On écrit le programme `helloworld` en C qui doit afficher `hello, world`.
### Mettre en place une action de *build*
Dans votre clone local, basculez sur la branche `exo2`
%% Cell type:code id: tags:
``` bash
cd $TPDIR
git stash # si vous avez des modifications non enregistrées dans exo1
git checkout exo2
```
%% Cell type:markdown id: tags:
Listez le contenu du répertoire
%% Cell type:code id: tags:
``` bash
ls -al
```
%% Cell type:markdown id: tags:
Vérifiez que le progamme compile
%% Cell type:code id: tags:
``` bash
make
```
%% Cell type:markdown id: tags:
On crée le fichier `.gitlab-ci.yml` avec une étape (`stage`) de `build`. Il doit contenir :
```yaml
build_hello:
stage: build
tags:
- shell
script:
- make
```
%% Cell type:code id: tags:
``` bash
cat > .gitlab-ci.yml <<- EOM
build_hello:
stage: build
tags:
- shell
script:
- make
EOM
```
%% Cell type:markdown id: tags:
On vérifie le contenu
%% Cell type:code id: tags:
``` bash
cat .gitlab-ci.yml
```
%% Cell type:markdown id: tags:
On enregistre et on pousse.
%% Cell type:code id: tags:
``` bash
git add .gitlab-ci.yml
git commit -m "Add .gitlab-ci.yml with a build stage"
```
%% Cell type:code id: tags:
``` bash
git push
```
%% Cell type:markdown id: tags:
Sur GitLab, observez l'exécution de votre job dans la rubrique de votre projet :
```
CI / CD > Pipelines
```
%% Cell type:markdown id: tags:
### Ajouter une action de *test*
On souhaite ajouter une étape de test réalisée avec `make test`. Tester l'exécution du test (il ne doit pas renvoyer d'erreur) :
%% Cell type:code id: tags:
``` bash
make test
```
%% Cell type:markdown id: tags:
Il faut ajouter le contenu suivant :
```yaml
test_hello:
stage: test
tags:
- shell
script:
- make test
```
%% Cell type:code id: tags:
``` bash
cat >> .gitlab-ci.yml <<- EOM
test_hello:
stage: test
tags:
- shell
script:
- make test
EOM
```
%% Cell type:code id: tags:
``` bash
cat .gitlab-ci.yml
```
%% Cell type:markdown id: tags:
On enregistre, on pousse et on vérifie l'exécution de la chaîne d'intégration continue dans `CI / CD > Pipelines`
%% Cell type:code id: tags:
``` bash
git add .gitlab-ci.yml
git commit -m "Add a test stage to .gitlab-ci.yml"
```
%% Cell type:code id: tags:
``` bash
git push
```
%% Cell type:markdown id: tags:
### Provoquez des erreurs
Modifier les fichiers
- de build : notez que le test n'est pas exécuté
- de test : le
%% Cell type:code id: tags:
``` bash
Récupérer un artifact
```
%% Output
bash: Récupérer: command not found
%% Cell type:code id: tags:
``` bash
```