Sobes.tech
Junior

What do you understand by CI/CD?

sobes.tech AI

Answer from AI

CI/CD is a set of practices aimed at automating and monitoring the entire application lifecycle, from team integration of changes to deployment in production. It is a culture, a set of principles and methodologies that enable more frequent and reliable delivery of value to users.

Main components:

  • CI (Continuous Integration): Continuous integration. The process of frequently integrating code from all developers into a shared repository (e.g., Git) with subsequent automatic building and testing. The goal is early detection of integration errors.

    Main CI practices:

    • Frequent commits to the main branch.
    • Automatic project build on each commit.
    • Automatic execution of a set of tests (unit, integration).
    • Instant feedback to the team when problems are detected.
  • CD (Continuous Delivery) / CD (Continuous Deployment):

    • Continuous Delivery: CI evolution. After successful build and testing, the artifact (e.g., Docker image) is ready for deployment in any environment. Deployment to production remains a manual step, but the process is fully automated and always ready for execution.

    • Continuous Deployment: The highest level of automation. Any change that has successfully passed CI and automated tests is automatically deployed to production without manual steps. Requires a very high level of trust in automated testing.

Both forms of CD include automation of the following stages: * Passing all tests (additionally functional, load tests). * Packaging the application (artifact). * Deployment to testing, staging environments. * Deployment to production (automatic in case of Continuous Deployment).

Goals of CI/CD:

  • Accelerate development and delivery cycle.
  • Reduce deployment risk.
  • Improve product quality through early error detection.
  • Enhance collaboration between development, testing, and operations teams.

Tools used in CI/CD (examples): Jenkins, GitLab CI, GitHub Actions, CircleCI, Travis CI, Azure DevOps, Spinnaker, Kubernetes, Docker, Ansible, Terraform.

# Example part of a GitLab CI pipeline for the CI stage
stages:
  - build
  - test

build:
  stage: build
  script:
    - echo "Building the application..."
    - docker build -t my-app:$CI_COMMIT_SHORT_SHA .
  tags:
    - shared-runners

test:
  stage: test
  script:
    - echo "Running tests..."
    - docker run my-app:$CI_COMMIT_SHORT_SHA npm test
  needs:
    - build

# Example part of a GitLab CI pipeline for the CD (Delivery) stage
deploy_staging:
  stage: deploy
  environment:
    name: staging
    url: https://staging.example.com
  script:
    - echo "Deploying to staging..."
    # Commands for deploying to staging (e.g., kubectl apply)
  only:
    - main
  tags:
    - kubernetes-runner

deploy_production:
  stage: deploy
  environment:
    name: production
    url: https://prod.example.com
  script:
    - echo "Deploying to production manually triggered..."
    # Commands for deploying to production (e.g., kubectl apply)
  when: manual # Manual confirmation for production
  only:
    - main
  needs:
    - deploy_staging # Dependency on successful staging deployment
  tags:
    - kubernetes-runner