From 0ad4a5b0ce582a74c4019253066b0cd2115c6814 Mon Sep 17 00:00:00 2001 From: Nikita Andriyanov Date: Thu, 17 Apr 2025 16:08:41 +0300 Subject: [PATCH] hack --- .gitea/actions/deploy/action.yaml | 59 +++++++++++++++++++++++++++++++ .github/workflows/deploy.yaml | 50 ++++---------------------- 2 files changed, 65 insertions(+), 44 deletions(-) create mode 100644 .gitea/actions/deploy/action.yaml diff --git a/.gitea/actions/deploy/action.yaml b/.gitea/actions/deploy/action.yaml new file mode 100644 index 0000000..ecb301c --- /dev/null +++ b/.gitea/actions/deploy/action.yaml @@ -0,0 +1,59 @@ +name: 'deploy' +description: 'deploy' + +inputs: + environment: + required: true + type: string + tag: + required: true + type: string + migrate: + type: bool + default: false + secrets: + required: false + type: string + +runs: + using: 'composite' + steps: + - name: Checkout + uses: actions/checkout@master + - name: Yandex Cloud Login + uses: yc-actions/yc-cr-login@v2 + with: + yc-sa-json-credentials: ${{ fromJSON(inputs.secrets).YC_SA_JSON_CREDENTIALS }} + - name: Import Secrets + uses: hashicorp/vault-action@v2 + id: vault + with: + url: https://vault.hublab.ru/ + method: approle + roleId: ${{ fromJSON(inputs.secrets).VAULT_ROLE_ID }} + secretId: ${{ fromJSON(inputs.secrets).VAULT_SECRET_ID }} + secrets: | + hub/data/tach/${{ inputs.environment }}/base *; + hub/data/tach/${{ inputs.environment }}/${{github.event.repository.name}} *; + - name: Save envs + run: | + echo '${{ toJson(steps.vault.outputs) }}' > output.json + jq -r 'to_entries[] | "\(.key)=\"\(.value)\""' output.json > .env + source .env + cat .env + - name: Pull + env: + DOCKER_HOST: tcp://${{ inputs.host }}:2376 + run: | + docker compose pull + - name: Migrate + if: ${{ inputs.migrate == 'true' }} + env: + DOCKER_HOST: tcp://${{ inputs.host }}:2376 + run: | + docker compose run --rm ${CR_REPO:8} alembic upgrade head + - name: Deploy + env: + DOCKER_HOST: tcp://${{ inputs.host }}:2376 + run: | + docker compose -p ${{ inputs.environment }} up -d --force-recreate \ No newline at end of file diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index b7fcbe6..6bebc54 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -30,48 +30,10 @@ jobs: CR_REPO: ${{ github.event.repository.name }} TAG: ${{ inputs.tag }} steps: - - name: Checkout - uses: actions/checkout@master - - name: Yandex Cloud Login - uses: yc-actions/yc-cr-login@v2 + - name: deploy + uses: https://bb.hublab.ru/HUB/workflows/.gitea/actions/deploy@HEAD with: - yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }} - - name: Import Secrets - uses: hashicorp/vault-action@v2 - id: vault - with: - url: https://vault.hublab.ru/ - method: approle - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - secrets: | - hub/data/tach/${{ inputs.environment }}/base *; - hub/data/tach/${{ inputs.environment }}/${{github.event.repository.name}} *; - - name: Save envs - run: | - echo '${{ toJson(steps.vault.outputs) }}' > output.json - jq -r 'to_entries[] | "\(.key)=\"\(.value)\""' output.json > .env - source .env - cat .env - - name: Pull - env: - DOCKER_HOST: tcp://${{ inputs.host }}:2376 - run: | - docker compose pull - - name: Migrate - if: ${{ inputs.migrate == 'true' }} - env: - DOCKER_HOST: tcp://${{ inputs.host }}:2376 - run: | - docker compose run --rm ${CR_REPO:8} alembic upgrade head - - name: Build - if: ${{ inputs.build == 'true' }} - env: - DOCKER_HOST: tcp://${{ inputs.host }}:2376 - run: | - docker compose build - - name: Deploy - env: - DOCKER_HOST: tcp://${{ inputs.host }}:2376 - run: | - docker compose -p ${{ inputs.environment }} up -d --force-recreate \ No newline at end of file + secrets: ${{ toJSON(secrets) }} + environment: ${{ inputs.environment }} + tag: ${{ inputs.tag }} + migrate: ${{ inputs.migrate }} \ No newline at end of file