GCP Full Infra Creation/Deletion Test [APPLY] #150
Workflow file for this run
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: GCP Full Infra Creation/Deletion Test [APPLY] | |
on: | |
workflow_dispatch: | |
inputs: | |
pr_number: | |
description: "Pull Request Number" | |
required: true | |
pull_request_review: | |
types: [submitted] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: "read" | |
id-token: "write" | |
env: | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
PLAN_WORKFLOW_NAME: gcp-full-infra-test-plan.yaml | |
tenant_group_name: "workflow-pr-${{ github.event.pull_request.number }}" | |
tenant_name: "t-1" | |
TF_VAR_falkordb_version: "edge" | |
jobs: | |
apply: | |
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') | |
runs-on: ubuntu-latest | |
environment: testing | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set PR_NUMBER env variable | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
# If event is workflow_dispatch, use the event.workflow_dispatch.inputs.pr_number | |
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV | |
echo "tenant_group_name=workflow-pr-${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV | |
- name: Setup GCloud | |
uses: "google-github-actions/[email protected]" | |
with: | |
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} | |
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }} | |
- name: Set up Cloud SDK | |
uses: "google-github-actions/[email protected]" | |
with: | |
version: ">= 363.0.0" | |
install_components: "gke-gcloud-auth-plugin" | |
- name: Set up Tofu | |
uses: opentofu/[email protected] | |
with: | |
tofu_wrapper: false | |
- name: Retrieve artifacts from last plan | |
uses: dawidd6/action-download-artifact@v3 | |
with: | |
workflow: ${{ env.PLAN_WORKFLOW_NAME }} | |
pr: ${{ env.PR_NUMBER }} | |
name: artifacts-${{ env.PR_NUMBER }} | |
path: artifacts | |
- name: Apply GCP Test Environment | |
id: apply_tenant_group | |
timeout-minutes: 20 | |
continue-on-error: true | |
working-directory: ./tofu/gcp/test_env | |
run: | | |
tofu init -backend-config="bucket=${{ vars.GCP_STATE_BUCKET_NAME }}" -backend-config="prefix=test_env/$PR_NUMBER" | |
tofu apply -auto-approve ${GITHUB_WORKSPACE}/artifacts/test_env.tfplan | |
- name: Get link for Tenant Group state | |
run: echo "https://console.cloud.google.com/storage/browser/${{ vars.GCP_STATE_BUCKET_NAME }}/test_env/$PR_NUMBER?project=${{ vars.GCP_PROJECT_ID }}" | |
- name: Get cluster credentials | |
if: steps.apply_tenant_group.outcome == 'success' | |
id: get_cluster_credentials | |
continue-on-error: true | |
working-directory: ./tofu/gcp/test_env | |
run: | | |
gcloud container clusters get-credentials $(tofu output -json | jq -r '.cluster_name.value') --region ${{ vars.GCP_REGION }} --project ${{ vars.GCP_PROJECT_ID }} | |
- name: Check connection to cluster | |
if: steps.get_cluster_credentials.outcome == 'success' | |
continue-on-error: true | |
run: | | |
kubectl get pods --all-namespaces | |
- name: Set tenant connection variables | |
if: steps.apply_tenant_group.outcome == 'success' | |
continue-on-error: true | |
working-directory: ./tofu/gcp/test_env | |
run: | | |
echo "FALKORDB_STANDALONE_HOST=$(tofu output -json | jq -r '.ip_address.value')" >> $GITHUB_ENV | |
echo "FALKORDB_STANDALONE_PORT=$(tofu output -json | jq -r '.falkordb_standalone_tenant_redis_port.value')" >> $GITHUB_ENV | |
echo "FALKORDB_SINGLE_ZONE_HOST=$(tofu output -json | jq -r '.ip_address.value')" >> $GITHUB_ENV | |
echo "FALKORDB_SINGLE_ZONE_PORT=$(tofu output -json | jq -r '.falkordb_single_zone_tenant_redis_port.value')" >> $GITHUB_ENV | |
echo "FALKORDB_SINGLE_ZONE_TENANT_NAMESPACE=$(tofu output -json | jq -r '.falkordb_single_zone_tenant_namespace.value')" >> $GITHUB_ENV | |
echo "FALKORDB_PASSWORD=${{ secrets.TF_VAR_FALKORDB_PASSWORD }}" >> $GITHUB_ENV | |
- name: Setup Python environment | |
if: steps.apply_tenant_group.outcome == 'success' | |
id: setup_python | |
continue-on-error: true | |
run: | | |
python3 -m venv .venv | |
source .venv/bin/activate | |
pip install -r requirements.txt | |
- name: Run Standalone tests | |
if: steps.apply_tenant_group.outcome == 'success' && steps.setup_python.outcome == 'success' | |
id: python_tests_standalone | |
continue-on-error: true | |
run: | | |
source .venv/bin/activate | |
pytest -s tofu/gcp/test_env/__tests__/standalone/main.py --hostname ${{ env.FALKORDB_STANDALONE_HOST }} --port ${{ env.FALKORDB_STANDALONE_PORT }} --password ${{ secrets.TF_VAR_FALKORDB_PASSWORD }} | |
- name: Run Replica tests | |
if: steps.apply_tenant_group.outcome == 'success' && steps.setup_python.outcome == 'success' | |
id: python_tests_replica | |
continue-on-error: true | |
run: | | |
source .venv/bin/activate | |
pytest -s tofu/gcp/test_env/__tests__/replica/main.py --hostname ${{ env.FALKORDB_SINGLE_ZONE_HOST }} --port ${{ env.FALKORDB_SINGLE_ZONE_PORT }} --namespace ${{ env.FALKORDB_SINGLE_ZONE_TENANT_NAMESPACE }} --password ${{ secrets.TF_VAR_FALKORDB_PASSWORD }} | |
- name: Destroy GCP Test Environment | |
if: always() | |
continue-on-error: true | |
working-directory: ./tofu/gcp/test_env | |
env: | |
TF_VAR_project_id: ${{ vars.GCP_PROJECT_ID }} | |
TF_VAR_region: ${{ vars.GCP_REGION }} | |
TF_VAR_tenant_group_name: ${{ env.tenant_group_name }} | |
TF_VAR_force_destroy_backup_bucket: ${{ vars.GCP_FORCE_DESTROY_BACKUP_BUCKET }} | |
TF_VAR_subnet_cidr: ${{ vars.GCP_SUBNET_CIDR }} | |
TF_VAR_ip_range_pods: ${{ vars.GCP_IP_RANGE_PODS }} | |
TF_VAR_ip_range_services: ${{ vars.GCP_IP_RANGE_SERVICES }} | |
TF_VAR_tenant_provision_sa: ${{ vars.GCP_TENANT_PROVISION_SA }} | |
TF_VAR_backup_retention_policy_days: ${{ vars.GCP_BACKUP_RETENTION_POLICY_DAYS }} | |
TF_VAR_cluster_deletion_protection: ${{ vars.GCP_CLUSTER_DELETION_PROTECTION }} | |
TF_VAR_tenant_name: ${{ env.tenant_name }} | |
TF_VAR_falkordb_password: ${{ secrets.TF_VAR_FALKORDB_PASSWORD }} | |
TF_VAR_falkordb_cpu: ${{ vars.TF_VAR_FALKORDB_CPU }} | |
TF_VAR_falkordb_memory: ${{ vars.TF_VAR_FALKORDB_MEMORY }} | |
TF_VAR_persistence_size: ${{ vars.TF_VAR_PERSISTANCE_SIZE }} | |
TF_VAR_falkordb_replicas: ${{ vars.TF_VAR_FALKORDB_REPLICAS }} | |
TF_VAR_backup_schedule: ${{ vars.TF_VAR_BACKUP_SCHEDULE }} | |
TF_VAR_dns_domain: "${{ env.tenant_name }}.${{ vars.TF_VAR_DNS_DOMAIN }}" | |
run: | | |
tofu destroy -auto-approve | |
- name: Fail if tests did not pass | |
if: always() | |
run: | | |
# Check if python tests conclusion is success | |
if [ ${{ steps.python_tests_standalone.outcome }} != 'success' ] || [ ${{ steps.python_tests_replica.outcome }} != 'success' ]; then | |
exit 1 | |
fi |