docker-publish.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. permissions:
  26. contents: read
  27. packages: write
  28. # This is used to complete the identity challenge
  29. # with sigstore/fulcio when running outside of PRs.
  30. id-token: write
  31. steps:
  32. - name: Checkout repository
  33. uses: actions/checkout@v4
  34. # Fetch the ipinfo database file using curl if API key is defined
  35. - name: Fetch DB from ipinfo.io
  36. # IPINFO_APIKEY is set in https://github.com/librespeed/speedtest/settings/secrets/actions
  37. run: |
  38. if [ -z "${{ secrets.IPINFO_APIKEY }}" ]; then
  39. echo "Warning: IPINFO_APIKEY is not defined."
  40. else
  41. curl -L https://ipinfo.io/data/free/country_asn.mmdb?token=${{ secrets.IPINFO_APIKEY }} -o backend/country_asn.mmdb
  42. fi
  43. # Set up BuildKit Docker container builder to be able to build
  44. # multi-platform images and export cache
  45. # https://github.com/docker/setup-buildx-action
  46. - name: Set up Docker Buildx
  47. uses: docker/setup-buildx-action@v3
  48. # Login against a Docker registry except on PR
  49. # https://github.com/docker/login-action
  50. - name: Log into registry ${{ env.REGISTRY }}
  51. if: github.event_name != 'pull_request'
  52. uses: docker/login-action@v3
  53. with:
  54. registry: ${{ env.REGISTRY }}
  55. username: ${{ github.actor }}
  56. password: ${{ secrets.GITHUB_TOKEN }}
  57. # Extract metadata (tags, labels) for Docker
  58. # https://github.com/docker/metadata-action
  59. - name: Extract Docker metadata
  60. id: meta
  61. uses: docker/metadata-action@v5
  62. with:
  63. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  64. tags: |
  65. type=ref,event=branch
  66. type=ref,event=pr
  67. # set latest tag for default branch
  68. type=raw,value=latest,enable={{is_default_branch}}
  69. type=semver,pattern={{version}}
  70. type=semver,pattern={{major}}.{{minor}}
  71. # Build and push Docker image with Buildx (don't push on PR)
  72. # https://github.com/docker/build-push-action
  73. - name: Build and push Docker image
  74. id: build-and-push
  75. uses: docker/build-push-action@v5
  76. with:
  77. context: .
  78. platforms: linux/amd64,linux/arm64
  79. push: ${{ github.event_name != 'pull_request' }}
  80. tags: ${{ steps.meta.outputs.tags }}
  81. labels: ${{ steps.meta.outputs.labels }}
  82. cache-from: type=gha
  83. cache-to: type=gha,mode=max