docker.yml 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. if [ "${{ github.ref_type }}" = 'tag' ]; then
  49. VERSION="${GITHUB_REF_NAME#v}"
  50. echo "version=$VERSION" >> "$GITHUB_OUTPUT"
  51. echo "platforms=linux/amd64,linux/arm64" >> "$GITHUB_OUTPUT"
  52. echo "push=true" >> "$GITHUB_OUTPUT"
  53. MAJMIN="${VERSION%.*}"
  54. MAJ="${VERSION%%.*}"
  55. {
  56. echo "tags<<EOF"
  57. echo "$IMAGE:$VERSION"
  58. echo "$IMAGE:$MAJMIN"
  59. echo "$IMAGE:$MAJ"
  60. echo "$IMAGE:latest"
  61. echo "EOF"
  62. } >> "$GITHUB_OUTPUT"
  63. else
  64. echo "version=0.0.0-pr" >> "$GITHUB_OUTPUT"
  65. echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT"
  66. echo "push=false" >> "$GITHUB_OUTPUT"
  67. echo "tags=$IMAGE:pr-validation" >> "$GITHUB_OUTPUT"
  68. fi
  69. - name: Log in to GHCR (tag builds only)
  70. if: github.ref_type == 'tag'
  71. uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
  72. with:
  73. registry: ${{ env.REGISTRY }}
  74. username: ${{ github.actor }}
  75. password: ${{ secrets.GITHUB_TOKEN }}
  76. - uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
  77. with:
  78. context: .
  79. platforms: ${{ steps.meta.outputs.platforms }}
  80. push: ${{ steps.meta.outputs.push }}
  81. tags: ${{ steps.meta.outputs.tags }}
  82. build-args: |
  83. VERSION=${{ steps.meta.outputs.version }}
  84. BUILD_COMMIT=${{ steps.meta.outputs.commit }}
  85. AGENT_VERSION=${{ steps.meta.outputs.agent }}
  86. cache-from: type=gha
  87. cache-to: type=gha,mode=max