From 7c347485410b5192381babacafc122ee64f99807 Mon Sep 17 00:00:00 2001 From: Charles-Meldhine Madi Mnemoi Date: Mon, 19 May 2025 19:34:16 +0200 Subject: [PATCH 1/3] Revert "ci: Fix DB provisionning (#11)" This reverts commit 82cb2ac61bcf2ff60dd49c728fe9e8f982e3a2b9. --- .github/workflows/continuous_delivery.yaml | 2 +- terraform/database.tf | 2 +- terraform/variables.tf | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous_delivery.yaml b/.github/workflows/continuous_delivery.yaml index a241ed2..eb711fc 100644 --- a/.github/workflows/continuous_delivery.yaml +++ b/.github/workflows/continuous_delivery.yaml @@ -2,7 +2,7 @@ name: Continuous Delivery on: workflow_run: - workflows: ["Continous Delivery (Infrastructure)", "Continuous Integration"] + workflows: ["Continuous Integration", "Continous Delivery (Infrastructure)"] types: - completed workflow_dispatch: diff --git a/terraform/database.tf b/terraform/database.tf index 526e307..517a643 100644 --- a/terraform/database.tf +++ b/terraform/database.tf @@ -4,7 +4,7 @@ resource "google_sql_database_instance" "sql_instance_sightcall_qa_api" { database_version = "POSTGRES_17" settings { - tier = "db-g1-small" + tier = "db-f1-micro" ip_configuration { ipv4_enabled = false diff --git a/terraform/variables.tf b/terraform/variables.tf index 7f3065e..712053c 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -26,8 +26,7 @@ variable "enabled_apis" { "iam.googleapis.com", "serviceusage.googleapis.com", "logging.googleapis.com", - "monitoring.googleapis.com", - "vpcaccess.googleapis.com" + "monitoring.googleapis.com" ] } From 8860d82bd889fe6473e3a7a07165347cc7765712 Mon Sep 17 00:00:00 2001 From: Charles-Meldhine Madi Mnemoi Date: Mon, 19 May 2025 19:34:19 +0200 Subject: [PATCH 2/3] Revert "ci: add PostgreSQL resource (#10)" This reverts commit 758e196996b1403227c3924cf3e630d492996deb. --- .github/workflows/continuous_delivery.yaml | 4 +-- .github/workflows/update_infrastructure.yaml | 2 +- .vscode/settings.json | 5 ++- terraform/cloud_run.tf | 15 +-------- terraform/database.tf | 32 -------------------- terraform/locals.tf | 9 ------ terraform/terraform.tfvars.example | 2 +- terraform/variables.tf | 6 ---- terraform/vpc.tf | 22 -------------- 9 files changed, 7 insertions(+), 90 deletions(-) delete mode 100644 terraform/database.tf delete mode 100644 terraform/locals.tf delete mode 100644 terraform/vpc.tf diff --git a/.github/workflows/continuous_delivery.yaml b/.github/workflows/continuous_delivery.yaml index eb711fc..77caed6 100644 --- a/.github/workflows/continuous_delivery.yaml +++ b/.github/workflows/continuous_delivery.yaml @@ -74,8 +74,8 @@ jobs: - name: Deploy with Cloud Run run: | - gcloud run deploy sightcall-qa-api \ - --image=docker.io/${{ vars.DOCKERHUB_USERNAME }}/sightcall-qa-api:latest \ + gcloud run deploy fastapi-api \ + --image=docker.io/${{ vars.DOCKERHUB_USERNAME }}/sightcall-qa-api:${{ steps.get_hash.outputs.hash }} \ --platform=managed \ --region=${{ vars.GCP_REGION }} \ --allow-unauthenticated \ diff --git a/.github/workflows/update_infrastructure.yaml b/.github/workflows/update_infrastructure.yaml index 4abba66..ce9362c 100644 --- a/.github/workflows/update_infrastructure.yaml +++ b/.github/workflows/update_infrastructure.yaml @@ -27,11 +27,11 @@ jobs: - name: Setup terraform.tfvars run: | cat < terraform.tfvars - db_password = "${{ secrets.DB_PASSWORD }}" project_id = "${{ secrets.TF_PROJECT_ID }}" terraform_sa_email = "${{ secrets.TF_SA_EMAIL }}" cloud_run_env_vars = { + DATABASE_URL = "${{ secrets.DATABASE_URL }}" ENV = "production" OPENAI_API_KEY = "${{ secrets.OPENAI_API_KEY_PROD }}" } diff --git a/.vscode/settings.json b/.vscode/settings.json index b301d46..fa77965 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "editor.defaultFormatter": "charliermarsh.ruff" }, "python.analysis.autoImportCompletions": true, - "python.languageServer": "None", + "python.languageServer": "Pylance", "python.testing.pytestArgs": [ "tests" ], @@ -57,6 +57,5 @@ "username": "postgres", "password": "password" } - ], - "windsurfPyright.disableLanguageServices": true + ] } diff --git a/terraform/cloud_run.tf b/terraform/cloud_run.tf index d45a8fd..6ed7bce 100644 --- a/terraform/cloud_run.tf +++ b/terraform/cloud_run.tf @@ -4,18 +4,10 @@ resource "google_service_account" "cloudrun_sa" { } resource "google_cloud_run_service" "fastapi" { - name = "sightcall-qa-api" + name = "fastapi-api" location = var.region project = var.project_id - metadata { - annotations = { - "run.googleapis.com/cloudsql-instances" = google_sql_database_instance.sql_instance_sightcall_qa_api.connection_name - "run.googleapis.com/vpc-access-connector" = google_vpc_access_connector.serverless_connector.id - "run.googleapis.com/vpc-access-egress" = "all-traffic" - } - } - template { spec { service_account_name = google_service_account.cloudrun_sa.email @@ -34,11 +26,6 @@ resource "google_cloud_run_service" "fastapi" { value = env.value } } - - env { - name = "DATABASE_URL" - value = local.database_url - } } } diff --git a/terraform/database.tf b/terraform/database.tf deleted file mode 100644 index 517a643..0000000 --- a/terraform/database.tf +++ /dev/null @@ -1,32 +0,0 @@ -resource "google_sql_database_instance" "sql_instance_sightcall_qa_api" { - name = "sightcall-qa-api-db" - region = var.region - database_version = "POSTGRES_17" - - settings { - tier = "db-f1-micro" - - ip_configuration { - ipv4_enabled = false - private_network = google_compute_network.app_network.self_link - } - - database_flags { - name = "cloudsql.enable_pgvector" - value = "on" - } - } - - deletion_protection = false -} - -resource "google_sql_database" "vectordb" { - name = "sightcall_qa_api_vectordb" - instance = google_sql_database_instance.sql_instance_sightcall_qa_api.name -} - -resource "google_sql_user" "db_user" { - name = "sightcall_qa_api_user" - instance = google_sql_database_instance.sql_instance_sightcall_qa_api.name - password_wo = var.db_password -} diff --git a/terraform/locals.tf b/terraform/locals.tf deleted file mode 100644 index a1fc8cb..0000000 --- a/terraform/locals.tf +++ /dev/null @@ -1,9 +0,0 @@ -locals { - database_url = format( - "postgresql://%s:%s@/%s?host=/cloudsql/%s", - google_sql_user.db_user.name, - var.db_password, - google_sql_database.vectordb.name, - google_sql_database_instance.sql_instance_sightcall_qa_api.connection_name - ) -} diff --git a/terraform/terraform.tfvars.example b/terraform/terraform.tfvars.example index 45a2af7..89d91ba 100644 --- a/terraform/terraform.tfvars.example +++ b/terraform/terraform.tfvars.example @@ -1,8 +1,8 @@ -db_password = "password" project_id = "sightcall-qa-api" terraform_sa_email = "terraform@example.iam.gserviceaccount.com" cloud_run_env_vars = { + DATABASE_URL = "postgresql://postgres:password@vector_db:5432/vectordb" ENV = "production" OPENAI_API_KEY = "sk-" } \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 712053c..7b366a0 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -9,12 +9,6 @@ variable "cloud_run_env_vars" { default = {} } -variable "db_password" { - type = string - description = "Password for the database" - sensitive = true -} - variable "enabled_apis" { type = list(string) default = [ diff --git a/terraform/vpc.tf b/terraform/vpc.tf deleted file mode 100644 index f821634..0000000 --- a/terraform/vpc.tf +++ /dev/null @@ -1,22 +0,0 @@ -resource "google_compute_network" "app_network" { - name = "sightcall-qa-api-network" - auto_create_subnetworks = false -} - -resource "google_compute_subnetwork" "app_subnet" { - name = "sightcall-qa-api-subnet" - ip_cidr_range = "10.8.0.0/28" - region = var.region - network = google_compute_network.app_network.id -} - -resource "google_vpc_access_connector" "serverless_connector" { - name = "sightcall-qa-api-serverless-connector" - region = var.region - network = google_compute_network.app_network.name - ip_cidr_range = "10.8.0.0/28" - - lifecycle { - create_before_destroy = true - } -} \ No newline at end of file From c63891a8447bd5d8aa0b223b9ea75b9efa8377ee Mon Sep 17 00:00:00 2001 From: Charles-Meldhine Madi Mnemoi Date: Mon, 19 May 2025 19:40:04 +0200 Subject: [PATCH 3/3] ci: rename Cloud Run service and update CI/CD workflow triggers --- .github/workflows/continuous_delivery.yaml | 14 ++++++++------ .vscode/settings.json | 2 +- terraform/cloud_run.tf | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/continuous_delivery.yaml b/.github/workflows/continuous_delivery.yaml index 77caed6..e2f9062 100644 --- a/.github/workflows/continuous_delivery.yaml +++ b/.github/workflows/continuous_delivery.yaml @@ -10,8 +10,9 @@ on: jobs: release: if: | - github.event.workflow_run.conclusion == 'success' - && github.event.workflow_run.head_branch == 'main' + github.event.workflow_run.conclusion == 'success' && + contains(fromJson('["Continuous Integration", "Continous Delivery (Infrastructure)"]'), github.event.workflow_run.name) && + github.event.workflow_run.event == 'push' name: Create GitHub Release runs-on: ubuntu-24.04 concurrency: release @@ -36,8 +37,9 @@ jobs: runs-on: ubuntu-24.04 needs: release if: | - github.event.workflow_run.conclusion == 'success' - && github.event.workflow_run.head_branch == 'main' + github.event.workflow_run.conclusion == 'success' && + contains(fromJson('["Continuous Integration", "Continous Delivery (Infrastructure)"]'), github.event.workflow_run.name) && + github.event.workflow_run.event == 'push' steps: - name: Checkout code @@ -74,8 +76,8 @@ jobs: - name: Deploy with Cloud Run run: | - gcloud run deploy fastapi-api \ - --image=docker.io/${{ vars.DOCKERHUB_USERNAME }}/sightcall-qa-api:${{ steps.get_hash.outputs.hash }} \ + gcloud run deploy sightcall-qa-api \ + --image=docker.io/${{ vars.DOCKERHUB_USERNAME }}/sightcall-qa-api:latest \ --platform=managed \ --region=${{ vars.GCP_REGION }} \ --allow-unauthenticated \ diff --git a/.vscode/settings.json b/.vscode/settings.json index fa77965..da53936 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,7 @@ "editor.defaultFormatter": "charliermarsh.ruff" }, "python.analysis.autoImportCompletions": true, - "python.languageServer": "Pylance", + "python.languageServer": "None", "python.testing.pytestArgs": [ "tests" ], diff --git a/terraform/cloud_run.tf b/terraform/cloud_run.tf index 6ed7bce..94038c8 100644 --- a/terraform/cloud_run.tf +++ b/terraform/cloud_run.tf @@ -4,7 +4,7 @@ resource "google_service_account" "cloudrun_sa" { } resource "google_cloud_run_service" "fastapi" { - name = "fastapi-api" + name = "sightcall-qa-api" location = var.region project = var.project_id