1
0

docker-publish.yml 4.2 KB

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