Skip to content

Docker Deploy

Pipeline

name: docker-deploy
description: "Build, tag, and push a Docker image then deploy to remote server"
steps:
- id: get-version
run: "git describe --tags --always"
- id: lint
run:
- "hadolint Dockerfile"
- "docker compose config --quiet"
- id: build
run: "docker build -t myapp:$PIPE_GET_VERSION ."
depends_on: "lint"
- id: push
run: |
docker tag myapp:$PIPE_GET_VERSION registry.example.com/myapp:$PIPE_GET_VERSION
docker push registry.example.com/myapp:$PIPE_GET_VERSION
depends_on: "build"
- id: deploy
run: "ssh deploy@prod 'docker pull registry.example.com/myapp:$PIPE_GET_VERSION && docker service update --image registry.example.com/myapp:$PIPE_GET_VERSION myapp'"
depends_on: "push"
retry: 2

Concepts demonstrated

  • Output passingget-version output feeds into build, push, and deploy via $PIPE_GET_VERSION
  • Parallel commandslint runs hadolint and docker compose config concurrently
  • Dependenciesbuildpushdeploy chain via depends_on
  • Implicit edgesbuild depends on get-version through $PIPE_GET_VERSION reference
  • Retrydeploy retries up to 2 times on failure