Remove legacy Terraform configuration files and add a new script for … #11
This file contains hidden or 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 ECR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| AWS_REGION: ${{ secrets.AWS_REGION }} | |
| AWS_IAM_ROLE_ARN: ${{ secrets.AWS_IAM_ROLE_ARN }} | |
| TERRAFORM_DIR: ./01-tf | |
| TERRAFORM_VERSION: '1.12.0' | |
| jobs: | |
| deploy: | |
| name: Deploy to ECR | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ env.AWS_IAM_ROLE_ARN }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: ${{ env.TERRAFORM_VERSION }} | |
| - name: Terraform Init | |
| id: init | |
| run: terraform init -input=false | |
| working-directory: ${{ env.TERRAFORM_DIR }} | |
| - name: Terraform Apply | |
| id: apply | |
| run: | | |
| echo "O_AWS_REGION=${{ env.AWS_REGION }}" | |
| terraform apply -auto-approve -input=false -var="AWS_REGION=${{ env.AWS_REGION }}" | |
| working-directory: ${{ env.TERRAFORM_DIR }} | |
| - name: Get ECR Repository URL | |
| id: get_ecr_url | |
| run: echo "ECR_REPOSITORY_URL=$(terraform output -raw ecr_repository_url)" >> $GITHUB_ENV | |
| working-directory: ${{ env.TERRAFORM_DIR }} | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.ECR_REPOSITORY_URL }} | |
| - name: Build, tag, and push image to Amazon ECR | |
| id: build-image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ env.ECR_REPOSITORY_URL }}:latest |