Skip to content

chore: deploy action #35

chore: deploy action

chore: deploy action #35

name: "[WORKER] Deploy to Amazon ECS"
on:
push:
branches:
- FEAT/index-vaaul-balance
jobs:
check-changes:
name: "Check for Changes"
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.check.outputs.should_deploy }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Check for changes in ./packages/worker
id: check
run: |
if git diff --quiet HEAD~1 -- ./packages/worker; then
echo "No changes detected in ./packages/worker"
echo "::set-output name=should_deploy::false"
else
echo "Changes detected in ./packages/worker"
echo "::set-output name=should_deploy::true"
fi
deploy:
name: "[WORKER] Deploy to Amazon ECS"
needs: check-changes
runs-on: ubuntu-latest
if: needs.check-changes.outputs.should_deploy == 'true'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.BAKO_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.BAKO_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login_ecr.outputs.registry }}
ECR_REPOSITORY: bako-safe-worker
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./packages/worker
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- 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
with:
task-definition: ./packages/worker/task_def.json
container-name: bako-safe-worker
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: bako-safe-worker-service
cluster: Bako-Safe-ECS
wait-for-service-stability: true