From b8cc0cd11bc2104acaadfbddc303205b567c9baf Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 24 Aug 2024 22:41:32 -0600 Subject: [PATCH] refactor(template): add domain to supabase template --- .../templates/supabase/docker-compose.yml | 61 +++++++++++++------ apps/dokploy/templates/supabase/index.ts | 18 ++++-- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/apps/dokploy/templates/supabase/docker-compose.yml b/apps/dokploy/templates/supabase/docker-compose.yml index 5be8158c0..e1e187fde 100644 --- a/apps/dokploy/templates/supabase/docker-compose.yml +++ b/apps/dokploy/templates/supabase/docker-compose.yml @@ -15,7 +15,13 @@ services: - dokploy-network restart: unless-stopped healthcheck: - test: [ "CMD", "node", "-e", "require('http').get('http://localhost:3000/api/profile', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})" ] + test: + [ + "CMD", + "node", + "-e", + "require('http').get('http://localhost:3000/api/profile', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})", + ] timeout: 5s interval: 5s retries: 3 @@ -57,11 +63,6 @@ services: expose: - 8000 - 8443 - labels: - - traefik.enable=true - - traefik.http.routers.frontend-app.rule=Host(`${SUPABASE_HOST}`) - - traefik.http.routers.frontend-app.entrypoints=web - - traefik.http.services.frontend-app.loadbalancer.server.port=${KONG_HTTP_PORT} depends_on: analytics: condition: service_healthy @@ -93,7 +94,15 @@ services: analytics: condition: service_healthy healthcheck: - test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9999/health" ] + test: + [ + "CMD", + "wget", + "--no-verbose", + "--tries=1", + "--spider", + "http://localhost:9999/health", + ] timeout: 5s interval: 5s retries: 3 @@ -145,9 +154,6 @@ services: # GOTRUE_HOOK_PASSWORD_VERIFICATION_ATTEMPT_ENABLED="true" # GOTRUE_HOOK_PASSWORD_VERIFICATION_ATTEMPT_URI="pg-functions://postgres/public/password_verification_attempt" - - - rest: container_name: supabase-rest image: postgrest/postgrest:v12.2.0 @@ -183,7 +189,18 @@ services: analytics: condition: service_healthy healthcheck: - test: [ "CMD", "curl", "-sSfL", "--head", "-o", "/dev/null", "-H", "Authorization: Bearer ${ANON_KEY}", "http://localhost:4000/api/tenants/realtime-dev/health" ] + test: + [ + "CMD", + "curl", + "-sSfL", + "--head", + "-o", + "/dev/null", + "-H", + "Authorization: Bearer ${ANON_KEY}", + "http://localhost:4000/api/tenants/realtime-dev/health", + ] timeout: 5s interval: 5s retries: 3 @@ -195,7 +212,7 @@ services: DB_USER: supabase_admin DB_PASSWORD: ${POSTGRES_PASSWORD} DB_NAME: ${POSTGRES_DB} - DB_AFTER_CONNECT_QUERY: 'SET search_path TO _realtime' + DB_AFTER_CONNECT_QUERY: "SET search_path TO _realtime" DB_ENC_KEY: supabaserealtime API_JWT_SECRET: ${JWT_SECRET} SECRET_KEY_BASE: UpNVntn3cDxHJpq99YMc1T1AQgQpc8kfYTuRgBiYa15BLrx8etQoXz3gZv1/u2oq @@ -220,7 +237,15 @@ services: imgproxy: condition: service_started healthcheck: - test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5000/status" ] + test: + [ + "CMD", + "wget", + "--no-verbose", + "--tries=1", + "--spider", + "http://localhost:5000/status", + ] timeout: 5s interval: 5s retries: 3 @@ -249,7 +274,7 @@ services: networks: - dokploy-network healthcheck: - test: [ "CMD", "imgproxy", "health" ] + test: ["CMD", "imgproxy", "health"] timeout: 5s interval: 5s retries: 3 @@ -311,7 +336,7 @@ services: networks: - dokploy-network healthcheck: - test: [ "CMD", "curl", "http://localhost:4000/health" ] + test: ["CMD", "curl", "http://localhost:4000/health"] timeout: 5s interval: 5s retries: 10 @@ -410,13 +435,12 @@ services: healthcheck: test: [ - "CMD", "wget", "--no-verbose", "--tries=1", "--spider", - "http://vector:9001/health" + "http://vector:9001/health", ] timeout: 5s interval: 5s @@ -426,12 +450,11 @@ services: - ${DOCKER_SOCKET_LOCATION}:/var/run/docker.sock:ro environment: LOGFLARE_API_KEY: ${LOGFLARE_API_KEY} - command: [ "--config", "etc/vector/vector.yml" ] + command: ["--config", "etc/vector/vector.yml"] volumes: db-config: - networks: dokploy-network: external: true diff --git a/apps/dokploy/templates/supabase/index.ts b/apps/dokploy/templates/supabase/index.ts index 2456f015f..6922c77fb 100644 --- a/apps/dokploy/templates/supabase/index.ts +++ b/apps/dokploy/templates/supabase/index.ts @@ -1,9 +1,9 @@ -import { createHmac, randomBytes } from "node:crypto"; +import { createHmac } from "node:crypto"; import { + type DomainSchema, type Schema, type Template, generateBase64, - generateHash, generatePassword, generateRandomDomain, } from "../utils"; @@ -61,8 +61,7 @@ export function generateSupabaseServiceJWT(secret: string): string { } export function generate(schema: Schema): Template { - const mainServiceHash = generateHash(schema.projectName); - const randomDomain = generateRandomDomain(schema); + const mainDomain = generateRandomDomain(schema); const postgresPassword = generatePassword(32); const jwtSecret = generateBase64(32); @@ -71,9 +70,16 @@ export function generate(schema: Schema): Template { const annonKey = generateSupabaseAnonJWT(jwtSecret); const serviceRoleKey = generateSupabaseServiceJWT(jwtSecret); + const domains: DomainSchema[] = [ + { + serviceName: "kong", + host: mainDomain, + port: 8000, + }, + ]; const envs = [ - `SUPABASE_HOST=${randomDomain}`, + `SUPABASE_HOST=${mainDomain}`, `POSTGRES_PASSWORD=${postgresPassword}`, `JWT_SECRET=${jwtSecret}`, `ANON_KEY=${annonKey}`, @@ -114,7 +120,6 @@ export function generate(schema: Schema): Template { "DOCKER_SOCKET_LOCATION=/var/run/docker.sock", "GOOGLE_PROJECT_ID=GOOGLE_PROJECT_ID", "GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER", - `HASH=${mainServiceHash}`, ]; const mounts: Template["mounts"] = [ @@ -983,6 +988,7 @@ sinks: ]; return { + domains, envs, mounts, };