Breaking Bad habits
with GitLab CI
Ivan Nemytchenko | RubyConf Taiwan | December 2, 2016
Ivan
Nemytchenko
→ Russian, live in Serbia
→ Ruby developer since 2006
→ Co-found 2 outsource agencies
→ Team lead, Project manager, etc
→ Coorganized 2 IT conferences
→ Developer advocate at GitLab
→ inem.at
→ @inem
RailsHurts.com
How to Stop being Rails
developer
Why talk about GitLab?
→ big monolythic RoR application
→ open source
→ monthly releases
→ open processes (google for GitLab handbook)
→ 140 people (all remote)
→ 100.000+ companies use it
→ GitLab.com is free
GitLab
has been started as an attempt to build
open source alternative to GitHub
Breaking Bad with GitLab CI
Breaking Bad Habits with GitLab CI
Habit of not automating
routine operations
CatGrep Sophisticated Technologies inc.
→ file1.txt
→ file2.txt
CatGrep Sophisticated Technologies inc.
The code is on GitLab.com
Requirement #1
Concatenation result should contain
"Hello world"
cat file1.txt file2.txt | grep -q "Hello world"
Run first test inside CI
Run first test inside CI
.gitlab-ci.yml
Run first test inside CI
test:
script: cat file1.txt file2.txt | grep -q 'Hello world'
Run first test inside CI
Run first test inside CI
Requirement #2
Package code before sending it to customer
Package code
test:
script: cat file1.txt file2.txt | grep -q 'Hello world'
package:
script: cat file1.txt file2.txt | gzip > package.gz
Package code
Make results of your build downloadable
Make results of your build downloadable
Make results of your build downloadable
Make results of your build downloadable
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
Run jobs sequentially
Run jobs sequentially
Speeding up the build
Removing Duplication
Learning what Docker image to use
Learning what Docker image to use
Learning what Docker image to use
image: alpine
Learning what Docker image to use
Learning what Docker image to use
Requirement #3
ISO instead of GZIP
Dealing with complex scenarios
Dealing with complex scenarios
script:
- apk add -U cdrkit
- mkisofs -o ./packaged.iso ./compiled.txt
→ 3 stages
→ passing files between stages
→ downloadable artifacts
→ optimized execution time
→ custom pipeline
Requirement #4
Publish a website, containing packages
Publish a website
aws s3 cp ./ s3://yourbucket/ --recursive
Publish a website
Publish a website
First Automated Deployment
→ awscli can be installed using pip
→ pip goes together with python
First Automated Deployment
s3:
image: python
stage: deploy
script:
- pip install awscli
- aws s3 cp ./ s3://yourbucket/ --recursive
First Automated Deployment
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
First Automated Deployment
Keeping Secret Things Secret
Keeping Secret Things Secret
Settings → Variables
Keeping Secret Things Secret
s3:
image: python
stage: deploy
script:
- pip install awscli
- aws s3 cp ./ s3://yourbucket/ --recursive
Keeping Secret Things Secret
Requirement #5
Two developers on the project
Two developers on the project
Two developers on the project
Requirement #6
Need a separate place
for testing
Separate place for testing
GitLab Pages
Host website using GitLab Pages
→ your job should be named "pages"
→ put your files into "public" folder
→ specify "artifacts" section with this "public" folder
Host website using GitLab Pages
http://<username>.gitlab.io/<projectname>
Host website using GitLab Pages
pages:
stage: deploy
image: alpine
script:
- mkdir -p ./public && cp ./*.* ./public/
artifacts:
paths:
- public
except:
- master
Separate place for testing
s3:
image: python
stage: deploy
script:
- pip install awscli
- aws s3 cp ./ s3://yourbucket/ --recursive
only:
- master
pages:
image: alpine
stage: deploy
script:
- mkdir -p ./public && cp ./*.* ./public/
artifacts:
paths:
- public
except:
- master
Separate place for testing
Separate place for testing
Separate place for testing
Using Environments
Using Environments
Using Environments
Requirement #7
Do not mess up production
Do not mess up production
Do not mess up production
You can afford CI even for
small projects!
Why no ruby?
Questions?
@inem
ivan@gitlab.com
→ bit.ly/gitlab-ci
Breaking Bad Habits with GitLab CI