CI/CD Pipelines: Containers, Services, and Environments

Container build/push flows, service dependencies, environment modeling, and deploy snippets.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Build and publish container images
Build and push Docker image with GitHub Actions
steps:
  - uses: actions/checkout@v4
  - uses: docker/login-action@v3
    with:
      registry: ghcr.io
      username: ${{ github.actor }}
      password: ${{ secrets.GITHUB_TOKEN }}
  - uses: docker/build-push-action@v6
    with:
      context: .
      push: true
      tags: ghcr.io/acme/myapp:${{ github.sha }}

# Authenticate, build, and push to a registry.

Build image in GitLab CI
image: docker:27

services:
  - docker:27-dind

variables:
  DOCKER_TLS_CERTDIR: "/certs"

build_image:
  stage: build
  script:
    - docker build -t registry.example.com/myapp:$CI_COMMIT_SHA .
    - docker push registry.example.com/myapp:$CI_COMMIT_SHA

# Use Docker-in-Docker or a compatible runner setup.

Deploy a new image to Kubernetes
kubectl set image deployment/web web=ghcr.io/acme/myapp:$GIT_SHA
kubectl rollout status deployment/web

# Update a deployment image and monitor rollout status.

## Run with databases or environment-specific settings
Start PostgreSQL service for tests
services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_PASSWORD: postgres
    ports:
      - 5432:5432
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 10s
      --health-timeout 5s
      --health-retries 5

# Run integration tests against a service container.

Use named environments
jobs:
  deploy:
    environment:
      name: production
      url: https://app.example.com

# Attach production jobs to an environment with protection rules.

Run deploy only on deployment-capable agents
stage('Deploy') {
  agent { label 'deploy' }
  steps {
    sh './scripts/deploy.sh'
  }
}

# Target jobs to specific Jenkins workers or labels.

Recommended next

No recommendations yet.