docker-publish.yml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. name: "[Build] Release Image"
  2. on:
  3. push:
  4. # branches: [main]
  5. tags: ["v*"]
  6. workflow_dispatch:
  7. inputs:
  8. version:
  9. description: "Version to set (e.g. v1.2.3). Leave empty to auto-detect."
  10. required: false
  11. default: ""
  12. env:
  13. REGISTRY: ghcr.io
  14. IMAGE_NAME: ${{ github.repository }}
  15. jobs:
  16. build-and-push:
  17. runs-on: ubuntu-latest
  18. permissions:
  19. contents: read
  20. packages: write
  21. steps:
  22. - name: Checkout repository
  23. uses: actions/checkout@v4
  24. - name: Set up Docker Buildx
  25. uses: docker/setup-buildx-action@v3
  26. - name: Log in to GitHub Container Registry
  27. uses: docker/login-action@v3
  28. with:
  29. registry: ${{ env.REGISTRY }}
  30. username: ${{ github.actor }}
  31. password: ${{ secrets.GITHUB_TOKEN }}
  32. - name: Determine version
  33. id: version
  34. run: |
  35. if [[ -n "${{ github.event.inputs.version }}" ]]; then
  36. echo "value=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
  37. elif [[ "${{ github.ref_type }}" == "tag" ]]; then
  38. echo "value=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
  39. else
  40. TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "development")
  41. echo "value=${TAG}" >> "$GITHUB_OUTPUT"
  42. fi
  43. - name: Extract metadata (tags, labels)
  44. id: meta
  45. uses: docker/metadata-action@v5
  46. with:
  47. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  48. tags: |
  49. type=raw,value=latest
  50. type=raw,value=${{ steps.version.outputs.value }},enable=${{ steps.version.outputs.value != 'development' }}
  51. # A short hash of the server action key, so a new key rebuilds Next
  52. # instead of reusing a cached build (see the Dockerfile).
  53. - name: Fingerprint the server action key
  54. id: actions_key
  55. env:
  56. KEY: ${{ secrets.NEXT_SERVER_ACTIONS_BUILD_KEY }}
  57. run: echo "id=$(printf '%s' "$KEY" | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT"
  58. - name: Build and push Docker image
  59. uses: docker/build-push-action@v6
  60. with:
  61. context: .
  62. push: true
  63. tags: ${{ steps.meta.outputs.tags }}
  64. labels: ${{ steps.meta.outputs.labels }}
  65. # The POSTHOG_ lines upload the browser source maps to PostHog error
  66. # tracking for app.torqvoice.com when the key is set, and skip it
  67. # otherwise (see scripts/upload-source-maps.sh).
  68. build-args: |
  69. APP_VERSION=${{ steps.version.outputs.value }}
  70. NEXT_ACTIONS_FINGERPRINT=${{ steps.actions_key.outputs.id }}
  71. POSTHOG_SOURCEMAPS=${{ secrets.POSTHOG_SOURCEMAPS_API_KEY != '' && 'on' || 'off' }}
  72. POSTHOG_CLI_HOST=https://eu.posthog.com
  73. POSTHOG_CLI_PROJECT_ID=142584
  74. POSTHOG_UPLOAD_ATTEMPT=${{ github.run_id }}-${{ github.run_attempt }}
  75. # Keeps server action IDs the same from release to release, so tabs
  76. # opened before a deploy keep working (see the Dockerfile).
  77. secrets: |
  78. next_actions_key=${{ secrets.NEXT_SERVER_ACTIONS_BUILD_KEY }}
  79. posthog_cli_api_key=${{ secrets.POSTHOG_SOURCEMAPS_API_KEY }}
  80. cache-from: type=gha
  81. cache-to: type=gha,mode=max