Skip to content

Commit

Permalink
feat: add deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Feb 19, 2024
1 parent d1bfcc4 commit 20be870
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# https://docs.github.com/en/actions/deployment/deploying-to-your-cloud-provider/deploying-to-amazon-elastic-container-service
name: Deployment

on:
push:
branches:
- main
- development
- 12-add-deployment-script

env:
S3_BUCKET: lisk-migration-assets

jobs:
deployment:
name: deployment
runs-on: ubuntu-latest
# environment: ${{ github.ref_name }}
environment: development

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a

- name: Setup docker image
id: docker-image
run: |
repository=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "repository=$repository" >> $GITHUB_OUTPUT
echo "image=${{ steps.login-ecr.outputs.registry }}/$repository:${{ github.sha }}" >> $GITHUB_OUTPUT
- name: Download merkle tree information
run: |
aws s3 sync s3://$S3_BUCKET/token-claim/ data/token-claim
- name: Build and push
uses: docker/build-push-action@v5
id: docker-build
with:
context: .
push: true
tags: ${{ steps.docker-image.outputs.image }}

# - name: Download task definition
# run: |
# aws ecs describe-task-definition --task-definition ${{ github.event.repository.name }} --query taskDefinition > task-definition.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@c804dfbdd57f713b6c079302a4c01db7017a36fc
# with:
# task-definition: task-definition.json
# container-name: ${{ github.event.repository.name }}
# image: ${{ steps.docker-image.outputs.image }}

# - name: Deploy Amazon ECS task definition
# uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
# with:
# task-definition: ${{ steps.task-def.outputs.task-definition }}
# service: ${{ secrets.ECS_SERVICE }}
# cluster: ${{ secrets.ECS_CLUSTER }}
# wait-for-service-stability: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ dist

# Example Accounts and MerkleTree are not committed
data/example
data/token-claim
tmp

# DB is not committed
postgres
3 changes: 3 additions & 0 deletions docker/claim-backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ WORKDIR /usr/token-claim

COPY --from=0 /opt/build ./

ENV MERKLE_TREE_PATH=/usr/token-claim/data/token-claim/merkle-tree-result-detailed.json

WORKDIR /usr/token-claim/packages/claim-backend


EXPOSE 3000

CMD ["yarn", "server"]
30 changes: 30 additions & 0 deletions scripts/generate_merkle_tree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

FOLDER_NAME="token-claim"
OUTPUT_DIR="./data/$FOLDER_NAME"
SNAPSHOT_URL="https://snapshots.lisk.com/mainnet/blockchain.db.tar.gz"

if [ ! -d "./tmp" ]; then
mkdir -p ./tmp
fi

if [ ! -f "./tmp/blockchain.db.tar.gz" ]; then
curl -o ./tmp/blockchain.db.tar.gz $SNAPSHOT_URL
fi

if [ ! -d "./tmp/blockchain.db" ]; then
tar -xzf ./tmp/blockchain.db.tar.gz -C ./tmp
else
echo "Blockchain database folder already exists"
fi

if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p $OUTPUT_DIR
else
echo "Output folder already exists"
fi

./packages/tree-builder/bin/run.js generate-merkle-tree --db-path=./tmp --output-path=$OUTPUT_DIR || exit 1

# Upload files in $OUTPUT_DIR to S3 with folder token-claim
aws s3 cp $OUTPUT_DIR s3://$S3_BUCKET_NAME/$FOLDER_NAME --recursive

0 comments on commit 20be870

Please sign in to comment.