Skip to content

Commit

Permalink
Merge pull request #1 from near-daos/feature/github_actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
okalenyk authored Jan 14, 2022
2 parents 690c049 + 1bef237 commit efd11f3
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 12 deletions.
15 changes: 15 additions & 0 deletions .github/actions/build-test/action.yaml
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}
39 changes: 39 additions & 0 deletions .github/actions/docker-build-publish/action.yaml
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
1 change: 1 addition & 0 deletions .github/env.common
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AWS_DEFAULT_REGION=eu-central-1
5 changes: 5 additions & 0 deletions .github/env.develop
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
5 changes: 5 additions & 0 deletions .github/env.production
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
230 changes: 230 additions & 0 deletions .github/workflows/build-deploy.yaml
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
23 changes: 23 additions & 0 deletions .github/workflows/pull-requests-aggregator.yaml
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
23 changes: 23 additions & 0 deletions .github/workflows/pull-requests-api.yaml
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ Thumbs.db
.history
temp
tmp
.env.local
.env.*
.vscode
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ data:
NEST_APP_TYPE: aggregator
AGGREGATOR_POLLING_SCHEDULE: "{{ .Values.environment.aggregator_polling_schedule }}"
SMART_CONTRACTS: astro
LOG_LEVELS: "log,warn,error"
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ spec:
# successThreshold: {{ .Values.container.readinessProbe.successThreshold }}
# failureThreshold: {{ .Values.container.readinessProbe.failureThreshold }}
envFrom:
- configMapRef:
name: dao-stats-configmap
- configMapRef:
name: dao-stats-aggregator-configmap
- configMapRef:
Expand Down
2 changes: 1 addition & 1 deletion apps/api/deployment/app-chart/templates/api-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ data:
PORT: "3000"
NEST_APP_TYPE: api
REDIS_HTTP_CACHE_TTL: "60"
SMART_CONTRACTS: astro
LOG_LEVELS: "log,warn,error"
2 changes: 0 additions & 2 deletions apps/api/deployment/app-chart/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ spec:
successThreshold: {{ .Values.container.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.container.readinessProbe.failureThreshold }}
envFrom:
- configMapRef:
name: dao-stats-configmap
- configMapRef:
name: dao-stats-api-configmap
- configMapRef:
Expand Down
6 changes: 0 additions & 6 deletions apps/api/deployment/app-chart/templates/configmap.yaml

This file was deleted.

0 comments on commit efd11f3

Please sign in to comment.