docker.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. name: docker
  2. # Docker image pipeline (optional install path, docs/docker.md).
  3. # - pull_request: builds the server image on amd64 to keep the Dockerfile
  4. # honest; publishes nothing.
  5. # - v* tag: builds linux/amd64 + linux/arm64 and pushes to GHCR, tagged
  6. # semver + latest. The workflow is identical on forks and upstream:
  7. # images land under ghcr.io/<owner>/<repo> from github.repository, and
  8. # the built-in GITHUB_TOKEN is enough (no registry secrets).
  9. on:
  10. pull_request:
  11. paths:
  12. - 'Dockerfile'
  13. - '.dockerignore'
  14. - 'docker-compose.yml'
  15. - 'scripts/build-agents.sh'
  16. - '.github/workflows/docker.yml'
  17. push:
  18. tags: ['v*']
  19. concurrency:
  20. group: docker-${{ github.event.pull_request.number || github.ref }}
  21. cancel-in-progress: true
  22. permissions:
  23. contents: read
  24. packages: write
  25. env:
  26. REGISTRY: ghcr.io
  27. jobs:
  28. image:
  29. runs-on: ubuntu-latest
  30. steps:
  31. - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
  32. - uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
  33. - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
  34. # Image name lowercased (GHCR rejects uppercase), version from the tag
  35. # minus the v prefix (same value goreleaser feeds httpapi.Version), and
  36. # the agent version from agent/VERSION (#790) so the embed stamp
  37. # matches the release binaries.
  38. - name: Resolve image, version and agent version
  39. id: meta
  40. env:
  41. REPO: ${{ github.repository }}
  42. run: |
  43. set -e
  44. IMAGE="$REGISTRY/$(echo "$REPO" | tr '[:upper:]' '[:lower:]')"
  45. echo "image=$IMAGE" >> "$GITHUB_OUTPUT"
  46. echo "agent=$(tr -d '[:space:]' < agent/VERSION)" >> "$GITHUB_OUTPUT"
  47. echo "commit=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
  48. # The Go toolchain comes from the module, never from a copy in the
  49. # Dockerfile: when go.mod moved to 1.27 the image kept building with
  50. # 1.26 and failed here on every tag.
  51. GO_VER=$(sed -n 's/^go //p' server-go/go.mod | head -1)
  52. echo "go=$GO_VER" >> "$GITHUB_OUTPUT"
  53. if [ "${{ github.ref_type }}" = 'tag' ]; then
  54. VERSION="${GITHUB_REF_NAME#v}"
  55. echo "version=$VERSION" >> "$GITHUB_OUTPUT"
  56. echo "platforms=linux/amd64,linux/arm64" >> "$GITHUB_OUTPUT"
  57. echo "push=true" >> "$GITHUB_OUTPUT"
  58. MAJMIN="${VERSION%.*}"
  59. MAJ="${VERSION%%.*}"
  60. {
  61. echo "tags<<EOF"
  62. echo "$IMAGE:$VERSION"
  63. echo "$IMAGE:$MAJMIN"
  64. echo "$IMAGE:$MAJ"
  65. echo "$IMAGE:latest"
  66. echo "EOF"
  67. } >> "$GITHUB_OUTPUT"
  68. else
  69. echo "version=0.0.0-pr" >> "$GITHUB_OUTPUT"
  70. echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT"
  71. echo "push=false" >> "$GITHUB_OUTPUT"
  72. echo "tags=$IMAGE:pr-validation" >> "$GITHUB_OUTPUT"
  73. fi
  74. - name: Log in to GHCR (tag builds only)
  75. if: github.ref_type == 'tag'
  76. uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
  77. with:
  78. registry: ${{ env.REGISTRY }}
  79. username: ${{ github.actor }}
  80. password: ${{ secrets.GITHUB_TOKEN }}
  81. - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
  82. with:
  83. context: .
  84. platforms: ${{ steps.meta.outputs.platforms }}
  85. push: ${{ steps.meta.outputs.push }}
  86. tags: ${{ steps.meta.outputs.tags }}
  87. build-args: |
  88. GO_VERSION=${{ steps.meta.outputs.go }}
  89. VERSION=${{ steps.meta.outputs.version }}
  90. BUILD_COMMIT=${{ steps.meta.outputs.commit }}
  91. AGENT_VERSION=${{ steps.meta.outputs.agent }}
  92. cache-from: type=gha
  93. cache-to: type=gha,mode=max