build-publish.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. name: Build and publish Docker images
  2. permissions:
  3. contents: read
  4. packages: write
  5. on:
  6. workflow_dispatch:
  7. schedule:
  8. - cron: "0 0 * * 1"
  9. push:
  10. branches:
  11. - main
  12. tags:
  13. - "*.*.*"
  14. paths-ignore:
  15. - "test/*"
  16. - ".gitignore"
  17. - "docker-compose-separate-containers.yml"
  18. - "docker-compose.yml"
  19. - "LICENSE"
  20. - "Makefile"
  21. - "*.md"
  22. jobs:
  23. multiarch-build:
  24. name: Build and publish image
  25. strategy:
  26. matrix:
  27. base: [alpine, debian]
  28. runs-on: ubuntu-latest
  29. if: (github.event_name == 'schedule' && github.repository == 'nginx-proxy/nginx-proxy') || (github.event_name != 'schedule')
  30. steps:
  31. - name: Checkout
  32. uses: actions/checkout@v5
  33. with:
  34. fetch-depth: 0
  35. - name: Retrieve nginx-proxy version
  36. id: nginx-proxy_version
  37. run: echo "VERSION=$(git describe --tags)" >> "$GITHUB_OUTPUT"
  38. - name: Retrieve docker-gen version
  39. id: docker-gen_version
  40. run: sed -n -e 's;^FROM docker.io/nginxproxy/docker-gen:\([0-9.]*\).*;VERSION=\1;p' Dockerfile.${{ matrix.base }} >> "$GITHUB_OUTPUT"
  41. - name: Get Docker tags
  42. id: docker_meta
  43. uses: docker/metadata-action@v5
  44. with:
  45. images: |
  46. ghcr.io/nginx-proxy/nginx-proxy
  47. nginxproxy/nginx-proxy
  48. jwilder/nginx-proxy
  49. tags: |
  50. type=semver,pattern={{version}},enable=${{ matrix.base == 'debian' }}
  51. type=semver,pattern={{major}}.{{minor}},enable=${{ matrix.base == 'debian' }}
  52. type=semver,suffix=-alpine,pattern={{version}},enable=${{ matrix.base == 'alpine' }}
  53. type=semver,suffix=-alpine,pattern={{major}}.{{minor}},enable=${{ matrix.base == 'alpine' }}
  54. type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' && matrix.base == 'debian' }}
  55. type=raw,value=alpine,enable=${{ github.ref == 'refs/heads/main' && matrix.base == 'alpine' }}
  56. labels: |
  57. org.opencontainers.image.authors=Nicolas Duchon <nicolas.duchon@gmail.com> (@buchdag), Jason Wilder
  58. org.opencontainers.image.version=${{ steps.nginx-proxy_version.outputs.VERSION }}
  59. flavor: |
  60. latest=false
  61. - name: Set up QEMU
  62. uses: docker/setup-qemu-action@v3
  63. - name: Set up Docker Buildx
  64. uses: docker/setup-buildx-action@v3
  65. - name: Login to DockerHub
  66. uses: docker/login-action@v3
  67. with:
  68. username: ${{ secrets.DOCKERHUB_USERNAME }}
  69. password: ${{ secrets.DOCKERHUB_TOKEN }}
  70. - name: Log in to GitHub Container Registry
  71. uses: docker/login-action@v3
  72. with:
  73. registry: ghcr.io
  74. username: ${{ github.actor }}
  75. password: ${{ secrets.GITHUB_TOKEN }}
  76. - name: Build and push the image
  77. id: docker_build
  78. uses: docker/build-push-action@v6
  79. with:
  80. context: .
  81. file: Dockerfile.${{ matrix.base }}
  82. build-args: |
  83. NGINX_PROXY_VERSION=${{ steps.nginx-proxy_version.outputs.VERSION }}
  84. DOCKER_GEN_VERSION=${{ steps.docker-gen_version.outputs.VERSION }}
  85. platforms: linux/amd64,linux/arm64,linux/s390x,linux/arm/v7
  86. sbom: true
  87. push: true
  88. provenance: mode=max
  89. tags: ${{ steps.docker_meta.outputs.tags }}
  90. labels: ${{ steps.docker_meta.outputs.labels }}
  91. cache-from: type=gha
  92. cache-to: type=gha,mode=max
  93. - name: Images digests
  94. run: echo ${{ steps.docker_build.outputs.digest }}