-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from near-daos/feature/github_actions
GitHub actions
- Loading branch information
Showing
14 changed files
with
344 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Build Test' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14.16.0' | ||
cache: 'yarn' | ||
|
||
- shell: bash | ||
run: | | ||
yarn install | ||
yarn test || true | ||
yarn lint . || true | ||
yarn build ${APP_NAME} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: 'Docker Build Publish' | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v3 | ||
with: | ||
images: | | ||
${{ env.AWS_ECR_URL }}/dao-stats-${{ env.APP_NAME }} | ||
tags: | | ||
type=raw,value=latest | ||
type=raw,value=${{ env.DOCKER_ENV_TAG }} | ||
type=ref,event=branch,suffix=-latest | ||
type=sha,prefix=,format=long | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_DEFAULT_REGION }} | ||
|
||
- name: Login to ECR | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build And Push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
platforms: linux/amd64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
push: true | ||
build-args: APP_NAME=${{ env.APP_NAME }} | ||
cache-from: type=registry,ref=${{ env.AWS_ECR_URL }}/dao-stats-${{ env.APP_NAME }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AWS_DEFAULT_REGION=eu-central-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NODE_ENV=production | ||
DATABASE_MIGRATIONS_LIST=ContractsMigration,ReceiptActionArgsMigration,ContractIdRelationMigration,TransactionProposalVoteMigration,ReceiptActionBlockTimestampMigration | ||
AGGREGATOR_POLLING_SCHEDULE="0 * * * *" | ||
LOG_LEVELS=log,warn,error | ||
SMART_CONTRACTS=astro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
NODE_ENV=production | ||
DATABASE_MIGRATIONS_LIST=ContractsMigration,ReceiptActionArgsMigration,ContractIdRelationMigration,TransactionProposalVoteMigration,ReceiptActionBlockTimestampMigration | ||
AGGREGATOR_POLLING_SCHEDULE="0 * * * *" | ||
LOG_LEVELS=log,warn,error | ||
SMART_CONTRACTS=astro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,230 @@ | ||
name: Build Deploy All | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
required: false | ||
description: Specify environment to run on. Valid values are develop, production | ||
apps: | ||
required: false | ||
default: aggregator api | ||
push: | ||
branches: | ||
- develop | ||
- staging | ||
tags: | ||
- "**" | ||
|
||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_ECR_URL: ${{ secrets.AWS_ECR_URL }} | ||
|
||
jobs: | ||
get-updated-apps: | ||
name: Get Updated Apps | ||
runs-on: ubuntu-latest | ||
outputs: | ||
updated-apps: ${{ steps.updated-apps.outputs.apps }} | ||
aggregator: ${{ steps.updated-apps.outputs.aggregator }} | ||
api: ${{ steps.updated-apps.outputs.api }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 2 | ||
- uses: tj-actions/[email protected] | ||
id: changed-files | ||
|
||
- id: updated-apps | ||
shell: bash | ||
run: | | ||
if [[ "${{ github.event.inputs.apps }}" != "" ]] | ||
then | ||
echo "List of apps was provided manually: ${{ github.event.inputs.apps }}" | ||
echo "::set-output name=apps::${{ github.event.inputs.apps }}" | ||
for app in ${{ github.event.inputs.apps }} | ||
do | ||
echo "::set-output name=$app::true" | ||
done | ||
exit 0 | ||
fi | ||
for file in ${{ join(steps.changed-files.outputs.modified_files, ' ') }} | ||
do | ||
echo "$file was updated, checking if it is libs file" | ||
if [[ "$file" =~ ^libs/.* ]] | ||
then | ||
echo "$file matched libs" | ||
echo "::set-output name=apps::aggregator api" | ||
echo "::set-output name=aggregator::true" | ||
echo "::set-output name=api::true" | ||
exit 0 | ||
fi | ||
done | ||
for app in aggregator api | ||
do | ||
for file in ${{ join(steps.changed-files.outputs.modified_files, ' ') }} | ||
do | ||
echo "$file was updated, checking if it is $app file" | ||
if [[ "$file" =~ ^apps/$app/.* ]] | ||
then | ||
echo "$file is part of $app" | ||
export UPDATED_APPS="$UPDATED_APPS $app" | ||
echo "::set-output name=$app::true" | ||
break | ||
fi | ||
done | ||
done | ||
echo "::set-output name=apps::$UPDATED_APPS" | ||
get-environment: | ||
name: Get Environment | ||
runs-on: ubuntu-latest | ||
outputs: | ||
environment: ${{ steps.get-environment.outputs.environment }} | ||
namespace_prefix: ${{ steps.get-environment.outputs.namespace_prefix }} | ||
k8s_ingress_base_host: ${{ steps.get-environment.outputs.k8s_ingress_base_host }} | ||
kube_config_data_secret_name: ${{ steps.get-environment.outputs.kube_config_data_secret_name }} | ||
steps: | ||
- name: get environment | ||
id: get-environment | ||
shell: bash | ||
run: | | ||
if [[ "${{ github.ref }}" =~ ^refs/tags.* ]] | ||
then | ||
echo "::set-output name=environment::production" | ||
echo "::set-output name=namespace_prefix::dao-stats-api-production" | ||
echo "::set-output name=k8s_ingress_base_host::api.daostats.io" | ||
echo "::set-output name=kube_config_data_secret_name::KUBE_CONFIG_DATA_PRODUCTION" | ||
elif [[ "${{ github.ref }}" =~ ^refs/heads/staging ]] | ||
then | ||
echo "::set-output name=environment::staging" | ||
echo "::set-output name=namespace_prefix::ds-s" | ||
elif [[ "${{ github.ref }}" =~ ^refs/heads/develop ]] | ||
then | ||
echo "::set-output name=environment::develop" | ||
echo "::set-output name=namespace_prefix::ds-d" | ||
echo "::set-output name=k8s_ingress_base_host::development.api.daostats.io" | ||
echo "::set-output name=kube_config_data_secret_name::KUBE_CONFIG_DATA_DEVELOP" | ||
fi | ||
if [[ "${{ github.event.inputs.environment }}" != "" ]] | ||
then | ||
echo "input was provided: ${{ github.event.inputs.environment }}" | ||
echo "::set-output name=environment::${{ github.event.inputs.environment }}" | ||
echo "::set-output name=namespace_prefix::ds-d" | ||
echo "::set-output name=k8s_ingress_base_host::development.api.daostats.io" | ||
echo "::set-output name=kube_config_data_secret_name::KUBE_CONFIG_DATA_DEVELOP" | ||
fi | ||
build-image-aggregator: | ||
name: Build Image Aggregator | ||
if: needs.get-updated-apps.outputs.aggregator | ||
env: | ||
APP_NAME: aggregator | ||
runs-on: ubuntu-latest | ||
needs: | ||
- get-updated-apps | ||
- get-environment | ||
environment: | ||
name: ${{ needs.get-environment.outputs.environment }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo DOCKER_ENV_TAG=${{ needs.get-environment.outputs.environment }}-$GITHUB_SHA >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
cat ".github/env.${{ needs.get-environment.outputs.environment }}" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Docker Build Publish | ||
uses: ./.github/actions/docker-build-publish | ||
|
||
build-image-api: | ||
name: Build Image API | ||
if: needs.get-updated-apps.outputs.api | ||
env: | ||
APP_NAME: api | ||
runs-on: ubuntu-latest | ||
needs: | ||
- get-updated-apps | ||
- get-environment | ||
environment: | ||
name: ${{ needs.get-environment.outputs.environment }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo DOCKER_ENV_TAG=${{ needs.get-environment.outputs.environment }}-$GITHUB_SHA >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
cat ".github/env.${{ needs.get-environment.outputs.environment }}" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Docker Build Publish | ||
uses: ./.github/actions/docker-build-publish | ||
|
||
helm-deploy-testnet: | ||
name: Helm Deploy Testnet | ||
runs-on: ubuntu-latest | ||
if: always() | ||
needs: | ||
- get-updated-apps | ||
- get-environment | ||
- build-image-aggregator | ||
- build-image-api | ||
environment: | ||
name: ${{ needs.get-environment.outputs.environment }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo DOCKER_ENV_TAG=${{ needs.get-environment.outputs.environment }}-$GITHUB_SHA >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
cat ".github/env.${{ needs.get-environment.outputs.environment }}" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Helm Deploy | ||
uses: koslib/[email protected] | ||
env: | ||
KUBE_CONFIG_DATA: ${{ secrets[needs.get-environment.outputs.kube_config_data_secret_name] }} | ||
with: | ||
command: | | ||
set -x | ||
for APP_NAME in ${{ needs.get-updated-apps.outputs.updated-apps }} | ||
do | ||
export CHART_FOLDER=apps/${APP_NAME}/deployment/app-chart | ||
helm lint $CHART_FOLDER | ||
helm -n ${{ needs.get-environment.outputs.namespace_prefix }}-testnet upgrade --install --create-namespace --atomic dao-stats-$APP_NAME $CHART_FOLDER \ | ||
--set image.tag=$DOCKER_ENV_TAG \ | ||
--set environment.contract_env=testnet \ | ||
--set aggregatorConfig=${{ secrets.AGGREGATOR_CONFIG_TESTNET }} \ | ||
--set ingress.host=testnet.${{ needs.get-environment.outputs.k8s_ingress_base_host }} | ||
done | ||
helm-deploy-mainnet: | ||
name: Helm Deploy Mainnet | ||
runs-on: ubuntu-latest | ||
if: always() | ||
needs: | ||
- get-updated-apps | ||
- get-environment | ||
- build-image-aggregator | ||
- build-image-api | ||
environment: | ||
name: ${{ needs.get-environment.outputs.environment }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo DOCKER_ENV_TAG=${{ needs.get-environment.outputs.environment }}-$GITHUB_SHA >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
cat ".github/env.${{ needs.get-environment.outputs.environment }}" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Helm Deploy | ||
uses: koslib/[email protected] | ||
env: | ||
KUBE_CONFIG_DATA: ${{ secrets[needs.get-environment.outputs.kube_config_data_secret_name] }} | ||
with: | ||
command: | | ||
set -x | ||
for APP_NAME in ${{ needs.get-updated-apps.outputs.updated-apps }} | ||
do | ||
export CHART_FOLDER=apps/${APP_NAME}/deployment/app-chart | ||
helm lint $CHART_FOLDER | ||
helm -n ${{ needs.get-environment.outputs.namespace_prefix }}-mainnet upgrade --install --create-namespace --atomic dao-stats-$APP_NAME $CHART_FOLDER \ | ||
--set image.tag=$DOCKER_ENV_TAG \ | ||
--set environment.contract_env=mainnet \ | ||
--set aggregatorConfig=${{ secrets.AGGREGATOR_CONFIG_MAINNET }} \ | ||
--set ingress.host=mainnet.${{ needs.get-environment.outputs.k8s_ingress_base_host }} | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test Aggregator | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- '**' | ||
paths: | ||
- 'apps/aggregator/**' | ||
- 'libs/**' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Build | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo APP_NAME=aggregator >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Build Test | ||
uses: ./.github/actions/build-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test API | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- '**' | ||
paths: | ||
- 'apps/api/**' | ||
- 'libs/**' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Build | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Environment | ||
run: | | ||
echo APP_NAME=aggregator >> $GITHUB_ENV | ||
cat ".github/env.common" | grep -E -v '^\ *#' >>$GITHUB_ENV | ||
- name: Build Test | ||
uses: ./.github/actions/build-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,5 +51,5 @@ Thumbs.db | |
.history | ||
temp | ||
tmp | ||
.env.local | ||
.env.* | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.