docker-publish.yml 4.7 KB

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