Slide 1

Slide 1 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 - 08/02/2024

Slide 2

Slide 2 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 “Qu'es aquo ?”

Slide 3

Slide 3 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯

Slide 4

Slide 4 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯

Slide 5

Slide 5 text

Jean-Philippe Baconnais JPhi_Baconnais Jean-Philippe Baconnais

Slide 6

Slide 6 text

https://unsplash.com/fr/@timaesthetic

Slide 7

Slide 7 text

Cloud Development Environments (CDE)

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

.gitpod.yml 🚨 1 chose à retenir 🚨

Slide 12

Slide 12 text

Mon utilisation ? ➡ Quotidienne

Slide 13

Slide 13 text

Il était une fois … un vendredi après-midi https://unsplash.com/fr/@californong

Slide 14

Slide 14 text

Je “développais” sur un projet open source (enfin je faisais de la CI)

Slide 15

Slide 15 text

git add .gitlab-ci.yml && git commit -m “🚀 changes on CI”

Slide 16

Slide 16 text

git add .gitlab-ci.yml && git commit -m “🚀 changes on CI”

Slide 17

Slide 17 text

git add .gitlab-ci.yml && git commit -m “🚀 changes on CI”

Slide 18

Slide 18 text

https://unsplash.com/fr/@grakozy

Slide 19

Slide 19 text

- Outil développé en Go - Permet d’exécuter les pipelines de vos projets - Différents types de runner : shared / group / specific - Plusieurs implémentations possibles : docker, kubernetes, ssh, etc.

Slide 20

Slide 20 text

Lien ⤵

Slide 21

Slide 21 text

git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” 👋 Ok c’est cool mais quel est le lien avec les 150 commits de modifications de CI ? 🤔 git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI” git add .gitlab-ci.yml && git commit -m “🚀 changes on CI”

Slide 22

Slide 22 text

https://unsplash.com/fr/@zekedrone

Slide 23

Slide 23 text

https://unsplash.com/fr/@zekedrone

Slide 24

Slide 24 text

https://unsplash.com/fr/@zekedrone “Je vais rallumer mon raspberry et redémarrer mon Runner”

Slide 25

Slide 25 text

“💡 Pourquoi ne pas créer mon runner dans Gitpod ?”

Slide 26

Slide 26 text

Création du runner docker container run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest https://unsplash.com/fr/@wasdrew

Slide 27

Slide 27 text

https://unsplash.com/fr/@wasdrew docker container run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest Création du runner

Slide 28

Slide 28 text

https://unsplash.com/fr/@wasdrew docker container run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latest Création du runner

Slide 29

Slide 29 text

https://unsplash.com/fr/@wasdrew docker container run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \ --non-interactive \ --executor "docker" \ --docker-image ruby:2.7 \ --url "https://gitlab.com/" \ --registration-token $MY_CICD_REGISTRATION_TOKEN \ --description "gitpod-runner" \ --tag-list "gitpod" \ --access-level="not_protected" Création du runner

Slide 30

Slide 30 text

https://unsplash.com/fr/@wasdrew docker container run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \ --non-interactive \ --executor "docker" \ --docker-image ruby:2.7 \ --url "https://gitlab.com/" \ --registration-token $MY_CICD_REGISTRATION_TOKEN \ --description "gitpod-runner" \ --tag-list "gitpod" \ --access-level="not_protected" Création du runner

Slide 31

Slide 31 text

https://unsplash.com/fr/@wasdrew docker container run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \ --non-interactive \ --executor "docker" \ --docker-image ruby:2.7 \ --url "https://gitlab.com/" \ --registration-token $MY_CICD_REGISTRATION_TOKEN \ --description "gitpod-runner" \ --tag-list "gitpod" \ --access-level="not_protected" Création du runner

Slide 32

Slide 32 text

https://unsplash.com/fr/@wasdrew docker container run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \ --non-interactive \ --executor "docker" \ --docker-image ruby:2.7 \ --url "https://gitlab.com/" \ --registration-token $MY_CICD_REGISTRATION_TOKEN \ --description "gitpod-runner" \ --tag-list "gitpod" \ --access-level="not_protected" Création du runner

Slide 33

Slide 33 text

Configuration du secret

Slide 34

Slide 34 text

https://unsplash.com/fr/@wasdrew Modification de la CI pour utiliser notre Runner .gitpod: [...] tags: - gitpod

Slide 35

Slide 35 text

https://unsplash.com/fr/@wasdrew

Slide 36

Slide 36 text

🐛 Liste de runners 🤔 https://unsplash.com/fr/@hugsdealer

Slide 37

Slide 37 text

🗑 Suppression de Runner Récupérer le token créé dans le fichier config.toml à la création du Runner. Solliciter l’API de GitLab pour supprimer le Runner. https://unsplash.com/fr/@roman_lazygeek

Slide 38

Slide 38 text

https://unsplash.com/fr/@roman_lazygeek export RUNNER_TOKEN= $(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" 🗑 Suppression de Runner

Slide 39

Slide 39 text

https://unsplash.com/fr/@roman_lazygeek export RUNNER_TOKEN= $(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" 🗑 Suppression de Runner

Slide 40

Slide 40 text

https://unsplash.com/fr/@roman_lazygeek 👍 Le faire en automatique à la suppression du workspace Issue https://github.com/gitpod-io/gitpod/issues/3966 🗑 Suppression de Runner

Slide 41

Slide 41 text

https://unsplash.com/fr/@roman_lazygeek - Action faite par l’utilisateur (s’il y pense 😇) alias sr='curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN"' 🗑 Suppression de Runner

Slide 42

Slide 42 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner - Action faîte en utilisant des signaux - name: Shutdown GitLab Runner command: | function shutdown() { export RUNNER_TOKEN=$(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" } trap 'shutdown' SIGINT SIGQUIT SIGTERM; exec {sfd}<> <(:); until read -t 3600 -u $sfd; do continue; done;

Slide 43

Slide 43 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner - name: Shutdown GitLab Runner command: | function shutdown() { export RUNNER_TOKEN=$(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" } trap 'shutdown' SIGINT SIGQUIT SIGTERM; exec {sfd}<> <(:); until read -t 3600 -u $sfd; do continue; done; - Action faîte en utilisant des signaux

Slide 44

Slide 44 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner - name: Shutdown GitLab Runner command: | function shutdown() { export RUNNER_TOKEN=$(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" } trap 'shutdown' SIGINT SIGQUIT SIGTERM; exec {sfd}<> <(:); until read -t 3600 -u $sfd; do continue; done; - Action faîte en utilisant des signaux

Slide 45

Slide 45 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner - name: Shutdown GitLab Runner command: | function shutdown() { export RUNNER_TOKEN=$(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" } trap 'shutdown' SIGINT SIGQUIT SIGTERM; exec {sfd}<> <(:); until read -t 3600 -u $sfd; do continue; done; - Action faîte en utilisant des signaux

Slide 46

Slide 46 text

https://unsplash.com/fr/@roman_lazygeek - name: Shutdown GitLab Runner command: | function shutdown() { export RUNNER_TOKEN=$(sudo grep 'token =' /srv/gitlab-runner/config/config.toml | sed 's/token =//g' | tr -d '"') curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN" } trap 'shutdown' SIGINT SIGQUIT SIGTERM; exec {sfd}<> <(:); until read -t 3600 -u $sfd; do continue; done;

Slide 47

Slide 47 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner - Action faite par l’utilisateur (s’il y pense 😇) - Action automatique quand le workspace est arrêté ou expiré

Slide 48

Slide 48 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner tasks: - name: Shutdown GitLab Runner command: | function shutdown() { [...] } trap 'shutdown' SIGINT SIGQUIT SIGTERM; [...]

Slide 49

Slide 49 text

https://unsplash.com/fr/@roman_lazygeek 🗑 Suppression de Runner tasks: - name: Shutdown GitLab Runner command: | function shutdown() { [...] } trap 'shutdown' SIGINT SIGQUIT SIGTERM; [...] - name: Terminal init: | echo '🦊 Install GitLab Runner' [...] alias sr='curl --request DELETE "https://gitlab.com/api/v4/runners" --form "token=$RUNNER_TOKEN"'

Slide 50

Slide 50 text

Intérêts ? - Limiter sa consommation de CI avec de “vrais” pipelines - 💡 Pour les ateliers / formations - 💡 Avoir son Runner avec une configuration simple et adaptable à son besoin - Ne pas être dépendant de GitLab

Slide 51

Slide 51 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 Repository GitLab : https://gitlab.com/jeanphi-baconnais/gitpod-create-gitlab-runner Cheatsheet GitLab Runner : https://dev.to/zenika/gitlab-cheatsheet-2-runners-2ib Cheatsheet Gitpod : https://dev.to/zenika/gitpod-cheatsheet-2ek6 Gitpod Issue d’action on stop : https://github.com/gitpod-io/gitpod/issues/3966