Continuous Integration mit GitLab CI Christine Koppelt Philipp Haußleiter GUUG-Frühjahrsfachgespräch 1. März 2018
Continuous Integration (CI)
Continuous Integration (CI) Sourcecode Source Repository Deploybare Bauen Testen Paketieren Anwendung Entwicklungsteam Feedback CI Server Server mit Anwendung
Softwareentwicklung heute Systeme die aus mehreren eigenständigen Anwendungen bestehen Technologiemix Umfangreiche Testsuiten Testinfrastruktur Umfangreiche Toolchains für Build Dockerbasierte Deployments A/B Testing
Infrastruktur DO Entkopplung Infra-Team und Entwicklung Entwickler konfigurieren CI Jobs und Staging Umgebung selbständig Kapselung der Buildumgebung DON T Modifikation der Konfiguration des CI Servers für einzelne Projekte Adminrechte für Entwickler Langwierige Abstimmungen zwischen Infra-Team und Entwicklung
Self Service
GitLab
GitLab Gestartet als Web-Basierter Git Repository Manager Mittlerweile: Umfangreiche Softwareentwicklungssuite Issue Tracker integriert CI Server integriert Bauen von Merge Requests und Branches integriert Anlegen von Jobs über eine deklarative Konfiguration mittels Yaml Builds innerhalb Docker => Sinnvolle Konventionen, modularer Ansatz Open Source, kommerzielle und Cloud Versionen
Komponenten
High Level View
https://gitlab.com/gitlab-org/gitlab-ce/blob/ master/doc/development/architecture.md
Access Processes Data Gitaly (Repo / RPC) Monitoring/Logs CI/CD Prometheus (Metrics) Gitlab Runner (Docker) Gitlab-monitor Gitlab Runner (Shell) Node-exporter Sidekiq (Jobs) Postgres-exporter Gitlab-shell Unicorn (Rails) Redis (Jobs) Nginx Gitlab-workhorse (reverse proxy) Postgres (App Data) Redis-exporter Mattermost (Chat) Registry (Docker) Logrotate (Logs)
Setup
Setup Optionen Deployment auf Bare Metal Deployment innerhalb von Kubernetes/Openshift per Helm Chart (current) Cloud Native GitLab Chart (WIP) Konfiguration per Omnibus und gitlab.rb File.
Omnibus Easily create full-stack installers for your project across a variety of platforms. Setup von Gitlab (LDAP/AD/oAuth/Backup/S3 Storage) Infrastruktur (Postgres, Redis, Nginx, ) Kommunikation (Mattermost/Slack/Mail) Weiteren Services (Docker Registry, Mattermost, ) Konfiguration externer Services (z.b. JIRA/Redmine) => sinnvolle Defaults. Überschreiben, wenn notwendig https://github.com/chef/omnibus
Installation per Omnibus (Bare Metal) Gitlab Konfiguration Spezifische Konfiguration Repo hinzufügen Gitlab installieren Mail, LDAP, Settings gitlab.rb anpassen Reconfigure Services Konfiguration Konfiguration Test Service Konfiguration RPM, APT, Nginx, Mattermost, Prometheus, Gitlab restart
Update per Omnibus (Bare Metal) Gitlab Postgres Mattermost, Package update yum update Update laden Ggf. aktualisierte Konfiguration Backup erstellen DB-Snapshot Docker Registry Build Artifacts Pages Reconfigure Services Konfiguration Konfiguration Test Gitlab restart
Installation per (Helm) Spezifische Konfiguration Repo hinzufügen gitlab.rb anpassen Gitlab installieren Kubernetes Deployment Service Pods Gitlab Pods start start Gitlab upgrade helm install --namespace <NAMESPACE> --name gitlab -f <CONFIG_VALUES_FILE> gitlab/gitlab helm repo add gitlab https://charts.gitlab.io helm init helm upgrade --namespace <NAMESPACE> -f <CONFIG_VALUES_FILE> <RELEASE-NAME> gitlab/gitlab
Deployment Kubernetes Kubernetes Docker Docker Gitlab Web Redis Postgres Web User Repo Docker Gitlab Shell Repository User Gitlab-CI Runner Runner Runner Runner Instances Runner Instances Instances Instances
Beispiel
CI Pipeline Sourcecode auschecken Kompilieren Testen Paketieren Deployen int_test1 Job build_jar build_docker_image deploy_staging int_test2 Stage build test package deploy
Demo
Bau eines Java Projektes stages: - build build_jar: stage: build image: maven:3-jdk-8 script: - mvn install artifacts: paths: - target/*.jar build test package deploy
Services einbinden am Beispiel PostgreSQL... variables: POSTGRES_DB: enco POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres int_test1: stage: test image: maven:3-jdk-8 services: - postgres:9.6 script: - mvn install -P integration-test1 artifacts: paths: - target/reports/* build test package deploy
Docker Image bauen & pushen stages: - build - test - package... build test build_docker_image: stage: package image: docker:latest services: - docker:dind script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker build -t $CI_REGISTRY_IMAGE:latest. - docker push $CI_REGISTRY_IMAGE:latest package deploy
Branch-Spezifische Jobs stages: - build - test - package... build test build_docker_image: stage: package image: docker:latest services: - docker:dind script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker build -t $CI_REGISTRY_IMAGE:latest. - docker push $CI_REGISTRY_IMAGE:latest only: - master package deploy
Deployment bei AWS Beanstalk deploy_staging:... script: - aws elasticbeanstalk create-application-version \ --application-name "$EB_APP_NAME" \ --version-label "$CI_COMMIT_SHA" \ --description "$CI_COMMIT_SHA" \ --source-bundle S3Bucket="$S3_BUCKET", \ S3Key="$CI_COMMIT_SHA.zip" - aws elasticbeanstalk update-environment \ --application-name "$EB_APP_NAME" \ --environment-name $EB_ENVIRONMENT \ --version-label "$CI_COMMIT_SHA" environment: name: staging url: $DEPLOYMENT_URL build test package deploy
Fragen?
Vielen Dank! christine.koppelt@innoq.com philipp.haussleiter@innoq.com
Bildquellen https://unsplash.com/photos/6gmysegmpmw https://unsplash.com/photos/c53hva-blyq https://unsplash.com/photos/7ehhidt3wyc https://unsplash.com/photos/gq8v_6n3fno https://www.pexels.com/photo/shallow-focus-photography-of-black-microph one-164960/
Extra
Komponenten Entwicklung Feature Branch Issue Tracker Ticket erstellen Feature Automatisches Bauen von Branches Git Repository Entwickeln Einchecken Merge schließt Ticket automatisch Automatisches Prüfen & Bauen von Merge Requests Build prüfen Wiki Merge Request erstellen Review & Merge Static Page Hosting Ticket schließen Boards
Komponenten CI Zeitgesteuertes Starten von Builds Artifakt Archivierung Buildumgebung als Docker Image Testabdeckung Docker Registry Sourcecode auschecken Kompilieren Bauen von Branches & Merge Requests Testen Metriken Erfassen Services & Infrastruktur als Docker Container einbinden Reports & Doku generieren Paketieren Docker-in-Docker Unterstützung
Komponenten Deployment Prometheus Integration Manuelle Freigabe Abnahme Übertragen & Installieren Kubernetes Integration Metriken erfassen