diff --git a/clouddeploy.yaml b/clouddeploy.yaml index 1c95340..7e2117e 100644 --- a/clouddeploy.yaml +++ b/clouddeploy.yaml @@ -5,8 +5,8 @@ metadata: description: main application pipeline serialPipeline: stages: - - targetId: dev-comfy-backend - profiles: [dev] + - targetId: staging-comfy-backend + profiles: [staging] - targetId: prod-comfy-backend profiles: [prod] --- @@ -14,7 +14,7 @@ serialPipeline: apiVersion: deploy.cloud.google.com/v1 kind: Target metadata: - name: dev-comfy-backend + name: staging-comfy-backend description: Cloud Run development service run: location: projects/dreamboothy/locations/us-central1 diff --git a/config/config.go b/config/config.go index 71e46bd..3508977 100644 --- a/config/config.go +++ b/config/config.go @@ -1,7 +1,6 @@ package config type Config struct { - ProjectID string - DripEnv string - SelfOrigin string + ProjectID string + DripEnv string } diff --git a/docker-compose.yml b/docker-compose.yml index fd98f71..58d76c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,15 +10,10 @@ services: - ./:/app # Ensure this matches the working_dir - $HOME/.config/gcloud/application_default_credentials.json:/tmp/keys/application_default_credentials.json environment: - DB_HOST: host.docker.internal # Since we are running Supabase outside, we need to use the host.docker.internal to connect to the database. - DB_PORT: 54322 - DB_USER: postgres - DB_PASSWORD: postgres - DB_NAME: postgres DRIP_ENV: localdev - GOOGLE_APPLICATION_CREDENTIALS: /tmp/keys/application_default_credentials.json + DB_CONNECTION_STRING: "user=postgres password=postgres host=host.docker.internal port=54322 dbname=postgres" + GOOGLE_APPLICATION_CREDENTIALS: /tmp/keys/application_default_credentials.json # This will be set in prod by GCP. GOOGLE_CLOUD_PROJECT: "dreamboothy-dev" # This will be set in prod by GCP. PROJECT_ID: "dreamboothy-dev" CORS_ORIGIN: "http://localhost:3000" - SELF_ORIGIN: "http://localhost:8080" LOG_LEVEL: info # Set the log level here diff --git a/main.go b/main.go index 6e585d2..9dbd537 100644 --- a/main.go +++ b/main.go @@ -18,23 +18,18 @@ import ( func main() { drip_logging.SetGlobalLogLevel(os.Getenv("LOG_LEVEL")) - host := os.Getenv("DB_HOST") - port := os.Getenv("DB_PORT") - user := os.Getenv("DB_USER") - password := os.Getenv("DB_PASSWORD") - dbname := os.Getenv("DB_NAME") + connection_string := os.Getenv("DB_CONNECTION_STRING") config := config.Config{ - ProjectID: os.Getenv("PROJECT_ID"), - DripEnv: os.Getenv("DRIP_ENV"), - SelfOrigin: os.Getenv("SELF_ORIGIN"), + ProjectID: os.Getenv("PROJECT_ID"), + DripEnv: os.Getenv("DRIP_ENV"), } var dsn string if os.Getenv("DRIP_ENV") == "localdev" { - dsn = fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s sslmode=disable", host, port, user, dbname, password) + dsn = fmt.Sprintf("%s sslmode=disable", connection_string) } else { - dsn = fmt.Sprintf("host=%s port=%s user=%s dbname=%s password=%s", host, port, user, dbname, password) + dsn = connection_string } client, err := ent.Open("postgres", dsn) diff --git a/run-service-dev.yaml b/run-service-dev.yaml deleted file mode 100644 index 58d7d37..0000000 --- a/run-service-dev.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Dev Cloud Run - -apiVersion: serving.knative.dev/v1 -kind: Service -metadata: - name: dev-comfy-backend -spec: - template: - metadata: - annotations: - autoscaling.knative.dev/min-scale: "1" - spec: - containers: - - image: registry-backend-image-substitute - env: - - name: DRIP_ENV - value: staging - - name: DB_USER - value: postgres.zplpzudqewiaavtbnyus - - name: DB_PASSWORD - valueFrom: - secretKeyRef: - key: 1 - name: STAGING-SUPABASE-DB-PASSWORD - - name: DB_PORT - value: 5432 - # Unix socket https://cloud.google.com/sql/docs/postgres/connect-run - - name: DB_HOST - value: aws-0-us-west-1.pooler.supabase.com - - name: DB_NAME - value: postgres - - name: CLOUD_TASK_PROJECT - value: dreamboothy - - name: CLOUD_TASK_REGION - value: us-central1 - - name: CLOUD_CONFIG_PATH - value: /app/gateways/compute/gcp/cloudconfig.yaml - - name: PROJECT_ID - value: dreamboothy - - name: APPROVED_ZONE - value: us-central1-a,us-central1-b,us-central1-c,us-central1-f - - name: CORS_ORIGIN - value: https://drip.art - - name: MACHINE_IMAGE - value: comfy-cloud-template-3 - - name: SELF_ORIGIN - value: https://staging.api.drip.art diff --git a/run-service-prod.yaml b/run-service-prod.yaml index 43a8e5b..bdefc7e 100644 --- a/run-service-prod.yaml +++ b/run-service-prod.yaml @@ -6,13 +6,22 @@ metadata: name: prod-comfy-backend spec: template: + metadata: + annotations: + autoscaling.knative.dev/min-scale: "1" spec: containers: - image: registry-backend-image-substitute env: - name: DRIP_ENV - value: staging - - name: SELF_ORIGIN - value: https://api.drip.art - - name: APPROVED_ZONE - value: us-central1-a,us-central1-b,us-central1-c,us-central1-f \ No newline at end of file + value: prod + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + key: 1 + name: PROD_SUPABASE_CONNECTION_STRING + - name: PROJECT_ID + value: dreamboothy + # TODO(robinhuang): Switch to a list of strings + - name: CORS_ORIGIN + value: https://comfyregistry.org \ No newline at end of file diff --git a/run-service-staging.yaml b/run-service-staging.yaml new file mode 100644 index 0000000..1c4ae6b --- /dev/null +++ b/run-service-staging.yaml @@ -0,0 +1,27 @@ +# Dev Cloud Run + +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: staging-comfy-backend +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/min-scale: "1" + spec: + containers: + - image: registry-backend-image-substitute + env: + - name: DRIP_ENV + value: staging + - name: DB_CONNECTION_STRING + valueFrom: + secretKeyRef: + key: 1 + name: STAGING_SUPABASE_CONNECTION_STRING + - name: PROJECT_ID + value: dreamboothy + # TODO(robinhuang): Switch to a list of strings + - name: CORS_ORIGIN + value: https://staging.comfyregistry.org \ No newline at end of file diff --git a/server/server.go b/server/server.go index b508c3a..d804f74 100644 --- a/server/server.go +++ b/server/server.go @@ -44,11 +44,8 @@ func (s *Server) Start() error { AllowCredentials: true, AllowOriginFunc: func(origin string) (bool, error) { allowedOrigins := []string{ - ".drip.art", // Any subdomain of drip.art ".comfyci.org", // Any subdomain of comfyci.org os.Getenv("CORS_ORIGIN"), // Environment-specific allowed origin - s.Config.SelfOrigin, // Self-origin as configured - "http://127.0.0.1:8188", // Localhost for development ".comfyregistry.org", } diff --git a/skaffold.yaml b/skaffold.yaml index d4a1873..bb8d74a 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -1,12 +1,12 @@ apiVersion: skaffold/v4beta2 kind: Config metadata: - name: deploy-run-quickstart + name: deploy-comfy-backend profiles: -- name: dev +- name: staging manifests: rawYaml: - - run-service-dev.yaml + - run-service-staging.yaml - name: prod manifests: rawYaml: