docker.yml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. name: Build Docker image
  2. on:
  3. workflow_dispatch:
  4. push:
  5. branches:
  6. - '**'
  7. tags:
  8. - 'v*'
  9. # pull_request:
  10. env:
  11. DOCKER_IMAGE: archivebox-ci
  12. jobs:
  13. buildx:
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Checkout
  17. uses: actions/checkout@v4
  18. with:
  19. submodules: true
  20. fetch-depth: 1
  21. - name: Set up QEMU
  22. uses: docker/setup-qemu-action@v3
  23. - name: Set up Docker Buildx
  24. id: buildx
  25. uses: docker/setup-buildx-action@v3
  26. with:
  27. version: latest
  28. install: true
  29. platforms: linux/amd64,linux/arm64,linux/arm/v7
  30. - name: Builder instance name
  31. run: echo ${{ steps.buildx.outputs.name }}
  32. - name: Available platforms
  33. run: echo ${{ steps.buildx.outputs.platforms }}
  34. - name: Cache Docker layers
  35. uses: actions/cache@v3
  36. with:
  37. path: /tmp/.buildx-cache
  38. key: ${{ runner.os }}-buildx-${{ github.sha }}
  39. restore-keys: |
  40. ${{ runner.os }}-buildx-
  41. - name: Docker Login
  42. uses: docker/login-action@v3
  43. if: github.event_name != 'pull_request'
  44. with:
  45. username: ${{ secrets.DOCKER_USERNAME }}
  46. password: ${{ secrets.DOCKER_PASSWORD }}
  47. - name: Collect Docker tags
  48. id: docker_meta
  49. uses: docker/metadata-action@v5
  50. with:
  51. images: archivebox/archivebox,nikisweeting/archivebox
  52. tags: |
  53. type=ref,event=branch
  54. type=semver,pattern={{version}}
  55. type=semver,pattern={{major}}.{{minor}}
  56. type=sha
  57. type=raw,value=latest,enable={{is_default_branch}}
  58. - name: Build and push
  59. id: docker_build
  60. uses: docker/build-push-action@v5
  61. with:
  62. context: ./
  63. file: ./Dockerfile
  64. builder: ${{ steps.buildx.outputs.name }}
  65. push: ${{ github.event_name != 'pull_request' }}
  66. tags: ${{ steps.docker_meta.outputs.tags }}
  67. cache-from: type=local,src=/tmp/.buildx-cache
  68. cache-to: type=local,dest=/tmp/.buildx-cache-new
  69. platforms: linux/amd64,linux/arm64,linux/arm/v7
  70. - name: Image digest
  71. run: echo ${{ steps.docker_build.outputs.digest }}
  72. # This ugly bit is necessary if you don't want your cache to grow forever
  73. # until it hits GitHub's limit of 5GB.
  74. # Temp fix
  75. # https://github.com/docker/build-push-action/issues/252
  76. # https://github.com/moby/buildkit/issues/1896
  77. - name: Move cache
  78. run: |
  79. rm -rf /tmp/.buildx-cache
  80. mv /tmp/.buildx-cache-new /tmp/.buildx-cache