Skip to content

Commit

Permalink
Merge pull request #41 from timi-codes/chore/run-migration-on-deployment
Browse files Browse the repository at this point in the history
run migrations on deployment
  • Loading branch information
timi-codes authored Oct 13, 2024
2 parents d962887 + aa6921d commit cebeab0
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Deploy to AWS

on:
push:
branches:
Expand All @@ -10,58 +10,58 @@ jobs:
name: Build and push Docker image to ECR
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Check out the repository
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
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: 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: 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/$IMAGE_TAG:latest
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest
- 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-node16
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: 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: 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"
- 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"

0 comments on commit cebeab0

Please sign in to comment.