push.yaml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. name: Build and push Docker image (latest)
  2. on:
  3. push:
  4. branches:
  5. - main
  6. tags:
  7. - v*
  8. jobs:
  9. docker-tests:
  10. runs-on: ubuntu-latest
  11. strategy:
  12. matrix:
  13. dockerfile: [ "Dockerfile", "Dockerfile.alpine" ]
  14. steps:
  15. - uses: actions/checkout@v3
  16. with:
  17. submodules: recursive
  18. - name: Set up Docker Buildx
  19. id: buildx
  20. uses: docker/setup-buildx-action@master
  21. with:
  22. install: true
  23. - name: Build test image
  24. uses: docker/build-push-action@v3
  25. with:
  26. context: ./
  27. file: ${{ matrix.dockerfile }}
  28. push: false
  29. pull: true
  30. target: builder
  31. tags: frankenphp:${{ github.sha }}-builder
  32. builder: ${{ steps.buildx.outputs.name }}
  33. cache-from: type=gha
  34. cache-to: type=gha,mode=max
  35. outputs: type=docker,dest=/tmp/.builder.tar
  36. - name: Run tests
  37. run: |
  38. docker load -i /tmp/.builder.tar
  39. docker run --rm frankenphp:${{ github.sha }}-builder "go test"
  40. push-image:
  41. runs-on: ubuntu-latest
  42. strategy:
  43. matrix:
  44. dockerfile: [ "Dockerfile", "Dockerfile.alpine" ]
  45. steps:
  46. - uses: actions/checkout@v3
  47. with:
  48. submodules: recursive
  49. - name: Docker Login
  50. uses: docker/login-action@v2
  51. with:
  52. registry: ${{secrets.REGISTRY_LOGIN_SERVER}}
  53. username: ${{secrets.REGISTRY_USERNAME}}
  54. password: ${{secrets.REGISTRY_PASSWORD}}
  55. - name: Docker meta
  56. id: meta
  57. uses: docker/metadata-action@v4
  58. with:
  59. # list of Docker images to use as base name for tags
  60. images: |
  61. ${{ secrets.REGISTRY_LOGIN_SERVER }}/${{ secrets.REGISTRY_REPO }}/frankenphp
  62. # generate Docker tags based on the following events/attributes
  63. tags: |
  64. type=schedule
  65. type=ref,event=branch
  66. type=ref,event=pr
  67. type=semver,pattern={{version}}
  68. type=semver,pattern={{major}}.{{minor}}
  69. type=semver,pattern={{major}}
  70. type=sha
  71. - name: Set up Docker Buildx
  72. id: buildx
  73. uses: docker/setup-buildx-action@master
  74. with:
  75. install: true
  76. - name: Setup QEMU
  77. uses: docker/setup-qemu-action@v2
  78. - name: Build and Push Image
  79. uses: docker/build-push-action@v3
  80. with:
  81. context: ./
  82. file: ${{ matrix.dockerfile }}
  83. push: true
  84. pull: true
  85. target: final
  86. platforms: linux/amd64,linux/arm64
  87. tags: ${{ steps.meta.outputs.tags }}
  88. labels: ${{ steps.meta.outputs.labels }}
  89. builder: ${{ steps.buildx.outputs.name }}
  90. cache-from: type=gha
  91. cache-to: type=gha,mode=max