added docker #41
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: Full Infra Deployment with OIDC | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Configure AWS credentials via OIDC | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::011664843975:role/github-permissions | |
| aws-region: ap-south-1 | |
| - name: Verify identity | |
| run: aws sts get-caller-identity | |
| # ------------------------- | |
| # Terraform FIRST | |
| # ------------------------- | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v2 | |
| with: | |
| terraform_version: 1.7.3 | |
| - name: Terraform Init | |
| working-directory: terraform | |
| run: terraform init | |
| - name: Terraform Apply | |
| working-directory: terraform | |
| run: terraform apply -auto-approve | |
| env: | |
| TF_VAR_db_password: ${{ secrets.DB_PASSWORD }} | |
| TF_VAR_key_name: ${{ secrets.EC2_KEY_NAME }} | |
| # ------------------------- | |
| # Docker AFTER ECR exists | |
| # ------------------------- | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to ECR | |
| run: | | |
| aws ecr get-login-password --region ap-south-1 \ | |
| | docker login --username AWS --password-stdin 011664843975.dkr.ecr.ap-south-1.amazonaws.com | |
| - name: Build Docker image | |
| run: docker build -t serverless-crud-api-terraform . | |
| - name: Tag Docker image | |
| run: | | |
| docker tag serverless-crud-api-terraform:latest \ | |
| 011664843975.dkr.ecr.ap-south-1.amazonaws.com/serverless-crud-api-terraform:latest | |
| - name: Push Docker image | |
| run: | | |
| docker push 011664843975.dkr.ecr.ap-south-1.amazonaws.com/serverless-crud-api-terraform:latest |