docker_publish.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. name: Publish docker image
  2. on:
  3. schedule:
  4. - cron: "0 3 * * *" # At 03:00 every day
  5. workflow_dispatch:
  6. inputs:
  7. git_ref:
  8. type: string
  9. required: true
  10. default: main
  11. description: "Git branch/tag revision to build"
  12. dockerfile_branch:
  13. type: string
  14. required: true
  15. default: main
  16. description: "Git branch for getting Dockerfile"
  17. image_tag:
  18. type: string
  19. required: true
  20. default: trunk
  21. description: "docker image tag"
  22. jobs:
  23. build:
  24. runs-on: [self-hosted, auto-provisioned]
  25. steps:
  26. - name: Checkout .github
  27. uses: actions/checkout@v4
  28. with:
  29. ref: ${{ inputs.dockerfile_branch || 'main' }}
  30. path: main
  31. sparse-checkout: |
  32. .github
  33. - name: Checkout
  34. uses: actions/checkout@v4
  35. with:
  36. ref: ${{ inputs.git_ref || 'main' }}
  37. path: ydb
  38. - name: get revision
  39. shell: bash
  40. id: get-sha
  41. working-directory: ydb
  42. run: |
  43. echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
  44. - name: Set up Docker buildx
  45. uses: docker/setup-buildx-action@v2
  46. - name: Log in to the Container registry
  47. uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
  48. with:
  49. registry: ghcr.io
  50. username: ${{ github.actor }}
  51. password: ${{ secrets.GITHUB_TOKEN }}
  52. - name: Log in to the Docker Hub
  53. uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
  54. with:
  55. username: ${{ vars.DOCKER_HUB_USER_NAME }}
  56. password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
  57. - name: Docker meta
  58. id: meta
  59. uses: docker/metadata-action@v4
  60. with:
  61. images: |
  62. ghcr.io/${{ github.repository_owner }}/local-ydb
  63. ${{ vars.DOCKER_HUB_REPOSITORY && vars.DOCKER_HUB_REPOSITORY || '' }}
  64. labels: |
  65. ydb.revision=${{ steps.get-sha.outputs.SHA }}
  66. org.opencontainers.image.revision=${{ steps.get-sha.outputs.SHA }}
  67. tags: |
  68. type=schedule,pattern=nightly
  69. type=raw,value=${{ inputs.image_tag || 'trunk' }}
  70. - name: Build docker image
  71. uses: docker/build-push-action@v4
  72. with:
  73. context: .
  74. file: main/.github/docker/Dockerfile
  75. load: true
  76. tags: ${{ steps.meta.outputs.tags }}
  77. labels: ${{ steps.meta.outputs.labels }}
  78. platforms: linux/amd64
  79. provenance: false
  80. cache-from: type=s3,name=local_ydb,region=ru-central1,bucket=${{ vars.AWS_BUCKET }},endpoint_url=${{ vars.AWS_ENDPOINT }},access_key_id=${{ secrets.AWS_KEY_ID }},secret_access_key=${{ secrets.AWS_KEY_VALUE }}
  81. cache-to: type=s3,name=local_ydb,region=ru-central1,bucket=${{ vars.AWS_BUCKET }},endpoint_url=${{ vars.AWS_ENDPOINT }},access_key_id=${{ secrets.AWS_KEY_ID }},secret_access_key=${{ secrets.AWS_KEY_VALUE }},mode=max
  82. - name: Test docker image
  83. continue-on-error: false
  84. run: |
  85. docker run -d --rm --name local-ydb-test ghcr.io/${{ github.repository_owner }}/local-ydb:${{ inputs.image_tag || 'trunk' }}
  86. sleep 61 # Wait for the health check to run (--start-period=60s --interval=1s)
  87. if [ "$(docker inspect --format='{{json .State.Health.Status}}' local-ydb-test)" != "\"healthy\"" ]; then
  88. echo "Container is not healthy"
  89. docker inspect --format='{{json .State.Health}}' local-ydb-test
  90. docker logs local-ydb-test
  91. exit 1
  92. fi
  93. docker stop local-ydb-test || true
  94. - name: Push docker image
  95. uses: docker/build-push-action@v4
  96. with:
  97. context: .
  98. file: main/.github/docker/Dockerfile
  99. push: true
  100. tags: ${{ steps.meta.outputs.tags }}
  101. labels: ${{ steps.meta.outputs.labels }}
  102. platforms: linux/amd64
  103. provenance: false
  104. cache-from: type=s3,name=local_ydb,region=ru-central1,bucket=${{ vars.AWS_BUCKET }},endpoint_url=${{ vars.AWS_ENDPOINT }},access_key_id=${{ secrets.AWS_KEY_ID }},secret_access_key=${{ secrets.AWS_KEY_VALUE }}
  105. cache-to: type=s3,name=local_ydb,region=ru-central1,bucket=${{ vars.AWS_BUCKET }},endpoint_url=${{ vars.AWS_ENDPOINT }},access_key_id=${{ secrets.AWS_KEY_ID }},secret_access_key=${{ secrets.AWS_KEY_VALUE }},mode=max