Slide 1

Slide 1 text

CONTINUOUS INTEGRATION WITH GITLAB IVAN NEMYTCHENKO, DEVELOPER ADVOCATE

Slide 2

Slide 2 text

MODERN SOFTWARE DEVELOPMENT PROCESS IS SPREAD ACROSS MANY TOOLS

Slide 3

Slide 3 text

Travis - GitHub - Trello - Slack

Slide 4

Slide 4 text

Bitbucket - Semaphore - Pivotal Tracker - HipChat

Slide 5

Slide 5 text

Jenkins - GitLab - Jira

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

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

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

CATGREP SOPHISTICATED TECHNOLOGIES INC. > file1.txt > file2.txt

Slide 18

Slide 18 text

REQUIREMENT #1 CONCATENATION RESULT SHOULD CONTAIN "HELLO WORLD"

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

RUN OUR FIRST TEST INSIDE CI

Slide 22

Slide 22 text

.gitlab-ci.yml

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

REQUIREMENT #2 PACKAGE CODE BEFORE SENDING IT TO CUSTOMER

Slide 27

Slide 27 text

test: script: cat file1.txt file2.txt | grep -q 'Hello world' package: script: cat file1.txt file2.txt | gzip > package.gz

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

MAKE RESULTS OF YOUR BUILD DOWNLOADABLE

Slide 30

Slide 30 text

test: script: cat file1.txt file2.txt | grep -q 'Hello world' package: script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

RUN JOBS SEQUENTIALLY

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

SPEEDING UP THE BUILD

Slide 35

Slide 35 text

#1: DUPLICATION

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

#2: RUBY 2.1 ????

Slide 38

Slide 38 text

LEARNING WHAT DOCKER IMAGE TO USE

Slide 39

Slide 39 text

image: alpine

Slide 40

Slide 40 text

image: alpine stages: - compile - test - package compile: ... test: ...

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

> defined 3 stages > pass files between stages > downloadable artifacts > optimized execution time

Slide 43

Slide 43 text

REQUIREMENT #3 ISO INSTEAD OF GZIP

Slide 44

Slide 44 text

DEALING WITH COMPLEX SCENARIOS

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

image: alpine stages: - compile - test - package compile: ... test: ... pack-gz: stage: package script: cat compiled.txt | gzip > packaged.gz artifacts: paths: - packaged.gz pack-iso: stage: package script: - mkisofs -o ./packaged.iso ./compiled.txt artifacts: paths: - packaged.iso

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

DEALING WITH MISSING SOFTWARE/PACKAGES

Slide 49

Slide 49 text

INSTALL PACKAGE IN ALPINE LINUX apk add -U cdrkit

Slide 50

Slide 50 text

script: - apk add -U cdrkit - mkisofs -o ./packaged.iso ./compiled.txt

Slide 51

Slide 51 text

pack-iso: stage: package before_script: - apk add -U cdrkit script: - mkisofs -o ./packaged.iso ./compiled.txt artifacts: paths: - packaged.iso

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

GITLAB REQUIREMENT #4 PUBLISH A SMALL WEBSITE WITH OUR PACKAGES

Slide 55

Slide 55 text

HTML + PACKAGES → AMAZON S3

Slide 56

Slide 56 text

aws s3 cp ./ s3://yourbucket/ --recursive

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

FIRST AUTOMATED DEPLOYMENT

Slide 60

Slide 60 text

> awscli can be installed using pip > pip goes together with python

Slide 61

Slide 61 text

s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive

Slide 62

Slide 62 text

AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

Slide 63

Slide 63 text

variables: AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE" AWS_SECRET_ACCESS_KEY: “wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY” s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive

Slide 64

Slide 64 text

KEEPING SECRET THINGS SECRET

Slide 65

Slide 65 text

SETTINGS --> VARIABLES

Slide 66

Slide 66 text

s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive

Slide 67

Slide 67 text

So far so good:

Slide 68

Slide 68 text

REQUIREMENT #5 MORE THAN ONE DEVELOPER ON THE PROJECT

Slide 69

Slide 69 text

s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive only: - master

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

REQUIREMENT #6 WE NEED A SEPARATE PLACE FOR TESTING

Slide 72

Slide 72 text

GITLAB PAGES

Slide 73

Slide 73 text

HOST WEBSITES ON GITLAB PAGES > your job should be named "pages" > put your files into "public" folder > specify "artifacts" section with this "public" folder

Slide 74

Slide 74 text

HOST WEBSITES ON GITLAB PAGES > your job should be named "pages" > put your files into "public" folder > specify "artifacts" section with this "public" folder HTTP://.GITLAB.IO/

Slide 75

Slide 75 text

pages: stage: deploy image: alpine:latest script: - mkdir -p ./public && cp ./*.* ./public/ artifacts: paths: - public except: - master

Slide 76

Slide 76 text

s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive only: - master pages: image: alpine:latest stage: deploy script: - mkdir -p ./public && cp ./*.* ./public/ artifacts: paths: - public except: - master

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

INTRODUCING ENVIRONMENTS

Slide 81

Slide 81 text

s3: environment: production image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://$S3_BUCKET_NAME/ --recursive only: - master pages: image: alpine:latest environment: staging stage: deploy script: - mkdir -p ./public && cp ./*.* ./public/ artifacts: paths: - public except: - master

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

REQUIREMENT #7 DO NOT MESS UP PRODUCTION

Slide 86

Slide 86 text

SWITCHING TO MANUAL DEPLOYMENT

Slide 87

Slide 87 text

s3: image: python:latest stage: deploy script: - pip install awscli - aws s3 cp ./ s3://yourbucket/ --recursive only: - master when: manual

Slide 88

Slide 88 text

SUMMARY 1. Deployment is just a set of commands 2. You need to provide secret keys 3. You specify where which branches should go to 4. GitLab conserves the history of deployments 5. You can enable manual deployment

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

GO TO GITLAB.COM

Slide 93

Slide 93 text

@INEM [email protected] BIT.LY/GITLAB-CI1 BIT.LY/GITLAB-CI2