From 10a18bf4bca6be1d2ab8c3c5ca17b51df527c941 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Mon, 14 Oct 2024 12:17:53 +0200 Subject: [PATCH] ci(release): implement akash deployment refs #345 --- .github/workflows/deploy-to-akash.yml | 124 +++++++++++++++++++++++++ .github/workflows/release-all-apps.yml | 43 ++++++++- apps/api/{deploy.yml => deploy.yaml} | 12 +-- 3 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/deploy-to-akash.yml rename apps/api/{deploy.yml => deploy.yaml} (86%) diff --git a/.github/workflows/deploy-to-akash.yml b/.github/workflows/deploy-to-akash.yml new file mode 100644 index 000000000..da72b44cd --- /dev/null +++ b/.github/workflows/deploy-to-akash.yml @@ -0,0 +1,124 @@ +name: Deploy to Akash + +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy' + required: true + type: string + +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 }}/${{ inputs.project-path }}/deploy-parsed.yaml + PROVIDER: ${{inputs.provider}} + SQL_PROXY_AUTH_TOKEN: ${{secrets.SQL_PROXY_AUTH_TOKEN}} + +jobs: + define-vars: + name: Define Variables + runs-on: ubuntu-latest + + permissions: + contents: write + packages: write + + outputs: + app: ${{ steps.vars.outputs.app }} + image: ${{ steps.vars.outputs.image }} + workspace: ${{ steps.vars.outputs.workspace }} + steps: + - name: Set app name + id: vars + env: + API_REGISTRY: ${{ vars.API_REGISTRY }} + WEB_REGISTRY: ${{ vars.WEB_REGISTRY }} + run: | + API_WORKSPACE="apps/api" + WEB_WORKSPACE="apps/deploy-web" + + FULL_TAG="${{ github.event.inputs.tag }}" + IFS='/' read -r scope version <<< "$FULL_TAG" + prerelease_type=$(echo "$version" | sed -n 's/.*-\([a-zA-Z]*\).*/\1/p') + app="${scope#console-}" + + registry_var="$(echo "$app" | tr '[:lower:]' '[:upper:]')_REGISTRY" + registry="${!registry_var}" + + workspace_var="$(echo "$app" | tr '[:lower:]' '[:upper:]')_WORKSPACE" + workspace="${!workspace_var}" + + app="${scope#console-}-${prerelease_type:-stable}" + version="${version#v}" + image="$registry:$version" + + echo "workspace=${workspace}" + echo "app=${app}" + echo "image=${image}" + + echo "workspace=${workspace}" >> $GITHUB_OUTPUT + echo "app=${app}" >> $GITHUB_OUTPUT + echo "image=${image}" >> $GITHUB_OUTPUT + + deploy-sandbox: + needs: define-vars + runs-on: ubuntu-latest + steps: + - name: Deploy Sandbox + uses: akash-network/akash-deploy-action/.github/actions/deploy@main + env: + DOPPLER_TOKEN: ${{ secrets.DOPPLER_API_STAGING_SANDBOX_TOKEN }} + API_DOMAIN: ${{ vars.API_SANDBOX_STAGING_DOMAIN }} + with: + project-path: ${{ needs.define-vars.outputs.workspace }} + project-name: ${{ needs.define-vars.outputs.app }}-sandbox + image: ${{ needs.define-vars.outputs.image }} + provider: ${{ vars.AKASH_PROVIDER }} + seed: ${{ secrets.WALLET_MNEMONIC }} + password: ${{ secrets.WALLET_PASSWORD }} + github-author-email: "developer@akash.network" + github-author-name: "Akash Network Team" + github-token: ${{ secrets.GITHUB_TOKEN }} + + deploy-mainnet: + needs: [define-vars,deploy-sandbox] + runs-on: ubuntu-latest + steps: + - name: Deploy Mainnet + uses: akash-network/akash-deploy-action/.github/actions/deploy@main + env: + DOPPLER_TOKEN: ${{ secrets.DOPPLER_API_STAGING_MAINNET_TOKEN }} + API_DOMAIN: ${{ vars.API_MAINNET_STAGING_DOMAIN }} + with: + project-path: ${{ needs.define-vars.outputs.workspace }} + project-name: ${{ needs.define-vars.outputs.app }}-mainnet + image: ${{ needs.define-vars.outputs.image }} + provider: ${{ vars.AKASH_PROVIDER }} + password: ${{ secrets.WALLET_PASSWORD }} + seed: ${{ secrets.WALLET_MNEMONIC }} + github-author-email: "developer@akash.network" + github-author-name: "Akash Network Team" + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-all-apps.yml b/.github/workflows/release-all-apps.yml index 72ddc2fee..1c9375d6e 100644 --- a/.github/workflows/release-all-apps.yml +++ b/.github/workflows/release-all-apps.yml @@ -44,7 +44,11 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build the Docker images + - name: Get the latest tag + id: latest_tag + run: echo "value=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT + + - name: Generate releases and build docker images env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -52,3 +56,40 @@ jobs: git config --global user.name "Akash Network Team" npm run release -w apps/api -- --preRelease=beta --verbose --ci -r ${{ vars.API_REGISTRY }} npm run release -w apps/deploy-web -- --preRelease=beta -f --verbose --ci -r ${{ vars.WEB_REGISTRY }} + + - name: Trigger Akash deployment + run: | + latest_tag=${{ steps.latest_tag.outputs.value }} + if [ -z "$latest_tag" ]; then + echo "No latest tag found. Iterating over all tags." + tags=$(git tag --sort=-creatordate --merged) + else + echo "Latest tag found: $latest_tag. Iterating over tags since latest tag." + tags=$(git tag --sort=-creatordate --merged | grep -v "$latest_tag") + fi + + DEPLOYABLE_TAGS=("console-api") + tags_to_deploy="" + + for tag in $tags; do + for deployable_tag in "${DEPLOYABLE_TAGS[@]}"; do + if [[ $tag == $deployable_tag* ]]; then + echo "Adding tag to deploy: $tag" + tags_to_deploy="$tags_to_deploy $tag" + fi + done + done + + if [ -n "$tags_to_deploy" ]; then + for tag in $tags_to_deploy; do + echo "Dispatching deploy workflow for: $tag" + curl -X POST \ + -H "Authorization: token ${{ secrets.AKASH_GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/actions/workflows/deploy-to-akash.yml/dispatches \ + -d "{\"ref\": \"main\", \"inputs\": { \"tag\": \"$tag\" }}" + done + else + echo "No tags to deploy." + fi + 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: