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

Use CI/CD to produce repeatable containers.

Build and push Docker image with GitHub Actions

Authenticate, build, and push to a registry.

yamlANYdockerregistrycontainer
yaml
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 }}
Notes

Combine checkout, registry login, and a build-push step for standard container release pipelines.

Build image in GitLab CI

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

yamlANYdockergitlabdind
yaml
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
Notes

Make sure your runner and registry auth model support the chosen Docker strategy.

Deploy a new image to Kubernetes

Update a deployment image and monitor rollout status.

bashANYkubernetesdeploy
bash
kubectl set image deployment/web web=ghcr.io/acme/myapp:$GIT_SHA
kubectl rollout status deployment/web
Notes

Many CI/CD systems ultimately call platform CLIs like `kubectl`, `helm`, or cloud deploy tools.

Run with databases or environment-specific settings

Model services, secrets, and target environments.

Start PostgreSQL service for tests

Run integration tests against a service container.

yamlANYservicespostgrestesting
yaml
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
Notes

Service containers are useful for test environments that need databases, Redis, or other dependencies.

Use named environments

Attach production jobs to an environment with protection rules.

yamlANYenvironmentproduction
yaml
jobs:
  deploy:
    environment:
      name: production
      url: https://app.example.com
Notes

Named environments make approvals, secrets scoping, and deployment history easier to manage.

Run deploy only on deployment-capable agents

Target jobs to specific Jenkins workers or labels.

groovyANYjenkinsagentdeploy
groovy
stage('Deploy') {
  agent { label 'deploy' }
  steps {
    sh './scripts/deploy.sh'
  }
}
Notes

Dedicated deploy agents help isolate credentials, tools, and access for release operations.

Recommended next

No recommendations yet.