Skip to content

Commit

Permalink
Add DB string as connection string.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang committed May 23, 2024
1 parent 823dce5 commit 1877cd6
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 81 deletions.
6 changes: 3 additions & 3 deletions clouddeploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ 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]
---

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
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

type Config struct {
ProjectID string
DripEnv string
SelfOrigin string
ProjectID string
DripEnv string
}
9 changes: 2 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 5 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
47 changes: 0 additions & 47 deletions run-service-dev.yaml

This file was deleted.

19 changes: 14 additions & 5 deletions run-service-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
27 changes: 27 additions & 0 deletions run-service-staging.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
6 changes: 3 additions & 3 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 1877cd6

Please sign in to comment.