BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.
Python ai-agentsai-memoryknowledge-graphknowledge-managementknowledge-representationreccomendation-system
test(terraform): added placeholder files
Christian5a7059e56dc6
diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yamlnew file mode 100644index 0000000..4f30e2d--- /dev/null+++ b/.github/workflows/deploy.yaml@@ -0,0 +1,62 @@+name: Deploy per-user on tag++on:+ push:+ tags:+ - "brainapi@*@*@*@v*"++jobs:+ deploy:+ runs-on: ubuntu-latest+ permissions:+ id-token: write+ contents: read+ env:+ TF_IN_AUTOMATION: "true"+ steps:+ - uses: actions/checkout@v4+ - name: Extract tag parts+ id: parts+ run: |+ TAG="${GITHUB_REF_NAME}"+ # brainapi@alice@europe-west8@[email protected]+ IFS='@' read -r APP USER REGION PLAN VERSION <<< "$TAG"+ echo "user_slug=$USER" >> $GITHUB_OUTPUT+ echo "region=$REGION" >> $GITHUB_OUTPUT+ echo "plan=$PLAN" >> $GITHUB_OUTPUT+ echo "version=$VERSION" >> $GITHUB_OUTPUT+ - name: Setup Terraform+ uses: hashicorp/setup-terraform@v3+ with:+ terraform_version: 1.8.5+ cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} # if using Terraform Cloud+ - name: GCP Auth (OIDC)+ uses: google-github-actions/auth@v2+ with:+ workload_identity_provider: ${{ secrets.GCP_WIF_PROVIDER }}+ service_account: ${{ secrets.GCP_SA_EMAIL }}+ - name: Configure gcloud (for provider ADC)+ uses: google-github-actions/setup-gcloud@v2+ - name: Terraform init+ working-directory: infra+ run: terraform init+ - name: Select/Create workspace+ working-directory: infra+ run: |+ WS="${{ steps.parts.outputs.user_slug }}-${{ steps.parts.outputs.region }}"+ terraform workspace select "$WS" || terraform workspace new "$WS"+ - name: Terraform apply+ working-directory: infra+ env:+ TF_VAR_gcp_project: ${{ secrets.GCP_PROJECT }}+ TF_VAR_cloudflare_api_token: ${{ secrets.CF_API_TOKEN }}+ TF_VAR_ghcr_username: ${{ secrets.GHCR_USER }}+ TF_VAR_ghcr_token: ${{ secrets.GHCR_TOKEN }}+ TF_VAR_zone_id: ${{ secrets.CF_ZONE_ID }}+ run: |+ terraform apply -auto-approve \+ -var "user_slug=${{ steps.parts.outputs.user_slug }}" \+ -var "region=${{ steps.parts.outputs.region }}" \+ -var "plan=${{ steps.parts.outputs.plan }}" \+ -var "version=${{ steps.parts.outputs.version }}" \+ -var-file="plans/${{ steps.parts.outputs.plan }}.tfvars"diff --git a/deploy/terraform/infra/backend.tf b/deploy/terraform/infra/backend.tfnew file mode 100644index 0000000..b453881--- /dev/null+++ b/deploy/terraform/infra/backend.tf@@ -0,0 +1,6 @@+terraform {+ cloud {+ organization = "lumen-labs"+ workspaces { name = "brainapi-multi-tenant" }+ }+}diff --git a/deploy/terraform/infra/main.tf b/deploy/terraform/infra/main.tfnew file mode 100644index 0000000..4f0e32b--- /dev/null+++ b/deploy/terraform/infra/main.tf@@ -0,0 +1,55 @@+locals {+ workspace = terraform.workspace # if you choose one-workspace-per-user+ app_name = "brainapi"+ machine = var.plan == "pro" ? var.machine_type_pro : var.machine_type_small+ fqdn = "${var.subdomain_prefix}-${var.user_slug}.${var.domain}"+ name_prefix= "${local.app_name}-${var.user_slug}"+ image_ref = "${var.base_image}:${var.version}"+}++module "network" {+ source = "./modules/network"+ name_prefix = local.name_prefix+ region = var.region+ labels = var.labels+}++module "secrets" {+ source = "./modules/secrets"+ name_prefix = local.name_prefix+ ghcr_user = var.ghcr_username+ ghcr_token = var.ghcr_token+}++module "vm" {+ source = "./modules/vm_docker"+ name_prefix = local.name_prefix+ region = var.region+ subnet_selflink = module.network.subnet_selflink+ machine_type = local.machine+ fqdn = local.fqdn+ image_ref = local.image_ref+ ghcr_user = var.ghcr_username+ ghcr_token = var.ghcr_token+ labels = var.labels+ enable_sql = var.enable_sql+ # If SQL enabled, provide connection info via metadata/env+ db_conn_str = var.enable_sql ? module.sql.conn_str : null+}++module "dns" {+ source = "./modules/dns_cloudflare"+ zone_id = var.zone_id+ name = "${var.subdomain_prefix}-${var.user_slug}"+ domain = var.domain+ target_ip= module.vm.public_ip+ ttl = 120+}++module "sql" {+ count = var.enable_sql ? 1 : 0+ source = "./modules/sql"+ name_prefix = local.name_prefix+ region = var.region+ labels = var.labels+}diff --git a/deploy/terraform/infra/modules/dns_cloudflare/main.tf b/deploy/terraform/infra/modules/dns_cloudflare/main.tfnew file mode 100644index 0000000..f5be573--- /dev/null+++ b/deploy/terraform/infra/modules/dns_cloudflare/main.tf@@ -0,0 +1,16 @@+variable "zone_id" { type = string }+variable "name" { type = string }+variable "domain" { type = string }+variable "target_ip"{ type = string }+variable "ttl" { type = number default = 120 }++resource "cloudflare_record" "a" {+ zone_id = var.zone_id+ name = "${var.name}.${var.domain}"+ type = "A"+ value = var.target_ip+ ttl = var.ttl+ proxied = true+}++output "fqdn" { value = cloudflare_record.a.hostname }diff --git a/deploy/terraform/infra/modules/network/main.tf b/deploy/terraform/infra/modules/network/main.tfnew file mode 100644index 0000000..a260d9f--- /dev/null+++ b/deploy/terraform/infra/modules/network/main.tf@@ -0,0 +1,21 @@+resource "google_compute_network" "vpc" {+ name = "${var.name_prefix}-vpc"+ auto_create_subnetworks = false+}++resource "google_compute_subnetwork" "subnet" {+ name = "${var.name_prefix}-subnet"+ ip_cidr_range = "10.42.0.0/24"+ region = var.region+ network = google_compute_network.vpc.id+}++resource "google_compute_firewall" "allow_http" {+ name = "${var.name_prefix}-allow-http"+ network = google_compute_network.vpc.name++ allow { protocol = "tcp", ports = ["80", "443", "8080", "22"] }+ source_ranges = ["0.0.0.0/0"]+}++output "subnet_selflink" { value = google_compute_subnetwork.subnet.self_link }diff --git a/deploy/terraform/infra/modules/vm_docker/main.tf b/deploy/terraform/infra/modules/vm_docker/main.tfnew file mode 100644index 0000000..79a7de1--- /dev/null+++ b/deploy/terraform/infra/modules/vm_docker/main.tf@@ -0,0 +1,35 @@+resource "google_compute_instance" "vm" {+ name = "${var.name_prefix}-vm"+ machine_type = var.machine_type+ zone = "${var.region}-a"++ boot_disk {+ initialize_params {+ image = "ubuntu-os-cloud/ubuntu-2204-jammy-v20241001"+ size = 30+ type = "pd-balanced"+ }+ }++ network_interface {+ subnetwork = var.subnet_selflink+ access_config {} # ephemeral public IP+ }++ metadata = {+ user-data = templatefile("${path.module}/templates/cloud-init.yaml.tftpl", {+ fqdn = var.fqdn+ image_ref = var.image_ref+ ghcr_user = var.ghcr_user+ ghcr_token = var.ghcr_token+ enable_sql = var.enable_sql+ db_conn_str = var.db_conn_str+ })+ }++ labels = var.labels+}++output "public_ip" {+ value = google_compute_instance.vm.network_interface[0].access_config[0].nat_ip+}diff --git a/deploy/terraform/infra/modules/vm_docker/templates/cloud-init.yaml.tftpl b/deploy/terraform/infra/modules/vm_docker/templates/cloud-init.yaml.tftplnew file mode 100644index 0000000..4430c3b--- /dev/null+++ b/deploy/terraform/infra/modules/vm_docker/templates/cloud-init.yaml.tftpl@@ -0,0 +1,31 @@+#cloud-config+package_update: true+packages:+ - docker.io+ - docker-compose+runcmd:+ # GHCR login+ - echo "${ghcr_token}" | docker login ghcr.io -u "${ghcr_user}" --password-stdin+ # pull & run+ - docker pull ${image_ref}+ - mkdir -p /opt/brainapi+ - |+ cat >/opt/brainapi/.env <<'EOF'+ PORT=8080+ FQDN=${fqdn}+ %{ if enable_sql ~}+ DATABASE_URL=${db_conn_str}+ %{ endif ~}+ EOF+ - |+ cat >/opt/brainapi/docker-compose.yml <<'EOF'+ services:+ app:+ image: ${image_ref}+ env_file: /opt/brainapi/.env+ ports: ["8080:8080"]+ restart: always+ EOF+ - systemctl enable docker+ - systemctl start docker+ - docker compose -f /opt/brainapi/docker-compose.yml up -ddiff --git a/deploy/terraform/infra/modules/vm_docker/variables.tf b/deploy/terraform/infra/modules/vm_docker/variables.tfnew file mode 100644index 0000000..2afe85e--- /dev/null+++ b/deploy/terraform/infra/modules/vm_docker/variables.tf@@ -0,0 +1,11 @@+variable "name_prefix" { type = string }+variable "region" { type = string }+variable "subnet_selflink" { type = string }+variable "machine_type" { type = string }+variable "fqdn" { type = string }+variable "image_ref" { type = string }+variable "ghcr_user" { type = string }+variable "ghcr_token" { type = string }+variable "labels" { type = map(string) default = {} }+variable "enable_sql" { type = bool }+variable "db_conn_str" { type = string, default = null }diff --git a/deploy/terraform/infra/plans/pro.tfvars b/deploy/terraform/infra/plans/pro.tfvarsnew file mode 100644index 0000000..a9d14c5--- /dev/null+++ b/deploy/terraform/infra/plans/pro.tfvars@@ -0,0 +1,2 @@+plan = "pro"+enable_sql = truediff --git a/deploy/terraform/infra/plans/small.tfvars b/deploy/terraform/infra/plans/small.tfvarsnew file mode 100644index 0000000..a272762--- /dev/null+++ b/deploy/terraform/infra/plans/small.tfvars@@ -0,0 +1,2 @@+plan = "small"+enable_sql = falsediff --git a/deploy/terraform/infra/providers.tf b/deploy/terraform/infra/providers.tfnew file mode 100644index 0000000..2469090--- /dev/null+++ b/deploy/terraform/infra/providers.tf@@ -0,0 +1,8 @@+provider "google" {+ project = var.gcp_project+ region = var.region+}++provider "cloudflare" {+ api_token = var.cloudflare_api_token+}diff --git a/deploy/terraform/infra/user.auto.tfvars.json b/deploy/terraform/infra/user.auto.tfvars.jsonnew file mode 100644index 0000000..8f88634--- /dev/null+++ b/deploy/terraform/infra/user.auto.tfvars.json@@ -0,0 +1,7 @@+{+ "gcp_project": "lumenlabs-prod",+ "domain": "example.com",+ "subdomain_prefix": "app",+ "base_image": "ghcr.io/lumen-labs/brainapi",+ "labels": { "service": "brainapi", "env": "prod" }+}diff --git a/deploy/terraform/infra/variables.tf b/deploy/terraform/infra/variables.tfnew file mode 100644index 0000000..af5d371--- /dev/null+++ b/deploy/terraform/infra/variables.tf@@ -0,0 +1,15 @@+variable "gcp_project" { type = string }+variable "region" { type = string }+variable "user_slug" { type = string } # e.g., "alice"+variable "plan" { type = string } # "small" | "pro"+variable "version" { type = string } # e.g., "v0.4.2"+variable "domain" { type = string } # e.g., "example.com"+variable "zone_id" { type = string } # Cloudflare zone id+variable "ghcr_username" { type = string }+variable "ghcr_token" { type = string } # GitHub PAT or fine-grained token+variable "base_image" { type = string } # e.g., "ghcr.io/lumen-labs/brainapi"+variable "enable_sql" { type = bool default = false }+variable "machine_type_small" { type = string default = "e2-standard-2" }+variable "machine_type_pro" { type = string default = "e2-standard-4" }+variable "subdomain_prefix" { type = string default = "app" } # app-<user>+variable "labels" { type = map(string) default = {} }diff --git a/deploy/terraform/infra/versions.tf b/deploy/terraform/infra/versions.tfnew file mode 100644index 0000000..54036f0--- /dev/null+++ b/deploy/terraform/infra/versions.tf@@ -0,0 +1,8 @@+terraform {+ required_version = ">= 1.8.0"+ required_providers {+ google = { source = "hashicorp/google", version = "~> 5.40" }+ cloudflare = { source = "cloudflare/cloudflare", version = "~> 4.40" }+ random = { source = "hashicorp/random", version = "~> 3.6" }+ }+}