docker_publish.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. name: Publish docker image
  2. on:
  3. schedule:
  4. - cron: "0 3 * * *"
  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. image_tag:
  13. type: string
  14. required: true
  15. default: trunk
  16. description: "docker image tag"
  17. local_ydb_ref:
  18. type: string
  19. required: true
  20. default: main
  21. description: "Git branch/tag revision to builld local_ydb"
  22. jobs:
  23. provide-runner:
  24. name: Start self-hosted YC runner
  25. timeout-minutes: 5
  26. runs-on: ubuntu-latest
  27. outputs:
  28. label: ${{steps.start-yc-runner.outputs.label}}
  29. instance-id: ${{steps.start-yc-runner.outputs.instance-id}}
  30. steps:
  31. - name: Start YC runner
  32. id: start-yc-runner
  33. uses: yc-actions/yc-github-runner@v1
  34. with:
  35. mode: start
  36. yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
  37. github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  38. folder-id: ${{secrets.YC_FOLDER}}
  39. image-id: fd8earpjmhevh8h6ug5o # TODO: create constant
  40. disk-size: ${{vars.DISK_SIZE && vars.DISK_SIZE || '1023GB'}}
  41. disk-type: network-ssd-nonreplicated
  42. cores: 32
  43. memory: 64GB
  44. core-fraction: 100
  45. zone-id: ru-central1-b
  46. subnet-id: ${{secrets.YC_SUBNET}}
  47. prepare-vm:
  48. name: Prepare runner
  49. needs: provide-runner
  50. runs-on: [ self-hosted, "${{ needs.provide-runner.outputs.label }}" ]
  51. steps:
  52. - name: install docker
  53. shell: bash
  54. run: |
  55. apt-get update
  56. apt-get install -y --no-install-recommends docker.io
  57. build:
  58. needs:
  59. - provide-runner
  60. - prepare-vm
  61. runs-on: "${{ needs.provide-runner.outputs.label }}"
  62. steps:
  63. - name: Checkout .github and local_ydb
  64. uses: actions/checkout@v4
  65. with:
  66. ref: main
  67. path: main
  68. sparse-checkout: |
  69. .github
  70. ydb/public/tools/local_ydb/
  71. - name: Checkout
  72. uses: actions/checkout@v4
  73. with:
  74. ref: ${{ inputs.git_ref || 'main' }}
  75. path: ydb
  76. - name: get revision
  77. shell: bash
  78. id: get-sha
  79. working-directory: ydb
  80. run: |
  81. echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
  82. - name: Set up Docker Buildx
  83. uses: docker/setup-buildx-action@v2
  84. - name: Log in to the Container registry
  85. uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
  86. with:
  87. registry: ghcr.io
  88. username: ${{ github.actor }}
  89. password: ${{ secrets.GITHUB_TOKEN }}
  90. - name: Docker meta
  91. id: meta
  92. uses: docker/metadata-action@v4
  93. with:
  94. images: |
  95. ghcr.io/${{ github.repository_owner }}/local-ydb
  96. labels: |
  97. ydb.revision=${{ steps.get-sha.outputs.SHA }}
  98. org.opencontainers.image.revision=${{ steps.get-sha.outputs.SHA }}
  99. tags: |
  100. type=schedule,pattern=nightly
  101. type=raw,value=${{ inputs.image_tag || 'trunk' }}
  102. - name: Build and push docker image
  103. uses: docker/build-push-action@v4
  104. with:
  105. push: true
  106. context: .
  107. file: main/.github/docker/Dockerfile
  108. tags: ${{ steps.meta.outputs.tags }}
  109. labels: ${{ steps.meta.outputs.labels }}
  110. platforms: linux/amd64
  111. provenance: false
  112. 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 }}
  113. 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
  114. secrets: |
  115. "ccache_remote_storage=${{ vars.REMOTE_CACHE_URL && format('http://{0}{1}', secrets.REMOTE_CACHE_AUTH, vars.REMOTE_CACHE_URL) || ''}}"
  116. release-runner:
  117. name: Release self-hosted YC runner if provided on-demand
  118. needs:
  119. - provide-runner
  120. - build
  121. runs-on: ubuntu-latest
  122. if: always()
  123. steps:
  124. - name: Stop YC runner
  125. uses: yc-actions/yc-github-runner@v1
  126. with:
  127. mode: stop
  128. yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
  129. github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  130. label: ${{ needs.provide-runner.outputs.label }}
  131. instance-id: ${{ needs.provide-runner.outputs.instance-id }}