Skip to content

Commit

Permalink
feat(release): implement release with image build
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Oct 2, 2024
1 parent b39b057 commit 4db618f
Show file tree
Hide file tree
Showing 56 changed files with 4,163 additions and 178 deletions.
5 changes: 3 additions & 2 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"billing",
"provider",
"deployment",
"certificate",
"dx"
"dx",
"release",
"certificate"
]
]
}
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/deploy-app-to-akash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Deploy to akash

on:
push:
tags:
- 'console-*/v[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+'
- 'console-*/v[0-9]+.[0-9]+.[0-9]+'

jobs:
define-vars:
name: Define Variables
runs-on: ubuntu-latest
outputs:
app: ${{ steps.vars.outputs.app }}
image: ${{ steps.vars.outputs.image }}
steps:
- name: Set app name
id: vars
run: |
API_REGISTRY="ghcr.io/akashnetwork/console-api"
WEB_REGISTRY="ghcr.io/akashnetwork/console-web"
API_WORKSPACE="apps/api"
WEB_WORKSPACE="apps/deploy-web"
FULL_TAG="${GITHUB_REF#refs/tags/}"
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}"
echo "::set-output name=workspace::$workspace"
echo "::set-output name=app::$app"
echo "::set-output name=version::$version"
echo "::set-output name=image::$image"
deploy-akash:
name: Deploy to akash
uses: ygrishajev/akash-deploy-action/.github/workflows/deploy.yml@main
with:
PROJECT_PATH: app/apps/${{ define-vars.outputs.workspace }}
project_name: ${{ define-vars.outputs.app }}
image: ${{ define-vars.outputs.image }}
secrets:
SEED: ${{ secrets.WALLET_MNEUMONIC }}
PASSWORD: ${{ secrets.WALLET_PASSWORD }}
ghcr-token: ${{ secrets.GITHUB_TOKEN }}
27 changes: 0 additions & 27 deletions .github/workflows/docker-build-deploy-web.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/docker-build-indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Build the Docker image
if: steps.filter.outputs.indexer == 'true'
run: npm run dc:build -- indexer
run: packages/docker/script/dc.sh build indexer
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-provider-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: Build the Docker image
if: steps.filter.outputs.provider-proxy == 'true'
run: npm run dc:build -- provider-proxy
run: packages/docker/script/dc.sh build provider-proxy
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-stats-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: Build the Docker image
if: steps.filter.outputs.stats-web == 'true'
run: npm run dc:build -- stats-web
run: packages/docker/script/dc.sh build stats-web
54 changes: 54 additions & 0 deletions .github/workflows/release-all-apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release All Apps

on:
push:
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.14.0

- name: Restore root node_modules cache
uses: martijnhols/actions-cache@v3
id: cache
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the Docker images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Akash Network Team"
npm run release -w apps/api -- --preRelease=beta --verbose --ci -r ${{ secrets.API_REGISTRY }}
npm run release -w apps/deploy-web -- --preRelease=beta -f --verbose --ci -r ${{ secrets.WEB_REGISTRY }}
82 changes: 82 additions & 0 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Release App

on:
workflow_dispatch:
inputs:
app:
type: choice
description: Which app to release
options:
- api
- deploy-web
required: true
release-type:
type: choice
description: Which app to release
options:
- stable
- beta
default: stable
force-build:
type: boolean
description: Rebuild the Docker image
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.14.0

- name: Restore root node_modules cache
uses: martijnhols/actions-cache@v3
id: cache
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the Docker images
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Akash Network Team"
pre_release=""
if [[ "${{ github.event.inputs.release-type }}" == 'beta' ]]; then
prerelease="--preRelease=beta"
fi
force_build=""
if [[ "${{ github.event.inputs.force-build }}" == 'true' ]]; then
force_build="-f"
fi
npm run release -w apps/${{ github.event.inputs.app }} -- $pre_release $force_build --verbose --ci -r ${{ secrets.API_REGISTRY }}
4 changes: 1 addition & 3 deletions .github/workflows/validate-n-build-api.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Validate and Build API

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

Expand Down Expand Up @@ -55,4 +53,4 @@ jobs:

- name: Build the Docker image for API
if: steps.filter.outputs.api == 'true'
run: npm run dc:build -- api
run: packages/docker/script/dc.sh build api
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [[ "$CI" != "true" ]]; then
npm run update-apps-local-deps
git add --all
fi
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [Running the Application](#running-the-application)
- [How to run](#how-to-run)
- [Database Structure](#database-structure)
- [Release Workflow](./doc/release-workflow.md)

# Quick start

Expand Down
1 change: 1 addition & 0 deletions apps/api/.release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@akashnetwork/releaser")
29 changes: 29 additions & 0 deletions apps/api/define-vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Enable debugging (prints each command as it's executed)
#set -x

API_REGISTRY="ghcr.io/akashnetwork/console-api"
WEB_REGISTRY="ghcr.io/akashnetwork/console-web"
API_WORKSPACE="apps/api"
WEB_WORKSPACE="apps/deploy-web"

FULL_TAG="${GITHUB_REF#refs/tags/}"
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}"

# Print the final results
echo "App: $app"
echo "workspace: $workspace"
echo "Version: $version"
echo "Registry: $registry"
28 changes: 14 additions & 14 deletions apps/api/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ version: "2.0"

services:
api:
image: <IMAGE_NAME>:<IMAGE_TAG>
image: {{IMAGE_NAME}}:{{IMAGE_TAG}}
depends-on: cloud-sql-proxy
env:
- GITHUB_PAT=
- AKASH_SANDBOX_DATABASE_CS=
- USER_DATABASE_CS=
- SECRET_TOKEN=
- NETWORK=<sandbox|mainnet>
- MASTER_WALLET_MNEMONIC=
- POSTGRES_DB_URI=
- ANONYMOUS_USER_TOKEN_SECRET=
- SENTRY_DSN=
- SENTRY_SERVER_NAME=
- DEPLOYMENT_ENV=<staging|production>
- STRIPE_SECRET_KEY=
- STRIPE_WEBHOOK_SECRET=
- GITHUB_PAT={{GITHUB_PAT}}
- AKASH_SANDBOX_DATABASE_CS={{AKASH_SANDBOX_DATABASE_CS}}
- USER_DATABASE_CS={{USER_DATABASE_CS}}
- SECRET_TOKEN={{SECRET_TOKEN}}
- NETWORK={{NETWORK}}
- MASTER_WALLET_MNEMONIC={{MASTER_WALLET_MNEMONIC}}
- POSTGRES_DB_URI={{POSTGRES_DB_URI}}
- ANONYMOUS_USER_TOKEN_SECRET={{ANONYMOUS_USER_TOKEN_SECRET}}
- SENTRY_DSN={{SENTRY_DSN}}
- SENTRY_SERVER_NAME={{SENTRY_SERVER_NAME}}
- DEPLOYMENT_ENV={{DEPLOYMENT_ENV}}
- STRIPE_SECRET_KEY={{STRIPE_SECRET_KEY}}
- STRIPE_WEBHOOK_SECRET={{STRIPE_WEBHOOK_SECRET}}
expose:
- port: 3080
as: 80
Expand Down
9 changes: 9 additions & 0 deletions apps/api/mvm.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"@akashnetwork/database": "1.0.0",
"@akashnetwork/http-sdk": "1.0.7"
},
"devDependencies": {
"@akashnetwork/dev-config": "1.0.0"
}
}
Empty file removed apps/api/package-lock.json
Empty file.
9 changes: 7 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "console-api",
"name": "@akashnetwork/console-api",
"version": "2.23.4",
"description": "Api providing data to the deploy tool",
"repository": {
Expand Down Expand Up @@ -28,7 +28,8 @@
"test:unit": "jest --selectProjects unit",
"test:unit:cov": "jest --selectProjects unit --coverage",
"test:unit:watch": "jest --selectProjects unit --watch",
"test:watch": "jest --selectProjects unit functional --watch"
"test:watch": "jest --selectProjects unit functional --watch",
"release": "release-it"
},
"dependencies": {
"@akashnetwork/akash-api": "^1.3.0",
Expand Down Expand Up @@ -95,7 +96,10 @@
},
"devDependencies": {
"@akashnetwork/dev-config": "*",
"@akashnetwork/docker": "*",
"@akashnetwork/releaser": "*",
"@faker-js/faker": "^8.4.1",
"@release-it/conventional-changelog": "github:ygrishajev/conventional-changelog#feature/pre-release",
"@types/http-assert": "^1.5.5",
"@types/http-errors": "^2.0.4",
"@types/jest": "^29.5.12",
Expand All @@ -119,6 +123,7 @@
"nodemon-webpack-plugin": "^4.8.2",
"prettier": "^3.3.0",
"prettier-plugin-tailwindcss": "^0.6.1",
"release-it": "^17.6.0",
"supertest": "^6.1.5",
"ts-jest": "^29.1.4",
"ts-loader": "^9.2.5",
Expand Down
Loading

0 comments on commit 4db618f

Please sign in to comment.