zeger-jan van de weg gitlab ci/cd · continuous integration / continuous deployment short...

21
GitLab CI/CD Zeger-Jan van de Weg

Upload: others

Post on 31-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

GitLab CI/CDZeger-Jan van de Weg

Page 2: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Today...

● What is CI/CD

● GitLab CI/CD

○ Setting up your first pipeline!

● Questions

Page 3: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

What is CI/CD

● Continuous Integration / Continuous Deployment○ Short iterations○ Fast feedback○ Quick improvements

● To do this, you need to automate the process○ Run tests○ Run a deploy job

● GitLab has an integrated CI solution! :)

Page 4: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Setup

● GitLab Runner○ Executors

■ SSH■ Docker■ Docker auto-scaled

○ Platforms■ Linux■ Mac■ Windows

Page 5: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Setup

● Shared vs Specific○ Shared

■ Might be limited to tags■ Should be enabled for your project

● Settings > Runners > Enable Shared runners● Specific

○ Only for 1 project○ No need to enable

● Install guide

Page 6: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Setup GitLab

● Job definitions are in the git repo○ .gitlab-ci.yml

● For this lecture I assume a Docker executor○ Most environment agnostic○ Each job should be idempotent, SSH doesn’t provide this

Page 7: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My first .gitlab-ci.yml

image "ubuntu:xenial"

test:

script:

- cat file1.txt file2.txt | grep -q "Hello world"

Page 8: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My first .gitlab-ci.yml

image "ruby:2.1"

test:

script:

- cat file1.txt file2.txt | grep -q "Hello world"

Page 9: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My first .gitlab-ci.yml

Page 10: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My first .gitlab-ci.yml

Page 11: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

image "ruby:2.1"

test:

script:

- cat file1.txt file2.txt | grep -q "Hello world"

package:

script:

- cat file1.txt file2.txt | gzip > package.gz

Page 12: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

Page 13: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

package:

artifacts:

paths:

- package.gz

script:

- cat file1.txt file2.txt | gzip > package.gz

Page 14: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

Page 15: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Sequential builds

stages: - test - package

test: stage: test script: cat file1.txt file2.txt | grep -q 'Hello world'

package: stage: package script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz

Page 16: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

Sequential builds

stages: - test - package

test: stage: test script: cat file1.txt file2.txt | grep -q 'Hello world'

package: stage: package script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz

Page 17: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

stages: - compile - test - package

compile: stage: compile script: cat file1.txt file2.txt > compiled.txt artifacts: paths: - compiled.txt

test: stage: test script: cat compiled.txt | grep -q 'Hello world'

package: stage: package script: cat compiled.txt | gzip > packaged.gz artifacts: paths: - packaged.gz

Page 18: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

Page 19: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

● Caching○ Like artifacts but used for dependencies

■ node_modules■ npm install■ Without cache, build should still run successfully

Page 20: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

● Small demo :)

Page 21: Zeger-Jan van de Weg GitLab CI/CD · Continuous Integration / Continuous Deployment Short iterations Fast feedback Quick improvements To do this, you need to automate the process

My second .gitlab-ci.yml

● Further reading:○ GitLab CI Docs○ GitLab Runner Docs

● Question?○ Ask now!○ @ZJvandeWeg○ [email protected]