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 (65)
stages:
- build
- test
- release
variables:
CONTAINER_TEST_IMAGE: boileaum/rosen:$CI_COMMIT_REF_NAME
CONTAINER_RELEASE_IMAGE: boileaum/rosen:latest
before_script:
- echo $DOCKERHUB_PASSWD | docker login -u boileaum --password-stdin
b:docker:
build_hello:
stage: build
tags:
- shell, docker
- shell
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE -f ./docker/Dockerfile-rosen .
- docker push $CONTAINER_TEST_IMAGE
t:helloworld:
- make
test_hello:
stage: test
tags:
- shell, docker
- shell
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE /bin/bash -c 'python test_helloworld.py'
t:rosen:
stage: test
tags:
- shell, docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker run $CONTAINER_TEST_IMAGE /bin/bash -c 'pytest -v'
r:docker:
stage: release
tags:
- shell, docker
script:
- docker pull $CONTAINER_TEST_IMAGE
- docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
- docker push $CONTAINER_RELEASE_IMAGE
only:
- master
- make test
# 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
File added
cicd_pipeline_infograph.png

31.7 KiB

FROM python:3
MAINTAINER Matthieu Boileau <matthieu.boileau@math.unistra.fr>
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
RUN apt-get update --fix-missing && \
apt-get install -y \
vim
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN useradd -m -s /bin/bash euler
ENV HOME /home/euler
RUN chown -R euler:euler /home/euler
USER euler
WORKDIR $HOME
CMD /bin/bash
FROM boileaum/pythran:latest
MAINTAINER Matthieu Boileau <matthieu.boileau@math.unistra.fr>
ENV HOME /home/euler
ADD . $HOME/rosen
USER root
RUN chown -R euler:euler /home/euler
WORKDIR $HOME/rosen
USER euler
RUN make clean && make
CMD /bin/bash
version: '2'
services:
env:
build:
context: ../
dockerfile: docker/Dockerfile-pythran
image: boileaum/pythran:latest
user:
build:
context: ../
dockerfile: docker/Dockerfile-rosen
image: boileaum/rosen:latest
depends_on:
- env
fork.png

53.1 KiB

#!/bin/bash
set -x
nbfile="tp-gitlab-ci.ipynb"
jupyter-nbconvert $nbfile --to slides --post serve $2 --allow-errors
.PHONY: clean pythran
all: helloworld
all: C pythran
helloworld:
cc helloworld.c
C:
gcc helloworld.c -o helloworld.e
pythran:
pythran rosenbrock.py -o rosenbrock_pythran.so
test: helloworld
./a.out
clean:
rm -rf *.o *.e *.so *.pyf *.pyc __pycache__
......
# -*- coding: utf-8 -*-
#runas import numpy as np; r = np.arange(0.,10., .01); rosen(r)
#bench import numpy as np; r = np.arange(50000000); rosen(r)
#pythran export rosen(int[])
#pythran export rosen(float[])
import numpy as np
def rosen(x):
t0 = 100 * (x[1:] - x[:-1] ** 2) ** 2
t1 = (1 - x[:-1]) ** 2
return np.sum(t0 + t1)
#!/bin/bash
docker run -ti --rm -v $(pwd):/home/euler boileaum/pythran:latest
tanuki.png

7.87 KiB

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Test Rosenbrock
"""
from rosenbrock_pythran import rosen as rosen_pythran
from rosenbrock import rosen as rosen_python
from pytest import mark, approx
import numpy as np
r_float = np.arange(0., 10., .01)
expect_float = 152089858.36719903
r_int = np.arange(50000000)
expect_int = 7842832767944603480
param = [(r_float, expect_float), (r_int, expect_int)]
@mark.parametrize('r, result', param)
def test_rosen_python(r, result):
assert rosen_python(r) == approx(result)
@mark.parametrize('r, result', param)
def test_rosen_pythran(r, result):
assert rosen_pythran(r) == approx(result)
%% 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 TPDIR=$HOME # le répertoire où vous souhaitez installer le TP
```
%% Cell type:markdown id: tags:
- Cloner localement votre projet
%% Cell type:code id: tags:
``` bash
cd $TPDIR
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 **Utiliser un runner partagé**
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
Aller dans le répertoire racine du clone local de votre projet et basculer 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:
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:
### Provoquer 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.