ci cd presentation What is CI/CD?Continuous Integration
1. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
php[tek] 2023
Build & Release Confidently with
Continuous Integration & Delivery
2. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
What is CI/CD?
3. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Continuous Integration
• Run a series of scripts automatically, any time changes are pushed
• Continuously Integrate our changes
• Automated tests
• Coding standards
• Static code analysis
• ...et cetera
5. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Dependencies & Artifacts
• Dependency management
• Anything that's generated for your app:
• Compiled and/or mini
fi
ed
fi
les
• Binaries
• Remember: source control should only worry about the source
6. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
• Being able to deploy on-demand
• One-click deployments
• You can't forget a step if
everything's automatic!
Continuous Delivery
7. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Delivery
Some manual step to deploy
Deployment
Always Be Deployin'
Continuous Delivery v Deployment
9. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Deploy with Confidence!
In order to deploy con
fi
dently,
we must have con
fi
dence in our tools.
10. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Setting up a CI/CD Pipeline
11. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
• A route from development to
production
• Triggered by di
ff
erent events
(push, merge, etc.)
• Di
ff
erent branches may take
di
ff
erent paths
What is a Pipeline?
Photo by Christian Bass
12. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Popular CI/CD Providers
GitHub Jenkins
Deploybot
GitLab
Travis CI CircleCI Codeship
TeamCity
13. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Welcome to GitLab!
• Source code management tool
• Hosted platform or available for private installation
• Includes CI/CD tools!
Hi, Fatima!
14. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
GitLab CI/CD Tools
• De
fi
ne multiple stages (build, test, deploy, etc.)
• Each stage has one or more jobs
• Multiple runners == run jobs in parallel!
15. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
A Typical Pipeline
Con
fi
gured in .gitlab-ci.yml
16. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Install npm dependencies:
stage: build
script:
- npm install --no-progress
- npm run prod
artifacts:
paths:
- public
cache:
key:
files:
- package-lock.json
paths:
- node_modules
A Simple Job IT AIN'T MUCH
BUT IT'S HONEST WORK
17. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Highly Configurable
docs.gitlab.com/ee/ci/yaml
• Specify a base Docker image
• Determine conditions under which jobs should run
• De
fi
ne dependencies between jobs
• Pre/post-script hooks
• Dynamic environments
• Automatically tag new releases
18. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Environment Variables
19. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Simple Deployments
20. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
What Does our Deployment Process
Look Like Right Now?
• (S)FTP?
• SSH + git pull?
• rsync?
• Docker?
21. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
A Bare-Bones Deployment Method
1. Build the app
2. scp a tarball to production
3. rsync the
fi
les into the web root
22. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Archive, scp, and rsync
ship_to_production:
stage: deploy
script:
- tar -czf release.tgz dist/*
- scp release.tgz "${SSH_USER}@${PRODUCTION_SERVER}:/tmp"
- ssh "${SSH_USER}@${PRODUCTION_SERVER}" "cd /tmp
&& tar -xzf release.tgz
&& rsync release/ /var/www/html/"
23. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Atomic Deployments
releases/
Contains multiple, timestamped deployments
shared/
Data that should persist between deployments
current
Symlink to the current release in releases/, part of web root
25. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Atomic Deployments
stevegrunwell.com/blog/atomic-deployments-from-scratch
ship_to_production:
stage: deploy
script:
# 1. Create + scp tarball
# 2. Extract to /var/www/releases/{TIMESTAMP}
# 3. Symlink shared assets
# 4. Update the `current` symlink
# 5. Reload the web server
# 6. (Optional) Roll off older releases
26. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Extending Our Pipelines
27. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
• Run multiple production
environments/servers
• Some active (blue), some idle
(green)
• Deploy to green
• Once ready, route tra
ffi
c to green
• Blue becomes idle
• In case of issues, re-route to blue
Blue-Green Deployments
28. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Automate Release Chores
Make your pipeline work for you!
• Automatically build Docker images for your app
• Generate + publish API documentation
• Code coverage reporting
• Webhooks
• If you can script it, you can do it!
29. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Remember: This Isn't Magic!
30. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Questions?
31. Steve Grunwell - stevegrunwell.com/slides/intro-to-ci-cd
Thank You!
Steve Grunwell
Sta
ff
Software Engineer, Mailchimp
joind.in/talk/8f583