Deploy Text-to-Code AWS demo by @robertandremitchell #22
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 Text-to-Code AWS demo | |
| run-name: Deploy Text-to-Code AWS demo by @${{ github.actor }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| apply: | |
| description: "Apply changes (if false, only runs plan)" | |
| type: boolean | |
| default: false | |
| destroy: | |
| description: "Destroy all resources (WARNING: irreversible)" | |
| type: boolean | |
| default: false | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: deploy-text-to-code-aws-demo | |
| cancel-in-progress: false | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| deploy_text_to_code: | |
| name: Terraform | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v4 | |
| with: | |
| terraform_version: 1.14.7 | |
| terraform_wrapper: false | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v6 | |
| with: | |
| role-to-assume: ${{ secrets.TERRAFORM_ROLE_ARN }} | |
| role-session-name: githubDeploymentWorkflow | |
| aws-region: ${{ vars.AWS_REGION }} | |
| - name: Terraform Init | |
| working-directory: terraform | |
| run: terraform init | |
| - name: Terraform Format Check | |
| working-directory: terraform | |
| run: terraform fmt -check -recursive | |
| - name: Terraform Validate | |
| working-directory: terraform | |
| run: terraform validate | |
| - name: Create ECR repositories | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| working-directory: terraform | |
| run: terraform apply -auto-approve -target=aws_ecr_repository.index_lambda -target=aws_ecr_repository.ttc_lambda | |
| - name: Login to Amazon ECR | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| id: ecr-login | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Get ECR repository URLs | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| id: ecr-url | |
| working-directory: terraform | |
| run: | | |
| INDEX_ECR_URL=$(terraform output -raw index_ecr_repository_url) | |
| echo "index_ecr_url=$INDEX_ECR_URL" >> "$GITHUB_OUTPUT" | |
| ECR_URL=$(terraform output -raw ecr_repository_url) | |
| echo "ecr_url=$ECR_URL" >> "$GITHUB_OUTPUT" | |
| - name: Build and push Index Docker image | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| run: | | |
| INDEX_ECR_URL="${{ steps.ecr-url.outputs.index_ecr_url }}" | |
| docker build -f Dockerfile.index -t "$INDEX_ECR_URL:${{ github.sha }}" -t "$INDEX_ECR_URL:latest" . | |
| docker push "$INDEX_ECR_URL:${{ github.sha }}" | |
| docker push "$INDEX_ECR_URL:latest" | |
| - name: Build and push TTC Docker image | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| run: | | |
| ECR_URL="${{ steps.ecr-url.outputs.ecr_url }}" | |
| docker build -f Dockerfile.ttc -t "$ECR_URL:${{ github.sha }}" -t "$ECR_URL:latest" . | |
| docker push "$ECR_URL:${{ github.sha }}" | |
| docker push "$ECR_URL:latest" | |
| - name: Terraform Plan | |
| if: ${{ !inputs.apply && !inputs.destroy }} | |
| working-directory: terraform | |
| run: terraform plan | |
| - name: Terraform Apply | |
| if: ${{ inputs.apply && !inputs.destroy }} | |
| working-directory: terraform | |
| run: terraform apply -auto-approve -var="index_lambda_image_tag=${{ github.sha }}" -var="ttc_lambda_image_tag=${{ github.sha }}" | |
| - name: Terraform Destroy | |
| if: ${{ inputs.destroy }} | |
| working-directory: terraform | |
| run: terraform destroy -auto-approve |