Breaking bad habits with GitLab CI

121
BREAKING BAD WITH GITLAB CI IVAN NEMYTCHENKO, DEVELOPER ADVOCATE

Transcript of Breaking bad habits with GitLab CI

Page 1: Breaking bad habits with GitLab CI

BREAKING BADWITH GITLAB CIIVAN NEMYTCHENKO, DEVELOPER ADVOCATE

Page 2: Breaking bad habits with GitLab CI

IVAN NEMYTCHENKO

> Ruby developer> Project manager

> Co-founder of outsourcing agency> Developer advocate at GitLab

> railshurts.com> inem.at> @inem

Page 3: Breaking bad habits with GitLab CI

SOFTWARE DEVELOPMENT PROCESS

Page 4: Breaking bad habits with GitLab CI
Page 5: Breaking bad habits with GitLab CI

Every tool covers a part of the whole process

Page 6: Breaking bad habits with GitLab CI

MODERN SOFTWARE DEVELOPMENT PROCESSIS SPREAD ACROSS MANY TOOLS

Page 7: Breaking bad habits with GitLab CI

Travis - GitHub - Trello - Slack

Page 8: Breaking bad habits with GitLab CI

Bitbucket - Semaphore - Pivotal Tracker - HipChat

Page 9: Breaking bad habits with GitLab CI

Jenkins - GitLab - Jira

Page 10: Breaking bad habits with GitLab CI
Page 11: Breaking bad habits with GitLab CI
Page 12: Breaking bad habits with GitLab CI
Page 13: Breaking bad habits with GitLab CI
Page 14: Breaking bad habits with GitLab CI
Page 15: Breaking bad habits with GitLab CI
Page 16: Breaking bad habits with GitLab CI
Page 17: Breaking bad habits with GitLab CI

BREAKING BADWITH GITLAB CI

IVAN NEMYTCHENKO, DEVELOPER ADVOCATE

Page 18: Breaking bad habits with GitLab CI

BREAKING BAD WITH GITLAB CI

  

Page 19: Breaking bad habits with GitLab CI

BREAKING BAD WITH GITLAB CI

  

Page 20: Breaking bad habits with GitLab CI

BREAKING BAD

HABITSWITH GITLAB CI

IVAN NEMYTCHENKO, DEVELOPER ADVOCATE

Page 21: Breaking bad habits with GitLab CI
Page 22: Breaking bad habits with GitLab CI

HABIT OFNOT AUTOMATING

THE ROUTINE TASKS

Page 23: Breaking bad habits with GitLab CI

THIS HABIT COMES FROM THE FEAR OF CI SYSTEMS

Page 24: Breaking bad habits with GitLab CI
Page 25: Breaking bad habits with GitLab CI
Page 26: Breaking bad habits with GitLab CI
Page 27: Breaking bad habits with GitLab CI
Page 28: Breaking bad habits with GitLab CI
Page 29: Breaking bad habits with GitLab CI
Page 30: Breaking bad habits with GitLab CI
Page 31: Breaking bad habits with GitLab CI
Page 32: Breaking bad habits with GitLab CI
Page 33: Breaking bad habits with GitLab CI
Page 34: Breaking bad habits with GitLab CI
Page 35: Breaking bad habits with GitLab CI
Page 36: Breaking bad habits with GitLab CI

CATGREP SOPHISTICATED TECHNOLOGIES INC.

> file1.txt> file2.txt

Page 37: Breaking bad habits with GitLab CI

REQUIREMENT #1CONCATENATION RESULT SHOULD

CONTAIN "HELLO WORLD"

Page 38: Breaking bad habits with GitLab CI

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

Page 39: Breaking bad habits with GitLab CI
Page 40: Breaking bad habits with GitLab CI

RUN OUR FIRST TEST INSIDE CI

Page 41: Breaking bad habits with GitLab CI

.gitlab-ci.yml

Page 42: Breaking bad habits with GitLab CI

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

Page 43: Breaking bad habits with GitLab CI
Page 44: Breaking bad habits with GitLab CI
Page 45: Breaking bad habits with GitLab CI

REQUIREMENT #2PACKAGE CODE BEFORE SENDING IT TO CUSTOMER

Page 46: Breaking bad habits with GitLab CI

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

package: script: cat file1.txt file2.txt | gzip > package.gz

Page 47: Breaking bad habits with GitLab CI
Page 48: Breaking bad habits with GitLab CI

MAKE RESULTS OF YOUR BUILD DOWNLOADABLE

Page 49: Breaking bad habits with GitLab CI

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

Page 50: Breaking bad habits with GitLab CI
Page 51: Breaking bad habits with GitLab CI

RUN JOBS SEQUENTIALLY

Page 52: Breaking bad habits with GitLab CI

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 53: Breaking bad habits with GitLab CI

SPEEDING UP THE BUILD

Page 54: Breaking bad habits with GitLab CI

#1: DUPLICATION

Page 55: Breaking bad habits with GitLab CI

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 56: Breaking bad habits with GitLab CI
Page 57: Breaking bad habits with GitLab CI

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

Page 58: Breaking bad habits with GitLab CI

#2: RUBY 2.1 ????

Page 59: Breaking bad habits with GitLab CI

LEARNING WHAT DOCKER IMAGE TO USE

Page 60: Breaking bad habits with GitLab CI

image: alpine

Page 61: Breaking bad habits with GitLab CI

image: alpinestages: - compile - test - package

compile: ...test: ...

Page 62: Breaking bad habits with GitLab CI
Page 63: Breaking bad habits with GitLab CI

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

Page 64: Breaking bad habits with GitLab CI

REQUIREMENT #3ISO INSTEAD OF GZIP

Page 65: Breaking bad habits with GitLab CI

DEALING WITH COMPLEX SCENARIOS

Page 66: Breaking bad habits with GitLab CI
Page 67: Breaking bad habits with GitLab CI

image: alpinestages: - 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

Page 68: Breaking bad habits with GitLab CI
Page 69: Breaking bad habits with GitLab CI

DEALING WITH MISSING SOFTWARE/PACKAGES

Page 70: Breaking bad habits with GitLab CI

apk add -U cdrkit

Page 71: Breaking bad habits with GitLab CI

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

Page 72: Breaking bad habits with GitLab CI

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

Page 73: Breaking bad habits with GitLab CI
Page 74: Breaking bad habits with GitLab CI
Page 75: Breaking bad habits with GitLab CI

GITLAB OUIREMENT #4PUBLISH

A SMALL WEBSITE WITH OUR PACKAGES

Page 76: Breaking bad habits with GitLab CI

HTML → AMAZON S3

Page 77: Breaking bad habits with GitLab CI

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

Page 78: Breaking bad habits with GitLab CI
Page 79: Breaking bad habits with GitLab CI
Page 80: Breaking bad habits with GitLab CI

FIRST AUTOMATED DEPLOYMENT

Page 81: Breaking bad habits with GitLab CI

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

Page 82: Breaking bad habits with GitLab CI

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

Page 83: Breaking bad habits with GitLab CI

AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY

Page 84: Breaking bad habits with GitLab CI

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

Page 85: Breaking bad habits with GitLab CI

KEEPING SECRET THINGS SECRET

Page 86: Breaking bad habits with GitLab CI

SETTINGS --> VARIABLES

Page 87: Breaking bad habits with GitLab CI

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

Page 88: Breaking bad habits with GitLab CI

So far so good:

Page 89: Breaking bad habits with GitLab CI

REQUIREMENT #5MORE THAN ONE DEVELOPER

ON THE PROJECT

Page 90: Breaking bad habits with GitLab CI

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

Page 91: Breaking bad habits with GitLab CI
Page 92: Breaking bad habits with GitLab CI

REQUIREMENT #6WE NEED A SEPARATE PLACE

FOR TESTING

Page 93: Breaking bad habits with GitLab CI

GITLAB PAGES

Page 94: Breaking bad habits with GitLab CI

HOST WEBSITES ON GITLAB PAGES

> your job should be named "pages"> put your files into "public" folder

> specify "artifacts" section with this "public" folder

Page 95: Breaking bad habits with GitLab CI

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://<USERNAME>.GITLAB.IO/<PROJECTNAME>

Page 96: Breaking bad habits with GitLab CI

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

Page 97: Breaking bad habits with GitLab CI

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

Page 98: Breaking bad habits with GitLab CI
Page 99: Breaking bad habits with GitLab CI
Page 100: Breaking bad habits with GitLab CI
Page 101: Breaking bad habits with GitLab CI

INTRODUCING ENVIRONMENTS

Page 102: Breaking bad habits with GitLab CI

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

Page 103: Breaking bad habits with GitLab CI
Page 104: Breaking bad habits with GitLab CI
Page 105: Breaking bad habits with GitLab CI
Page 106: Breaking bad habits with GitLab CI

REQUIREMENT #7DO NOT MESS UP PRODUCTION

Page 107: Breaking bad habits with GitLab CI

SWITCHING TO MANUAL DEPLOYMENT

Page 108: Breaking bad habits with GitLab CI

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

Page 109: Breaking bad habits with GitLab CI
Page 110: Breaking bad habits with GitLab CI

BOOTING UP APPLICATION INSTANCE PER FEATURE-BRANCH

Page 111: Breaking bad habits with GitLab CI
Page 112: Breaking bad habits with GitLab CI

<S3_BUCKET>.S3-WEBSITE-US-EAST-1.AMAZONAWS.COM/<BRANCHNAME>

Page 113: Breaking bad habits with GitLab CI

review apps: image: python:latest environment: review script: - pip install awscli - aws s3 cp ./ s3://reviewbucket/$CI_BUILD_REF_NAME/ --recursive

Page 114: Breaking bad habits with GitLab CI

$CI_BUILD_REF_NAME

?

Page 115: Breaking bad habits with GitLab CI

PREDEFINED VARIABLES

Page 116: Breaking bad habits with GitLab CI

SUMMARY

1. Deployment is just a set of commands2. You need to provide secret keys

3. You specify where which branches should go to4. GitLab conserves the history of deployments

5. You can enable manual deployment

Page 117: Breaking bad habits with GitLab CI
Page 118: Breaking bad habits with GitLab CI
Page 119: Breaking bad habits with GitLab CI
Page 120: Breaking bad habits with GitLab CI

GO TO GITLAB.COM

Page 121: Breaking bad habits with GitLab CI

@[email protected]/GITLAB-CI1

BIT.LY/GITLAB-CI2