Continuous Integration and Deployment automate testing and deployment, reducing errors and speeding up releases.
GitLab CI/CD
.gitlab-ci.yml
stages:
- build
- test
- deploy
build:
stage: build
script:
- docker build -t myapp:$CI_COMMIT_SHA .
- docker tag myapp:$CI_COMMIT_SHA myapp:latest
test:
stage: test
script:
- docker run myapp:latest npm test
deploy:
stage: deploy
script:
- docker-compose up -d
only:
- main
GitHub Actions
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy
run: |
docker build -t myapp .
docker-compose up -d
Jenkins
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'docker build -t myapp .'
}
}
stage('Test') {
steps {
sh 'docker run myapp npm test'
}
}
stage('Deploy') {
steps {
sh 'docker-compose up -d'
}
}
}
}
Deployment Strategies
Blue-Green Deployment
Run two identical environments, switch traffic between them.
Rolling Deployment
Gradually replace old instances with new ones.
Canary Deployment
Deploy to small subset, monitor, then roll out fully.
Best Practices
- Automate everything
- Test in staging first
- Use version tags
- Rollback plan ready
- Monitor deployments
- Document procedures
CI/CD transforms software delivery from manual to automated.