Upload
truongnhan
View
213
Download
0
Embed Size (px)
Citation preview
1
Continuous Integration mit GitLab CIChristine KoppeltPhilipp HaußleiterGUUG-Frühjahrsfachgespräch1. März 2018
Continuous Integration (CI)
Source Repository
CI ServerBauen Testen Paketieren
Server mit Anwendung
Entwicklungsteam
Sourcecode Deploybare Anwendung
Feedback
Softwareentwicklung heute● Systeme die aus mehreren eigenständigen Anwendungen bestehen● Technologiemix● Umfangreiche Testsuiten
○ Testinfrastruktur● Umfangreiche Toolchains für Build● Dockerbasierte Deployments● A/B Testing
InfrastrukturDO
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
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
High Level View
Gitaly(Repo / RPC)
Gitlab-monitor
Gitlab-workhorse(reverse proxy)
Logrotate(Logs)
Nginx
Mattermost(Chat)
Node-exporter
Postgres-exporterRedis(Jobs)
Postgres(App Data)
Redis-exporter
Prometheus(Metrics)
Registry(Docker)
Sidekiq(Jobs)
Unicorn(Rails)Gitlab-shell
Access Processes Data Monitoring/Logs
Gitlab Runner(Docker)
Gitlab Runner(Shell)
CI/CD
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
Gitlab restart
KonfigurationTest
Installation per Omnibus (Bare Metal)
ServicesKonfiguration“Reconfigure”“gitlab.rb“
anpassenGitlab
installierenRepo
hinzufügen
RPM, APT, …
SpezifischeKonfiguration
Gitlab Konfiguration
Mail, LDAP, Settings…
Service Konfiguration
Nginx, Mattermost, Prometheus, …
Gitlab restart
KonfigurationTest
Update per Omnibus (Bare Metal)
ServicesKonfiguration“Reconfigure”Backup
erstellenUpdateladen
Packageupdate
“yum update” DB-SnapshotDocker RegistryBuild ArtifactsPages
Ggf. aktualisierteKonfiguration
GitlabPostgresMattermost, …
Gitlab upgrade
Gitlab Pods start
Service Podsstart
KubernetesDeployment
Gitlab installieren
Installation per (Helm)
“gitlab.rb“anpassen
Repo hinzufügen
helm repo add gitlab https://charts.gitlab.iohelm init
SpezifischeKonfiguration
helm install --namespace <NAMESPACE> --name gitlab -f <CONFIG_VALUES_FILE> gitlab/gitlab
helm upgrade --namespace <NAMESPACE> -f <CONFIG_VALUES_FILE> <RELEASE-NAME> gitlab/gitlab
Deployment Kubernetes
Kubernetes
Docker Docker
Docker
Web User
RepositoryUser
GitlabWeb
GitlabShell
Repo
Redis Postgres
Gitlab-CIRunner
RunnerInstances
RunnerInstances
RunnerInstancesRunner
Instances
CI Pipeline
build_jar
build
build_docker_image
package
deploy_staging
deploy
Job
Stage
Versand von Benachrichtigungen bei Problemen
Sourcecodeauschecken Kompilieren Testen Paketieren Deployen
test
int_test1
int_test2
Bau eines Java Projektesstages: - build
build_jar: stage: build image: maven:3-jdk-8 script: - mvn install artifacts: paths: - target/*.jar
build
test
deploy
package
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
deploy
package
Docker Image bauen & pushenstages: - build - test - package...
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
build
test
deploy
package
Branch-Spezifische Jobsstages: - build - test - package...
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
build
test
deploy
package
Deployment bei AWS Beanstalkdeploy_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
deploy
package
Bildquellenhttps://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-microphone-164960/
Komponenten Entwicklung
Ticket erstellen Entwickeln Einchecken Build prüfen
Merge Request erstellen
Review & Merge
Ticket schließen
Feature Static Page Hosting Boards
Issue Tracker Git Repository
Wiki
Automatisches Bauen von Branches
Automatisches Prüfen & Bauen von Merge Requests
Merge schließt Ticket automatisch
Feature Branch
Komponenten CI
Sourcecodeauschecken Kompilieren Testen Metriken
Erfassen
Reports &Doku generieren
Paketieren
Docker Registry
Artifakt ArchivierungBuildumgebung als Docker Image
Services & Infrastruktur als Docker Container einbinden
Docker-in-Docker UnterstützungBauen von Branches
& Merge Requests
Zeitgesteuertes Starten von Builds
Testabdeckung