CI/CD is a set of practices for automating software development:
# Example of a simple CI/CD pipeline
stages:
- build
- test
- deploy
build_job:
stage: build
script: npm run build
test_job:
stage: test
script: npm run test
deploy_job:
stage: deploy
script: deploy-to-production.shCI/CD is a methodology that allows development teams to automate the processes of integration, testing, and delivery of software. It’s like a conveyor belt that automatically transforms code into a finished product! 🏭
Continuous Integration is a practice where developers regularly merge their code changes into a central repository, after which builds and tests are automatically executed.
# Example CI configuration in GitHub Actions
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm testA practice where code is automatically prepared for production release, but the deployment itself requires manual approval.
An extension of continuous delivery where every change that passes all tests is automatically deployed to production without manual intervention.
# Example CD configuration in GitLab CI
stages:
- build
- test
- staging
- production
build_job:
stage: build
script:
- docker build -t myapp:$CI_COMMIT_SHA .
test_job:
stage: test
script:
- docker run myapp:$CI_COMMIT_SHA npm test
deploy_staging:
stage: staging
script:
- deploy-to-staging.sh
environment:
name: staging
deploy_production:
stage: production
script:
- deploy-to-production.sh
environment:
name: production
when: manual # For Continuous Delivery
# when: on_success # For Continuous Deployment# GitHub Actions workflow
name: Web App CI/CD
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm ci
- name: Lint code
run: npm run lint
- name: Run tests
run: npm test
- name: Build
run: npm run build
- name: Deploy to staging
if: github.ref == 'refs/heads/develop'
run: |
echo "Deploying to staging..."
# deploy-to-staging.sh
- name: Deploy to production
if: github.ref == 'refs/heads/main'
run: |
echo "Deploying to production..."
# deploy-to-production.shCI/CD is not just a set of tools but a development philosophy that helps:
Implementing CI/CD requires a change in team culture, but the results are worth the effort — faster, higher quality, and more predictable software development! 🎯