docker-publish.yml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. - name: Build and push Docker image
  52. uses: docker/build-push-action@v6
  53. with:
  54. context: .
  55. push: true
  56. tags: ${{ steps.meta.outputs.tags }}
  57. labels: ${{ steps.meta.outputs.labels }}
  58. build-args: |
  59. APP_VERSION=${{ steps.version.outputs.value }}
  60. cache-from: type=gha
  61. cache-to: type=gha,mode=max