Skip to content

Merge pull request #41 from timi-codes/chore/run-migration-on-deployment #5

Merge pull request #41 from timi-codes/chore/run-migration-on-deployment

Merge pull request #41 from timi-codes/chore/run-migration-on-deployment #5

Workflow file for this run

name: Deploy to AWS
on:
push:
branches:
- main
jobs:
create-docker-image:
name: Build and push Docker image to ECR
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: c9m9e8e2
REPOSITORY: coinfolio-api
IMAGE_TAG: coinfolio-api
run: |
docker build -t $IMAGE_TAG .
docker tag $IMAGE_TAG:latest $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest
deploy:
name: Build and deploy the new Docker image to ECS
runs-on: ubuntu-latest
needs: create-docker-image
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Update ECS service
run: |
aws ecs update-service \
--cluster ${{ vars.AWS_CLUSTER_NAME }} \
--service ${{ vars.AWS_SERVICE_NAME }} \
--task-definition ${{ vars.AWS_TASK_DEFINITION_NAME }} \
--force-new-deployment
- name: Run database migrations
run: |
aws ecs execute-command \
--cluster ${{ vars.AWS_CLUSTER_NAME }} \
--task ${{ vars.AWS_TASK_ID }} \
--container ${{ vars.AWS_CONTAINER_NAME }} \
--interactive \
--command "yarn run db:migrate"