diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml new file mode 100644 index 0000000..0986458 --- /dev/null +++ b/.github/workflows/terraform.yaml @@ -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 + diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index a106712..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Test Branch - -on: - push: - branches: [dailyTest] - -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 - diff --git a/Terraform/Aliyun/main.tf b/Terraform/Aliyun/main.tf index 3df22fa..de03435 100644 --- a/Terraform/Aliyun/main.tf +++ b/Terraform/Aliyun/main.tf @@ -303,8 +303,8 @@ cd utils/create-cluster ./create-cluster start yes yes | ./create-cluster create -# 尝试克隆 Git 仓库,最多尝试 10 次 -REPO_URL="https://github.com/MrHappyEnding/compatibility-test-suite-for-redis.git" +# 可替换为含有dailyTest分支仓库的url +REPO_URL="https://github.com/tair-opensource/resp-compatibility.git" RETRY_COUNT=0 MAX_RETRIES=10 SLEEP_DURATION=30 @@ -325,7 +325,7 @@ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then exit 1 fi -cd compatibility-test-suite-for-redis +cd resp-compatibility git checkout dailyTest python3 conn.py EOF diff --git a/Terraform/Test/main.tf b/Terraform/Test/main.tf deleted file mode 100644 index c6a73d3..0000000 --- a/Terraform/Test/main.tf +++ /dev/null @@ -1,124 +0,0 @@ -variable "access_key" { - description = "Access key for Alicloud provider" - type = string -} - -variable "secret_key" { - description = "Secret key for Alicloud provider" - type = string -} - -variable "github_token" { - description = "GitHub token for accessing GitHub API" - type = string -} - -variable "user_name" { - description = "GitHub user name" - type = string -} - -variable "user_email" { - description = "GitHub user email" - type = string -} - -locals { - selected_zone_id = "cn-hongkong-b" -} - -provider "alicloud" { - access_key = var.access_key - secret_key = var.secret_key - region = "cn-hongkong" -} - -# 创建 VPC -resource "alicloud_vpc" "my_vpc" { - vpc_name = "MyVPC" - cidr_block = "172.16.0.0/24" -} - -# 创建 VSwitch -resource "alicloud_vswitch" "my_vswitch" { - vswitch_name = "glcc_vswitch" - vpc_id = alicloud_vpc.my_vpc.id - cidr_block = "172.16.0.0/24" - zone_id = local.selected_zone_id -} - -resource "alicloud_security_group" "my_sg" { - name = "glcc_test_security_group" - vpc_id = alicloud_vpc.my_vpc.id - description = "Security Group for testing" -} - -resource "alicloud_security_group_rule" "allow_ssh" { - security_group_id = alicloud_security_group.my_sg.id - type = "ingress" - ip_protocol = "tcp" - nic_type = "intranet" - policy = "accept" - port_range = "22/22" - priority = 1 - cidr_ip = "0.0.0.0/0" -} - -resource "alicloud_security_group_rule" "allow_http" { - security_group_id = alicloud_security_group.my_sg.id - type = "ingress" - ip_protocol = "tcp" - nic_type = "intranet" - policy = "accept" - port_range = "80/80" - priority = 100 - cidr_ip = "0.0.0.0/0" -} - -resource "alicloud_security_group_rule" "allow_https_outbound" { - type = "egress" - security_group_id = alicloud_security_group.my_sg.id - ip_protocol = "tcp" - nic_type = "intranet" - policy = "accept" - port_range = "443/443" - cidr_ip = "0.0.0.0/0" - description = "Allow outbound HTTPS traffic to external services" -} - -resource "alicloud_security_group_rule" "allow_redis" { - type = "ingress" - security_group_id = alicloud_security_group.my_sg.id - ip_protocol = "tcp" - nic_type = "intranet" - policy = "accept" - port_range = "6379/17005" - cidr_ip = "172.16.0.10/16" # 仅允许特定 ECS 实例的私有 IP 访问 - description = "Allow inbound Redis traffic" -} - -# 云原生 1GB 标准版 Tair 6.0 -resource "alicloud_kvstore_instance" "my_tair_standard" { - db_instance_name = "glcc_tair_standard" - instance_class = "tair.rdb.1g" - instance_type = "Redis" - engine_version = "7.0" - zone_id = local.selected_zone_id - vswitch_id = alicloud_vswitch.my_vswitch.id - payment_type = "PostPaid" - password = "T123456@*" - security_ips = ["172.16.0.10"] -} - - - -# 输出实例信息,目前用于验证 -output "tair_standard_instance_address" { - value = alicloud_kvstore_instance.my_tair_standard.connection_domain -} - -output "tair_standard_instance_port" { - value = alicloud_kvstore_instance.my_tair_standard.private_connection_port -} - - diff --git a/conn.py b/conn.py index 5dd3d35..b35907f 100644 --- a/conn.py +++ b/conn.py @@ -79,7 +79,7 @@ def run_test(): "git stash -u", "git checkout gh-pages || git checkout -b gh-pages", "git pull origin gh-pages", - "cp -r /root/html/* .", #更新直接覆盖原同名文件 + "cp -r /root/html/* .", "git add .", "git commit -m 'Update test results'", ]