Skip to content

Commit

Permalink
Daily test using Terraform (#29)
Browse files Browse the repository at this point in the history
1. Use terraform automate buy instance and run test
2. Support Aliyun and Opensource Redis-Like Database
  • Loading branch information
MrHappyEnding authored Oct 29, 2024
1 parent e3bb089 commit e13c4b9
Show file tree
Hide file tree
Showing 6 changed files with 589 additions and 58 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Terraform in Daily Test

on:
schedule:
- cron: '0 18 * * *' # 每天 UTC 时间 18:00,即中国时间凌晨 2 点

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Check GitHub Secrets
run: |
if [ -z "${{ secrets.MYAPP_GITHUB_TOKEN }}" ]; then
echo "GitHub Token is missing"
else
echo "GitHub Token is set"
fi
if [ -z "${{ secrets.MYAPP_USER_EMAIL }}" ]; then
echo "User Email is missing"
else
echo "User Email is set"
fi
if [ -z "${{ secrets.MYAPP_USER_NAME }}" ]; then
echo "User Name is missing"
else
echo "User Name is set"
fi
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: dailyTest

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.9.4

- name: Initialize Terraform
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun init

- name: Apply Terraform Configuration
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun apply -auto-approve

- name: Print current directory and file list
run: |
cd ./Terraform/Aliyun
echo "Current directory:"
pwd
echo "Files in the current directory:"
ls
- name: Wait for 20 minutes before destroying resources
run: sleep 1200 # 等待 20 分钟

- name: Destroy Terraform Configuration
env:
TF_VAR_access_key: ${{ secrets.ALI_ACCESS_KEY }}
TF_VAR_secret_key: ${{ secrets.ALI_SECRET_KEY }}
TF_VAR_github_token: ${{ secrets.MYAPP_GITHUB_TOKEN }}
TF_VAR_user_name: ${{ secrets.MYAPP_USER_NAME }}
TF_VAR_user_email: ${{ secrets.MYAPP_USER_EMAIL }}
run: terraform -chdir=./Terraform/Aliyun destroy -auto-approve

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
test.json
venv
html
__pycache__
__pycache__
Loading

0 comments on commit e13c4b9

Please sign in to comment.