docker-publish.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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: [master]
  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. # Keep e2e in this workflow so Docker image build/push is hard-gated by test success.
  24. # Do not move automatic e2e back to playwright.yml, otherwise master pushes run duplicate e2e jobs.
  25. e2e:
  26. runs-on: ubuntu-latest
  27. timeout-minutes: 45
  28. steps:
  29. - name: Checkout
  30. uses: actions/checkout@v6
  31. - name: Setup Node
  32. uses: actions/setup-node@v4
  33. with:
  34. node-version: 20
  35. - name: Install dependencies
  36. run: npm ci
  37. - name: Install Playwright Chromium
  38. run: npx playwright install --with-deps chromium
  39. - name: Run Playwright tests
  40. run: npm run test:e2e
  41. build:
  42. needs: e2e
  43. runs-on: ubuntu-latest
  44. strategy:
  45. fail-fast: false
  46. matrix:
  47. include:
  48. - dockerfile: ./Dockerfile
  49. image: ghcr.io/${{ github.repository }}
  50. flavour: ""
  51. - dockerfile: ./Dockerfile.alpine
  52. image: ghcr.io/${{ github.repository }}
  53. flavour: "-alpine"
  54. permissions:
  55. contents: read
  56. packages: write
  57. # This is used to complete the identity challenge
  58. # with sigstore/fulcio when running outside of PRs.
  59. id-token: write
  60. steps:
  61. - name: Checkout repository
  62. uses: actions/checkout@v6
  63. # Fetch the ipinfo database file using curl if API key is defined
  64. - name: Fetch DB from ipinfo.io
  65. # IPINFO_APIKEY is set in https://github.com/librespeed/speedtest/settings/secrets/actions
  66. run: |
  67. if [ -z "${{ secrets.IPINFO_APIKEY }}" ]; then
  68. echo "Warning: IPINFO_APIKEY is not defined."
  69. else
  70. curl -L https://ipinfo.io/data/free/country_asn.mmdb?token=${{ secrets.IPINFO_APIKEY }} -o backend/country_asn.mmdb
  71. fi
  72. # Set up QEMU for multi-arch builds
  73. - name: Set up QEMU
  74. uses: docker/setup-qemu-action@v4
  75. # Set up BuildKit Docker container builder to be able to build
  76. # multi-platform images and export cache
  77. # https://github.com/docker/setup-buildx-action
  78. - name: Set up Docker Buildx
  79. uses: docker/setup-buildx-action@v4
  80. # Login against a Docker registry except on PR
  81. # https://github.com/docker/login-action
  82. - name: Log into registry ${{ env.REGISTRY }}
  83. if: github.event_name != 'pull_request'
  84. uses: docker/login-action@v4
  85. with:
  86. registry: ${{ env.REGISTRY }}
  87. username: ${{ github.actor }}
  88. password: ${{ secrets.GITHUB_TOKEN }}
  89. # Extract metadata (tags, labels) for Docker
  90. # https://github.com/docker/metadata-action
  91. - name: Extract Docker metadata
  92. id: meta
  93. uses: docker/metadata-action@v6
  94. with:
  95. images: ${{ matrix.image }}
  96. tags: |
  97. type=ref,event=branch,suffix=${{ matrix.flavour }}
  98. type=ref,event=pr,suffix=${{ matrix.flavour }}
  99. # set latest tag for default branch
  100. type=raw,value=latest${{ matrix.flavour }},enable={{is_default_branch}}
  101. type=semver,pattern={{version}}${{ matrix.flavour }}
  102. type=semver,pattern={{major}}${{ matrix.flavour }}
  103. type=semver,pattern={{major}}.{{minor}}${{ matrix.flavour }}
  104. type=semver,pattern={{major}}.{{minor}}.{{patch}}${{ matrix.flavour }}
  105. # Build and push Docker image with Buildx (don't push on PR)
  106. # https://github.com/docker/build-push-action
  107. - name: Build and push Docker image
  108. id: build-and-push
  109. uses: docker/build-push-action@v7
  110. with:
  111. context: .
  112. file: ${{ matrix.dockerfile }}
  113. platforms: linux/amd64,linux/arm64,linux/arm/v7
  114. push: ${{ github.event_name != 'pull_request' }}
  115. tags: ${{ steps.meta.outputs.tags }}
  116. labels: ${{ steps.meta.outputs.labels }}
  117. cache-from: type=gha
  118. cache-to: type=gha,mode=max