docker-publish.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. name: Docker
  2. # This workflow uses actions that are not certified by GitHub.
  3. # They are provided by a third-party and are governed by
  4. # separate terms of service, privacy policy, and support
  5. # documentation.
  6. on:
  7. schedule:
  8. - cron: '30 20 * * Sun'
  9. push:
  10. branches: ["*"]
  11. # Publish semver tags as releases.
  12. tags: ["v*.*.*"]
  13. pull_request:
  14. branches: ["{{is_default_branch}}"]
  15. release:
  16. types: [published]
  17. env:
  18. # Use docker.io for Docker Hub if empty
  19. REGISTRY: ghcr.io
  20. # github.repository as <account>/<repo>
  21. IMAGE_NAME: ${{ github.repository }}
  22. jobs:
  23. build:
  24. runs-on: ubuntu-latest
  25. strategy:
  26. fail-fast: false
  27. matrix:
  28. include:
  29. - dockerfile: ./Dockerfile
  30. image: ghcr.io/${{ github.repository }}
  31. flavour: ""
  32. - dockerfile: ./Dockerfile.alpine
  33. image: ghcr.io/${{ github.repository }}
  34. flavour: "-alpine"
  35. permissions:
  36. contents: read
  37. packages: write
  38. # This is used to complete the identity challenge
  39. # with sigstore/fulcio when running outside of PRs.
  40. id-token: write
  41. steps:
  42. - name: Checkout repository
  43. uses: actions/checkout@v6
  44. # Fetch the ipinfo database file using curl if API key is defined
  45. - name: Fetch DB from ipinfo.io
  46. # IPINFO_APIKEY is set in https://github.com/librespeed/speedtest/settings/secrets/actions
  47. run: |
  48. if [ -z "${{ secrets.IPINFO_APIKEY }}" ]; then
  49. echo "Warning: IPINFO_APIKEY is not defined."
  50. else
  51. curl -L https://ipinfo.io/data/free/country_asn.mmdb?token=${{ secrets.IPINFO_APIKEY }} -o backend/country_asn.mmdb
  52. fi
  53. # Set up QEMU for multi-arch builds
  54. - name: Set up QEMU
  55. uses: docker/setup-qemu-action@v3
  56. # Set up BuildKit Docker container builder to be able to build
  57. # multi-platform images and export cache
  58. # https://github.com/docker/setup-buildx-action
  59. - name: Set up Docker Buildx
  60. uses: docker/setup-buildx-action@v3
  61. # Login against a Docker registry except on PR
  62. # https://github.com/docker/login-action
  63. - name: Log into registry ${{ env.REGISTRY }}
  64. if: github.event_name != 'pull_request'
  65. uses: docker/login-action@v3
  66. with:
  67. registry: ${{ env.REGISTRY }}
  68. username: ${{ github.actor }}
  69. password: ${{ secrets.GITHUB_TOKEN }}
  70. # Extract metadata (tags, labels) for Docker
  71. # https://github.com/docker/metadata-action
  72. - name: Extract Docker metadata
  73. id: meta
  74. uses: docker/metadata-action@v5
  75. with:
  76. images: ${{ matrix.image }}
  77. tags: |
  78. type=ref,event=branch,suffix=${{ matrix.flavour }}
  79. type=ref,event=pr,suffix=${{ matrix.flavour }}
  80. # set latest tag for default branch
  81. type=raw,value=latest${{ matrix.flavour }},enable={{is_default_branch}}
  82. type=semver,pattern={{version}}${{ matrix.flavour }}
  83. type=semver,pattern={{major}}${{ matrix.flavour }}
  84. type=semver,pattern={{major}}.{{minor}}${{ matrix.flavour }}
  85. type=semver,pattern={{major}}.{{minor}}.{{patch}}${{ matrix.flavour }}
  86. # Build and push Docker image with Buildx (don't push on PR)
  87. # https://github.com/docker/build-push-action
  88. - name: Build and push Docker image
  89. id: build-and-push
  90. uses: docker/build-push-action@v6
  91. with:
  92. context: .
  93. file: ${{ matrix.dockerfile }}
  94. platforms: linux/amd64,linux/arm64
  95. push: ${{ github.event_name != 'pull_request' }}
  96. tags: ${{ steps.meta.outputs.tags }}
  97. labels: ${{ steps.meta.outputs.labels }}
  98. cache-from: type=gha
  99. cache-to: type=gha,mode=max