From 12d90cc18419a4cc5eb7610729ded1e7b6d7ee55 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Mon, 14 Oct 2024 12:17:53 +0200 Subject: [PATCH] ci(release): implement api deploy to akash refs #345 --- .github/workflows/deploy-api-to-akash.yml | 107 ++++++++++++++++++++++ .github/workflows/release-all-apps.yml | 7 +- apps/api/{deploy.yml => deploy.yaml} | 12 +-- packages/docker/script/build.sh | 10 +- 4 files changed, 122 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/deploy-api-to-akash.yml rename apps/api/{deploy.yml => deploy.yaml} (86%) diff --git a/.github/workflows/deploy-api-to-akash.yml b/.github/workflows/deploy-api-to-akash.yml new file mode 100644 index 000000000..6b8b9e1bd --- /dev/null +++ b/.github/workflows/deploy-api-to-akash.yml @@ -0,0 +1,107 @@ +name: Deploy Beta API to Akash + +on: + push: + tags: + - console-api/v[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+ + +concurrency: + group: ${{ github.workflow }} + +env: + ORG: akash-network + REPO: provider + CLIENT: provider-services + CLIENT_VERSION: 0.6.4 + ARCH: linux_amd64 + NET: mainnet + BLOCK_TIME: 1s + CHAIN_LATENCY: 30 + AKASH_KEYRING_BACKEND: file + AKASH_BROADCAST_MODE: block + AKASH_YES: 1 + AKASH_GAS_PRICES: 0.025uakt + AKASH_GAS: auto + AKASH_GAS_ADJUSTMENT: 1.5 + AKASH_HOME: /home/runner/.akash + AKASH_FROM: default + AKASH_OUTPUT: json + MIN_BALANCE: 10 + AKASH_GSEQ: 1 + AKASH_OSEQ: 1 + SDL: deploy.yaml + PARSED_SDL: ${{ github.workspace }}/${{ github.event.inputs.project-path }}/deploy-parsed.yaml + PROVIDER: ${{ secrets.AKASH_PROVIDER }} + AKASH_PROVIDER: ${{secrets.AKASH_PROVIDER}} + + SQL_PROXY_AUTH_TOKEN: ${{secrets.SQL_PROXY_AUTH_TOKEN}} + +jobs: + define-vars: + name: Define Variables + runs-on: ubuntu-latest + + outputs: + app: ${{ steps.vars.outputs.app }} + image: ${{ steps.vars.outputs.image }} + + steps: + - name: Define common variables + id: vars + run: | + ref="${{ github.event.ref }}" + tag="${ref#refs/tags/}" + prerelease_type=$(echo "$tag" | sed -n 's/.*-\([a-zA-Z]*\).*/\1/p') + app="api-${prerelease_type:-prod}" + version="${tag#console-api/v}" + image="${{ vars.API_REGISTRY }}:$version" + + echo "app=${app}" + echo "image=${image}" + + echo "app=${app}" >> $GITHUB_OUTPUT + echo "image=${image}" >> $GITHUB_OUTPUT + + deploy-sandbox: + name: Deploy Sandbox + needs: define-vars + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Deploy + uses: akash-network/akash-deploy-action/.github/actions/deploy@action + env: + DOPPLER_TOKEN: ${{ secrets.DOPPLER_API_STAGING_SANDBOX_TOKEN }} + API_DOMAIN: ${{ vars.API_SANDBOX_STAGING_DOMAIN }} + AKASH_DSEQ: ${{ secrets.API_BETA_SANDBOX_AKASH_DSEQ }} + with: + project-path: apps/api + project-name: ${{ needs.define-vars.outputs.app }}-sandbox + image: ${{ needs.define-vars.outputs.image }} + seed: ${{ secrets.WALLET_MNEMONIC }} + password: ${{ secrets.WALLET_PASSWORD }} + + deploy-mainnet: + name: Deploy Mainnet + needs: [define-vars, deploy-sandbox] + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Deploy + uses: akash-network/akash-deploy-action/.github/actions/deploy@action + env: + DOPPLER_TOKEN: ${{ secrets.DOPPLER_API_STAGING_MAINNET_TOKEN }} + API_DOMAIN: ${{ vars.API_MAINNET_STAGING_DOMAIN }} + AKASH_DSEQ: ${{ secrets.API_BETA_MAINNET_AKASH_DSEQ }} + with: + project-path: apps/api + project-name: ${{ needs.define-vars.outputs.app }}-mainnet + image: ${{ needs.define-vars.outputs.image }} + password: ${{ secrets.WALLET_PASSWORD }} + seed: ${{ secrets.WALLET_MNEMONIC }} diff --git a/.github/workflows/release-all-apps.yml b/.github/workflows/release-all-apps.yml index dc8ea89ef..a35876e8d 100644 --- a/.github/workflows/release-all-apps.yml +++ b/.github/workflows/release-all-apps.yml @@ -9,7 +9,8 @@ concurrency: cancel-in-progress: true jobs: - build: + release: + name: Release runs-on: ubuntu-latest permissions: contents: write @@ -44,9 +45,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build the Docker images + - name: Generate releases and build docker images env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.AKASH_GITHUB_TOKEN }} run: | git config --global user.email "ci@akash.network" git config --global user.name "CI" diff --git a/apps/api/deploy.yml b/apps/api/deploy.yaml similarity index 86% rename from apps/api/deploy.yml rename to apps/api/deploy.yaml index 0f632041c..986b95aeb 100644 --- a/apps/api/deploy.yml +++ b/apps/api/deploy.yaml @@ -3,16 +3,16 @@ version: "2.0" services: api: - image: : + image: {{IMAGE_NAME}} depends-on: cloud-sql-proxy env: - - DOPPLER_TOKEN= - - SENTRY_SERVER_NAME= + - DOPPLER_TOKEN={{DOPPLER_TOKEN}} + - SENTRY_SERVER_NAME=akash expose: - port: 3080 as: 80 accept: - - console-api-sandbox-staging.akash.network + - {{API_DOMAIN}} to: - global: true cloud-sql-proxy: @@ -20,7 +20,7 @@ services: env: - KeyPath=/custom/proxy_key.json - ConnectionName=cloudmos-explorer:us-central1:cloudmos-postgresql - - Token= + - Token={{SQL_PROXY_AUTH_TOKEN}} command: - "sh" - "-c" @@ -47,7 +47,7 @@ profiles: cpu: units: 0.5 memory: - size: 512mi + size: 512Mi storage: size: 2Gi placement: diff --git a/packages/docker/script/build.sh b/packages/docker/script/build.sh index b4d9999c3..36066761c 100755 --- a/packages/docker/script/build.sh +++ b/packages/docker/script/build.sh @@ -64,11 +64,11 @@ commits=$(git log -n 10 --pretty=format:"%H %s" -- "$(git rev-parse --show-tople while IFS= read -r commit; do MESSAGE=$(echo $commit | cut -d' ' -f2-) - if [[ ! $MESSAGE =~ ^chore\(release\):\ released\ version ]]; then - echo "Base commit: $commit" - SHA=$(echo $commit | awk '{print $1}') - break - fi +if [[ ! $MESSAGE =~ ^chore\(release\):\ released\ version && ! $MESSAGE =~ ^chore\(deploy\):\ update\ deployment\ state ]]; then + echo "Base commit: $commit" + SHA=$(echo $commit | awk '{print $1}') + break +fi done <<< "$commits" SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")"