Skip to content

Deploy (Aggregator, Parser, Collector) #2

Deploy (Aggregator, Parser, Collector)

Deploy (Aggregator, Parser, Collector) #2

Workflow file for this run

name: Deploy (Aggregator, Parser, Collector)
on:
workflow_dispatch:
inputs:
network:
description: 'Network to deploy to'
required: true
type: choice
options:
- "phoenix"
- "columbus-v2"
- "cube"
- "dimension"
- "fetchhub"
app_type:
description: 'App type to deploy'
required: true
type: choice
options:
- "collector"
- "parser-dex"
- "aggregator"
region:
description: 'Region to be deployed'
required: false
type: choice
default: "ap-northeast-2"
options:
- "ap-northeast-2"
- "us-west-2"
env:
# AWS
ECR_REPOSITORY: cosmwasm-etl
ECS_CLUSTER: cosmwasm-etl
GIT_COMMIT: ${{ github.sha }}
TARGET: ${{ format('{0}-cosmwasm-etl-{1}', github.event.inputs.network, github.event.inputs.app_type) }}
CONFIG_NAME: ${{ format('{0}_{1}_CONFIG', github.event.inputs.network, github.event.inputs.app_type) }}
jobs:
deploy:
name: build and deploy the app
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Shortten commit hash
run: |
echo "GIT_COMMIT=${GIT_COMMIT::7}" >> $GITHUB_ENV
# to Upper case
echo "CONFIG_NAME=$(echo "$CONFIG_NAME" | tr '-' '_' | tr '[:lower:]' '[:upper:]')" >> $GITHUB_ENV
- name: checkout
uses: actions/checkout@v3
- name: Configure AWS credentials for dependency image
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEPS_REGION }}
mask-aws-account-id: 'true'
- name: Login to Amazon ECR
id: login-ecr-deps
uses: aws-actions/amazon-ecr-login@v2.0.1
- name: Pull dependency image
id: pull
working-directory: .
run: |
docker pull ${{ steps.login-ecr-deps.outputs.registry }}/$ECR_REPOSITORY:deps-${{env.GIT_COMMIT}}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ inputs.region }}
mask-aws-account-id: 'true'
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2.0.1
- name: Build the app, tag and push image
id: build
working-directory: .
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
CONFIG: ${{ secrets[env.CONFIG_NAME] }}
run: |
IMAGE_TAG=${{inputs.app_type}}-${{env.GIT_COMMIT}}
echo "${CONFIG}" > config.yaml
APP_PATH=$(echo ${{inputs.app_type}} | tr '-' '/')
docker build \
--build-arg BUILD_BASE_IMAGE="${{ steps.login-ecr-deps.outputs.registry }}/$ECR_REPOSITORY:deps-${{env.GIT_COMMIT}}" \
--build-arg APP_PATH=$APP_PATH \
--no-cache -t $ECR_REGISTRY/$ECR_REPOSITORY:${{env.TARGET}} -t $ECR_REGISTRY/$ECR_REPOSITORY:${IMAGE_TAG} .
docker image push -a $ECR_REGISTRY/$ECR_REPOSITORY
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
- name: Download Task Definition
id: download-task-definition
working-directory: .
run: |
aws ecs describe-task-definition --task-definition ${{ env.TARGET }} | jq '.taskDefinition' > ${{ env.TARGET }}.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1.2.0
with:
task-definition: ./${{ env.TARGET }}.json
container-name: ${{ env.TARGET }}
image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY}}:${{ env.TARGET }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1.4.10
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.TARGET }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true