From fde6d1e8aa18c48e37b0fb2170ea12198a587520 Mon Sep 17 00:00:00 2001 From: Andrey Kondratov <22258361+andrey-kondratov@users.noreply.github.com> Date: Mon, 19 Aug 2024 19:35:43 +0300 Subject: [PATCH] Consolidated workflows. --- .github/workflows/build.yml | 49 +++++++++++++++++++++++++-- .github/workflows/deploy-prod.yml | 55 ------------------------------- 2 files changed, 47 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/deploy-prod.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6cb65de..4952825 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build +name: Build and deploy on: pull_request: @@ -7,6 +7,7 @@ on: push: branches: - master + workflow_dispatch: env: out_dir: ${{ vars.OUTPUT_DIR }} @@ -23,7 +24,7 @@ jobs: run: dotnet tool restore - name: Push run: echo "${{ github.token }}" | dotnet cake --target Push --tag ${tag} - deploy: + deploy-test: needs: - build runs-on: [host, ARM64] @@ -67,4 +68,48 @@ jobs: run: | cd $out_dir docker compose up --detach --pull always --quiet-pull --remove-orphans --wait --wait-timeout 60 + deploy-prod: + runs-on: [host, ARM64] + environment: prod + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Update DockerCompose + run: | + mkdir -p $out_dir + cp src/docker-compose.yml $out_dir + cd $out_dir + + cat << EOF > docker-compose.override.yml + services: + server: + image: ghcr.io/${{ github.repository }}:${tag} + db-init: + image: ghcr.io/${{ github.repository }}:${tag} + EOF + + cat << EOF > server.env + DOTNET_ENVIRONMENT: Development + PILLSBOT__TELEGRAM__APITOKEN: ${{ secrets.PILLSBOT__TELEGRAM__APITOKEN }} + PILLSBOT__TELEGRAM__CHATID: "${{ secrets.PILLSBOT__TELEGRAM__CHATID }}" + PILLSBOT__REMINDER__BEGINS: ${{ secrets.PILLSBOT__REMINDER__BEGINS }} + PILLSBOT__AI__ENABLED: ${{ vars.PILLSBOT__AI__ENABLED }} + PILLSBOT__AI__LANGUAGES: ${{ secrets.PILLSBOT__AI__LANGUAGES }} + PILLSBOT__AI__PETNAMES: ${{ secrets.PILLSBOT__AI__PETNAMES }} + PILLSBOT__AI__PETGENDER: ${{ secrets.PILLSBOT__AI__PETGENDER }} + PILLSBOT__AI__LOGLEVEL: ${{ vars.PILLSBOT__AI__LOGLEVEL }} + PILLSBOT__AI__MAXTOKENS: ${{ vars.PILLSBOT__AI__MAXTOKENS }} + PILLSBOT__AI__AZURE__ENDPOINT: ${{ secrets.PILLSBOT__AI__AZURE__ENDPOINT }} + PILLSBOT__AI__AZURE__KEY: ${{ secrets.PILLSBOT__AI__AZURE__KEY }} + PILLSBOT__AI__AZURE__DEPLOYMENTNAME: ${{ secrets.PILLSBOT__AI__AZURE__DEPLOYMENTNAME }} + APPLICATIONINSIGHTS__CONNECTIONSTRING: ${{ secrets.APPLICATIONINSIGHTS__CONNECTIONSTRING }} + POSTGRES_DB: ${{ secrets.POSTGRES_DB }} + POSTGRES_USER: ${{ secrets.POSTGRES_USER }} + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} + CONNECTIONSTRINGS__PILLSBOTDBCONTEXT: Host=db;Database=${{ secrets.POSTGRES_DB }};Username=${{ secrets.POSTGRES_USER }};Password=${{ secrets.POSTGRES_PASSWORD }} + EOF + - name: Restart + run: | + cd $out_dir + docker compose up --detach --pull always --quiet-pull --remove-orphans --wait --wait-timeout 60 diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml deleted file mode 100644 index 8b5aa65..0000000 --- a/.github/workflows/deploy-prod.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Deploy (Prod) - -on: - workflow_dispatch: - -env: - out_dir: ${{ vars.OUTPUT_DIR }} - tag: latest-arm64v8 - -jobs: - deploy: - runs-on: [host, ARM64] - environment: prod - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - name: Update DockerCompose - run: | - mkdir -p $out_dir - - cp src/docker-compose.yml $out_dir - cd $out_dir - - cat << EOF > docker-compose.override.yml - services: - server: - image: ghcr.io/${{ github.repository }}:${tag} - db-init: - image: ghcr.io/${{ github.repository }}:${tag} - EOF - - cat << EOF > server.env - DOTNET_ENVIRONMENT: Development - PILLSBOT__TELEGRAM__APITOKEN: ${{ secrets.PILLSBOT__TELEGRAM__APITOKEN }} - PILLSBOT__TELEGRAM__CHATID: "${{ secrets.PILLSBOT__TELEGRAM__CHATID }}" - PILLSBOT__REMINDER__BEGINS: ${{ secrets.PILLSBOT__REMINDER__BEGINS }} - PILLSBOT__AI__ENABLED: ${{ vars.PILLSBOT__AI__ENABLED }} - PILLSBOT__AI__LANGUAGES: ${{ secrets.PILLSBOT__AI__LANGUAGES }} - PILLSBOT__AI__PETNAMES: ${{ secrets.PILLSBOT__AI__PETNAMES }} - PILLSBOT__AI__PETGENDER: ${{ secrets.PILLSBOT__AI__PETGENDER }} - PILLSBOT__AI__LOGLEVEL: ${{ vars.PILLSBOT__AI__LOGLEVEL }} - PILLSBOT__AI__MAXTOKENS: ${{ vars.PILLSBOT__AI__MAXTOKENS }} - PILLSBOT__AI__AZURE__ENDPOINT: ${{ secrets.PILLSBOT__AI__AZURE__ENDPOINT }} - PILLSBOT__AI__AZURE__KEY: ${{ secrets.PILLSBOT__AI__AZURE__KEY }} - PILLSBOT__AI__AZURE__DEPLOYMENTNAME: ${{ secrets.PILLSBOT__AI__AZURE__DEPLOYMENTNAME }} - APPLICATIONINSIGHTS__CONNECTIONSTRING: ${{ secrets.APPLICATIONINSIGHTS__CONNECTIONSTRING }} - POSTGRES_DB: ${{ secrets.POSTGRES_DB }} - POSTGRES_USER: ${{ secrets.POSTGRES_USER }} - POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} - CONNECTIONSTRINGS__PILLSBOTDBCONTEXT: Host=db;Database=${{ secrets.POSTGRES_DB }};Username=${{ secrets.POSTGRES_USER }};Password=${{ secrets.POSTGRES_PASSWORD }} - EOF - - name: Restart - run: | - cd $out_dir - docker compose up --detach --pull always --quiet-pull --remove-orphans --wait --wait-timeout 60