diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..8fac02f --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,7 @@ +ARG VARIANT=18-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:${VARIANT} +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +RUN npm install -g bun \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f4a3802 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Comfy Deploy Dev", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "postCreateCommand": "cd web && bun install && bun run migrate-local", + "customizations": { + "vscode": { + "extensions": [ + "biomejs.biome", + "formulahendry.auto-rename-tag", + "bradlc.vscode-tailwindcss", + "stivo.tailwind-fold" + ] + } + } +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..75c4186 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,48 @@ +version: '3' + +services: + app: + build: + context: . + dockerfile: Dockerfile + + environment: + VSCODE_DEV_CONTAINER: true + + volumes: + # Forwards the local Docker socket to the container. + - /var/run/docker.sock:/var/run/docker-host.sock + # Update this to wherever you want VS Code to mount the folder of your project + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + # entrypoint: /usr/local/share/docker-init.sh + command: sleep infinity + postgres: + image: "postgres:15.2-alpine" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: verceldb + ports: + - "5480:5432" + pg_proxy: + image: ghcr.io/neondatabase/wsproxy:latest + environment: + APPEND_PORT: "postgres:5432" + ALLOW_ADDR_REGEX: ".*" + LOG_TRAFFIC: "true" + ports: + - "5481:80" + depends_on: + - postgres + localstack: + image: localstack/localstack:latest + environment: + SERVICES: s3 + ports: + - 4566:4566 + volumes: + - ../web/aws:/etc/localstack/init/ready.d + - ../web/aws:/app/web/aws + diff --git a/.vscode/settings.json b/.vscode/settings.json index 4e9d4e3..f360dc6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,8 +2,8 @@ "typescript.tsdk": "node_modules/typescript/lib", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "quickfix.biome": true, - "source.organizeImports.biome": true + "quickfix.biome": "explicit", + "source.organizeImports.biome": "explicit" }, "typescript.preferences.importModuleSpecifier": "non-relative", "spellright.language": ["en"], diff --git a/web/biome.json b/web/biome.json index 8a54b26..9926aab 100644 --- a/web/biome.json +++ b/web/biome.json @@ -9,6 +9,11 @@ "recommended": true } }, + "json": { + "parser": { + "allowComments": true + } + }, "vcs": { "enabled": true, "clientKind": "git", diff --git a/web/migrate.mts b/web/migrate.mts index d989afe..5f4df12 100644 --- a/web/migrate.mts +++ b/web/migrate.mts @@ -12,10 +12,11 @@ let sslMode: string | boolean = process.env.SSL || "require"; if (sslMode === "false") sslMode = false; -console.log(migrationsFolderName, sslMode); +let connectionString = process.env.POSTGRES_URL!; + +const isDevContainer = process.env.VSCODE_DEV_CONTAINER !== undefined; +if (isDevContainer) connectionString = connectionString.replace("localhost","host.docker.internal") -const connectionString = process.env.POSTGRES_URL!; -console.log(connectionString); const sql = postgres(connectionString, { max: 1, ssl: sslMode as any }); const db = drizzle(sql, { logger: true, diff --git a/web/src/db/db.ts b/web/src/db/db.ts index 8d7379f..33aa553 100644 --- a/web/src/db/db.ts +++ b/web/src/db/db.ts @@ -2,10 +2,18 @@ import * as schema from "./schema"; import { neonConfig, Pool } from "@neondatabase/serverless"; import { drizzle as neonDrizzle } from "drizzle-orm/neon-serverless"; +const isDevContainer = process.env.REMOTE_CONTAINERS !== undefined; + // if we're running locally if (process.env.VERCEL_ENV !== "production") { // Set the WebSocket proxy to work with the local instance - neonConfig.wsProxy = (host) => `${host}:5481/v1`; + if (isDevContainer) { + // Running inside a VS Code devcontainer + neonConfig.wsProxy = (host) => `host.docker.internal:5481/v1`; + } else { + // Not running inside a VS Code devcontainer + neonConfig.wsProxy = (host) => `${host}:5481/v1`; + } // Disable all authentication and encryption neonConfig.useSecureWebSocket = false; neonConfig.pipelineTLS = false;