Merge pull request #39 from timi-codes/chore/final-cleanup #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-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: 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 | |
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: 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 |