docker.yml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. name: docker
  2. on:
  3. push:
  4. tags:
  5. - "v*"
  6. workflow_dispatch:
  7. permissions:
  8. contents: read
  9. packages: write
  10. env:
  11. REGISTRY: ghcr.io
  12. IMAGE_NAME: ${{ github.repository }}
  13. jobs:
  14. build-and-push:
  15. runs-on: ubuntu-latest
  16. steps:
  17. - name: Checkout
  18. uses: actions/checkout@v4
  19. - name: Lowercase repository owner for ghcr.io
  20. id: repo
  21. run: echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
  22. - name: Derive version from tag
  23. id: version
  24. run: |
  25. if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
  26. echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
  27. else
  28. echo "version=0.0.0-dev" >> "$GITHUB_OUTPUT"
  29. fi
  30. echo "build_time=$(git show -s --format=%cI HEAD)" >> "$GITHUB_OUTPUT"
  31. - name: Set up QEMU
  32. uses: docker/setup-qemu-action@v3
  33. - name: Set up Docker Buildx
  34. uses: docker/setup-buildx-action@v3
  35. - name: Log in to GHCR
  36. uses: docker/login-action@v3
  37. with:
  38. registry: ${{ env.REGISTRY }}
  39. username: ${{ github.actor }}
  40. password: ${{ secrets.GITHUB_TOKEN }}
  41. - name: Build and push multi-arch image
  42. uses: docker/build-push-action@v6
  43. with:
  44. context: .
  45. file: ./Dockerfile
  46. platforms: linux/amd64,linux/arm64
  47. push: true
  48. build-args: |
  49. VERSION=${{ steps.version.outputs.version }}
  50. BUILD_TIME=${{ steps.version.outputs.build_time }}
  51. tags: |
  52. ${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:latest
  53. ${{ env.REGISTRY }}/${{ steps.repo.outputs.name }}:${{ steps.version.outputs.version }}
  54. cache-from: type=gha
  55. cache-to: type=gha,mode=max