docker_publish.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/sha revision to build"
  12. image_tag:
  13. type: string
  14. required: true
  15. default: trunk
  16. description: "docker image tag"
  17. jobs:
  18. provide-runner:
  19. name: Start self-hosted YC runner
  20. timeout-minutes: 5
  21. runs-on: ubuntu-latest
  22. outputs:
  23. label: ${{steps.start-yc-runner.outputs.label}}
  24. instance-id: ${{steps.start-yc-runner.outputs.instance-id}}
  25. steps:
  26. - name: Start YC runner
  27. id: start-yc-runner
  28. uses: yc-actions/yc-github-runner@v1
  29. with:
  30. mode: start
  31. yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
  32. github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  33. folder-id: ${{secrets.YC_FOLDER}}
  34. image-id: fd8earpjmhevh8h6ug5o # TODO: create constant
  35. disk-size: ${{vars.DISK_SIZE && vars.DISK_SIZE || '1023GB'}}
  36. disk-type: network-ssd-nonreplicated
  37. cores: 32
  38. memory: 64GB
  39. core-fraction: 100
  40. zone-id: ru-central1-b
  41. subnet-id: ${{secrets.YC_SUBNET}}
  42. prepare-vm:
  43. name: Prepare runner
  44. needs: provide-runner
  45. runs-on: [ self-hosted, "${{ needs.provide-runner.outputs.label }}" ]
  46. steps:
  47. - name: Checkout PR
  48. uses: actions/checkout@v3
  49. with:
  50. sparse-checkout: .github
  51. - name: install docker
  52. shell: bash
  53. run: |
  54. apt-get update
  55. apt-get install -y --no-install-recommends docker.io
  56. build:
  57. needs:
  58. - provide-runner
  59. - prepare-vm
  60. runs-on: "${{ needs.provide-runner.outputs.label }}"
  61. steps:
  62. - name: Checkout
  63. uses: actions/checkout@v3
  64. with:
  65. sparse-checkout: .github
  66. - name: Set up Docker Buildx
  67. uses: docker/setup-buildx-action@v2
  68. - name: Log in to the Container registry
  69. uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
  70. with:
  71. registry: ghcr.io
  72. username: ${{ github.actor }}
  73. password: ${{ secrets.GITHUB_TOKEN }}
  74. - name: Build and push docker image
  75. uses: docker/build-push-action@v4
  76. with:
  77. push: true
  78. context: .github/docker/
  79. file: .github/docker/Dockerfile
  80. tags: ghcr.io/${{ github.repository_owner }}/local-ydb:${{ inputs.image_tag || 'trunk' }}
  81. platforms: linux/amd64
  82. provenance: false
  83. build-args: |
  84. GIT_REPO=${{ github.server_url }}/${{ github.repository }}
  85. GIT_REF=${{ inputs.git_ref || 'main' }}
  86. secrets: |
  87. "ccache_remote_storage=${{ vars.REMOTE_CACHE_URL && format('http://{0}{1}', secrets.REMOTE_CACHE_AUTH, vars.REMOTE_CACHE_URL) || ''}}"
  88. release-runner:
  89. name: Release self-hosted YC runner if provided on-demand
  90. needs:
  91. - provide-runner
  92. - build
  93. runs-on: ubuntu-latest
  94. if: always()
  95. steps:
  96. - name: Stop YC runner
  97. uses: yc-actions/yc-github-runner@v1
  98. with:
  99. mode: stop
  100. yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
  101. github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
  102. label: ${{ needs.provide-runner.outputs.label }}
  103. instance-id: ${{ needs.provide-runner.outputs.instance-id }}