Slide 1

Slide 1 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 Crédit Image : Very Tech Trip - 02/02/2023

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

No content

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

Slide 12

Slide 12 text

Mon utilisation ? ➡ Quotidienne

Slide 13

Slide 13 text

Il était une fois … un vendredi après-midi

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

No content

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 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 22

Slide 22 text

Lien ⤵

Slide 23

Slide 23 text

👋 Ok c’est cool mais quel est le lien avec les 150 commits de modifications de CI ? 🤔

Slide 24

Slide 24 text

“Aie” ! ❌

Slide 25

Slide 25 text

400 min offertes par mois et par groupe

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

“Je vais rallumer mon raspberry et redémarrer mon Runner”

Slide 28

Slide 28 text

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

Slide 29

Slide 29 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

Slide 30

Slide 30 text

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 31

Slide 31 text

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 32

Slide 32 text

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

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 34

Slide 34 text

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 35

Slide 35 text

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 36

Slide 36 text

Configuration du secret

Slide 37

Slide 37 text

Modification de la CI pour utiliser notre Runner .gitpod: [...] tags: - gitpod

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

🐛 Liste de runners 🤔

Slide 40

Slide 40 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.

Slide 41

Slide 41 text

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 42

Slide 42 text

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 43

Slide 43 text

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

Slide 44

Slide 44 text

- 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 45

Slide 45 text

🗑 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 46

Slide 46 text

🗑 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 47

Slide 47 text

🗑 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 48

Slide 48 text

🗑 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 49

Slide 49 text

- 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 50

Slide 50 text

🗑 Suppression de Runner - Action faite par l’utilisateur (s’il y pense 😇) avec la fermeture de l’onglet - Action automatique quand le workspace est arrêté ou expiré

Slide 51

Slide 51 text

🗑 Suppression de Runner tasks: - name: Shutdown GitLab Runner command: | function shutdown() { [...] } trap 'shutdown' SIGINT SIGQUIT SIGTERM; [...]

Slide 52

Slide 52 text

🗑 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 53

Slide 53 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 54

Slide 54 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 - 02/02/2023 Crédit Image : Very Tech Trip 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

Slide 55

Slide 55 text

Késako ⁉, il crée son propre runner GitLab quand il démarre son environnement de dev Gitpod : 🤯 - 02/02/2023 Crédit Image : Very Tech Trip Merci pour votre attention ! 🙏 JPhi_Baconnais