docker-build.yml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. name: Build and Push Docker Images
  2. on:
  3. schedule:
  4. - cron: '0 0 1 * *' # Run monthly on the 1st
  5. workflow_dispatch: # Allow manual triggers
  6. env:
  7. REGISTRY: ghcr.io
  8. IMAGE_NAME: ${{ github.repository }}
  9. jobs:
  10. build-and-push:
  11. runs-on: ubuntu-latest
  12. permissions:
  13. contents: read
  14. packages: write
  15. strategy:
  16. matrix:
  17. variant:
  18. - name: regular
  19. file: Dockerfile
  20. suffix: ''
  21. - name: alpine
  22. file: Dockerfile-alpine
  23. suffix: '-alpine'
  24. steps:
  25. - name: Checkout repository
  26. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
  27. with:
  28. persist-credentials: false
  29. - name: Log in to the Container registry
  30. uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
  31. with:
  32. registry: ${{ env.REGISTRY }}
  33. username: ${{ github.actor }}
  34. password: ${{ secrets.GITHUB_TOKEN }}
  35. - name: Extract metadata for Docker
  36. id: meta
  37. uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5
  38. with:
  39. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  40. tags: |
  41. type=raw,value=latest${{ matrix.variant.suffix }}
  42. type=raw,value={{date 'YYYYMMDD'}}${{ matrix.variant.suffix }}
  43. - name: Build and push image
  44. uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
  45. with:
  46. context: .
  47. file: ./${{ matrix.variant.file }}
  48. push: true
  49. tags: ${{ steps.meta.outputs.tags }}
  50. labels: ${{ steps.meta.outputs.labels }}