Template

Docker Service Pipeline

Build container images, run security scans, and promote deploy jobs with manual gates.

Best for containerized services.

stages:
  - build
  - scan
  - deploy

build_image:
  stage: build
  image: docker:27
  services:
    - docker:27-dind
  script:
    - docker build -t registry.example.com/app:$CI_COMMIT_SHA .
    - docker save registry.example.com/app:$CI_COMMIT_SHA > image.tar
  artifacts:
    paths:
      - image.tar

scan_image:
  stage: scan
  image: alpine:3.20
  needs:
    - job: build_image
      artifacts: true
  script:
    - echo "scan image.tar"

deploy_prod:
  stage: deploy
  image: alpine:3.20
  needs:
    - scan_image
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: manual
  script:
    - echo "deploy production"