Skip to content

Commit

Permalink
ci(release): implement api deploy to akash
Browse files Browse the repository at this point in the history
refs #345
  • Loading branch information
ygrishajev committed Oct 17, 2024
1 parent 498df40 commit 866a4cc
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 13 deletions.
111 changes: 111 additions & 0 deletions .github/workflows/deploy-api-to-akash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Deploy API 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 }}/${{ 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: |
tag=${{ github.event.inputs.tag }}
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
with:
ref: main

- name: Deploy
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 }}
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@main
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 }}
30 changes: 28 additions & 2 deletions .github/workflows/release-all-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ concurrency:
cancel-in-progress: true

jobs:
build:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -44,11 +45,36 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the Docker images
- name: Get the latest tag
id: latest_tag
run: |
output="value=$(git describe --tags --abbrev=0)"
echo $output
echo $output >> $GITHUB_OUTPUT
- name: Generate releases and build docker images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "CI"
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 deployments
run: |
latest_tag=${{ steps.latest_tag.outputs.value }}
api_tags=$(git tag --sort=-creatordate --merged | grep '^console-api/v')
new_api_tag=$(echo "$api_tags" | awk -v latest="$latest_tag" '$0 > latest' | head -n 1)
if [ -z "$new_api_tag" ]; then
echo "No new console-api tag found. Skipping api deployment."
else
echo "Dispatching deploy workflow for: $new_api_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-api-to-akash.yml/dispatches \
-d "{\"ref\": \"main\", \"inputs\": { \"tag\": \"$new_api_tag\" }}"
fi
12 changes: 6 additions & 6 deletions apps/api/deploy.yml → apps/api/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ version: "2.0"

services:
api:
image: <IMAGE_NAME>:<IMAGE_TAG>
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:
image: redm4x/cloud-sql-proxy:1.31.2
env:
- KeyPath=/custom/proxy_key.json
- ConnectionName=cloudmos-explorer:us-central1:cloudmos-postgresql
- Token=<AUTH>
- Token={{SQL_PROXY_AUTH_TOKEN}}
command:
- "sh"
- "-c"
Expand All @@ -47,7 +47,7 @@ profiles:
cpu:
units: 0.5
memory:
size: 512mi
size: 512Mi
storage:
size: 2Gi
placement:
Expand Down
10 changes: 5 additions & 5 deletions packages/docker/script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")")"
Expand Down

0 comments on commit 866a4cc

Please sign in to comment.