This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
Apply Deployments #18
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: Apply Deployments | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [deployment] | |
jobs: | |
deploy-k8s: | |
name: Apply Deployments | |
runs-on: ubuntu-latest | |
steps: | |
- name: AWS Deployment | |
run: echo "Deploying..." | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-region: "us-east-1" | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Run deploy script | |
run: | | |
aws eks update-kubeconfig --name eks-techmedicos --region us-east-1 | |
chmod +x ./k8s/apply-all.sh | |
./k8s/apply-all.sh | |
############################################################# | |
wait_lb: | |
name: Aguardar criação do Load Balancer | |
runs-on: ubuntu-latest | |
needs: deploy-k8s | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-region: 'us-east-1' | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Sleep for 3 minutes | |
run: sleep 180s | |
############################################################# | |
tf-test: | |
name: Terraform Test | |
runs-on: ubuntu-latest | |
needs: wait_lb | |
defaults: | |
run: | |
working-directory: src/terraform-api-gateway | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-region: 'us-east-1' | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: 1.6.2 | |
- name: Prepare environment | |
id: tf-init | |
run: terraform init | |
- name: Terraform fmt | |
id: tf-fmt | |
run: terraform fmt --recursive | |
- name: Terraform validate | |
id: tf-validate | |
run: terraform validate -no-color | |
- name: Terraform Plan | |
id: tf-plan | |
run: terraform plan -lock=false -no-color -input=false | |
continue-on-error: true | |
- name: Pull Request Updates | |
uses: actions/github-script@v6 | |
if: github.event_name == 'pull_request' | |
env: | |
PLAN: ${{ steps.tf-plan.outputs.stdout }} | |
with: | |
github-token: ${{ secrets.GH_TOKEN }} | |
script: | | |
const output = `#### Terraform Format and Style 🖌\`${{ steps.tf-fmt.outcome }}\` | |
#### Terraform Initialization ⚙️\`${{ steps.tf-init.outcome }}\` | |
#### Terraform Validation 🤖\`${{ steps.tf-validate.outcome }}\` | |
#### Terraform Plan 📖\`${{ steps.tf-plan.outcome }}\` | |
<details><summary>Show Plan</summary> | |
\`\`\`terraform\n | |
${process.env.PLAN} | |
\`\`\` | |
</details> | |
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: output | |
}) | |
- name: Terraform Plan Status | |
if: steps.tf-plan.outcome == 'failure' | |
run: exit 1 | |
tf-deploy: | |
name: Terraform Deploy | |
needs: | |
- tf-test | |
if: github.ref == 'refs/heads/release' || github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: src | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to AWS | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: 'us-east-1' | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-session-token: ${{ secrets.AWS_SESSION_TOKEN }} | |
- name: Configure AWS Dotnet CLI | |
run: dotnet tool install -g Amazon.Lambda.Tools | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v2 | |
- name: Prepare environment | |
run: terraform -chdir=terraform-api-gateway/ init | |
- name: Terraform Plan | |
run: terraform -chdir=terraform-api-gateway/ plan -lock=false -no-color -input=false | |
- name: Execute terraform apply | |
run: terraform -chdir=terraform-api-gateway/ apply -lock=false -auto-approve -input=false | |
############################################################# |