Initial commit #1
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: Build and Deploy to AWS | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to ECR | |
run: | | |
IMAGE_TAG=latest | |
REPOSITORY_URI=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ECR_REPOSITORY }} | |
# Build the Docker image | |
docker build -t $REPOSITORY_URI:$IMAGE_TAG . | |
# Push the image to ECR | |
docker push $REPOSITORY_URI:$IMAGE_TAG | |
- name: Deploy to ECS | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }} | |
ECS_SERVICE: ${{ secrets.ECS_SERVICE }} | |
run: | | |
# Update the ECS service with the new image | |
aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment |