2
0

docker.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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
  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@v4
  36. with:
  37. path: /tmp/.buildx-cache
  38. key: ${{ runner.os }}-buildx-${{ github.sha }}
  39. restore-keys: |
  40. ${{ runner.os }}-buildx-
  41. - name: Login to Docker Hub
  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: Login to GitHub Container Registry
  48. uses: docker/login-action@v3
  49. with:
  50. registry: ghcr.io
  51. username: ${{ github.actor }}
  52. password: ${{ secrets.GITHUB_TOKEN }}
  53. - name: Collect Full Release Docker tags
  54. # https://github.com/docker/metadata-action
  55. id: docker_meta
  56. uses: docker/metadata-action@v5
  57. if: github.event_name == 'workflow_dispatch'
  58. with:
  59. images: archivebox/archivebox,ghcr.io/archivebox/archivebox
  60. tags: |
  61. # :stable
  62. type=ref,event=branch
  63. # :0.7.3
  64. type=semver,pattern={{version}}
  65. # :0.7
  66. type=semver,pattern={{major}}.{{minor}}
  67. # :sha-463ea54
  68. type=sha
  69. # :latest
  70. type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }}
  71. - name: Collect Non-Release Docker tags
  72. # https://github.com/docker/metadata-action
  73. id: docker_meta_non_release
  74. uses: docker/metadata-action@v5
  75. if: github.event_name != 'workflow_dispatch'
  76. with:
  77. images: archivebox/archivebox,ghcr.io/archivebox/archivebox
  78. tags: |
  79. # :stable
  80. type=ref,event=branch
  81. # :sha-463ea54
  82. type=sha
  83. - name: Build and push
  84. id: docker_build
  85. uses: docker/build-push-action@v5
  86. with:
  87. context: ./
  88. file: ./Dockerfile
  89. builder: ${{ steps.buildx.outputs.name }}
  90. push: ${{ github.event_name != 'pull_request' }}
  91. tags: ${{ github.event_name == 'workflow_dispatch' ? steps.docker_meta.outputs.tags : steps.docker_meta_non_release.outputs.tags }}
  92. labels: ${{ github.event_name == 'workflow_dispatch' ? steps.docker_meta.outputs.labels : steps.docker_meta_non_release.outputs.labels }}
  93. cache-from: type=local,src=/tmp/.buildx-cache
  94. cache-to: type=local,dest=/tmp/.buildx-cache-new
  95. platforms: linux/amd64,linux/arm64
  96. - name: Image digest
  97. run: echo ${{ steps.docker_build.outputs.digest }}
  98. - name: Update README
  99. uses: peter-evans/dockerhub-description@v4
  100. with:
  101. username: ${{ secrets.DOCKER_USERNAME }}
  102. password: ${{ secrets.DOCKER_PASSWORD }}
  103. repository: archivebox/archivebox
  104. # This ugly bit is necessary if you don't want your cache to grow forever
  105. # until it hits GitHub's limit of 5GB.
  106. # Temp fix
  107. # https://github.com/docker/build-push-action/issues/252
  108. # https://github.com/moby/buildkit/issues/1896
  109. - name: Move cache
  110. run: |
  111. rm -rf /tmp/.buildx-cache
  112. mv /tmp/.buildx-cache-new /tmp/.buildx-cache