rsnarsna commited on
Commit ·
b14d4a6
1
Parent(s): cab8aa3
Refactor Docker setup and update environment configurations
Browse files- .gitignore +0 -0
- config/settings/__init__.py +8 -3
- docker-compose.yml +27 -0
- start_dev.ps1 +49 -0
- test_db.py +0 -26
.gitignore
CHANGED
|
Binary files a/.gitignore and b/.gitignore differ
|
|
|
config/settings/__init__.py
CHANGED
|
@@ -27,7 +27,7 @@ SECRET_KEY = 'django-insecure-1fy&f@qu8zuwei(7n3*ta5r=5pp1o84*e4bmk))tl9d_w72cg!
|
|
| 27 |
# SECURITY WARNING: don't run with debug turned on in production!
|
| 28 |
DEBUG = True
|
| 29 |
|
| 30 |
-
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "testserver", ".hf.space", ".
|
| 31 |
|
| 32 |
# Subdomain Tenancy Settings
|
| 33 |
BASE_DOMAIN = env("BASE_DOMAIN", default="localhost:9000")
|
|
@@ -43,7 +43,9 @@ CSRF_TRUSTED_ORIGINS = env.list("CSRF_TRUSTED_ORIGINS", default=[
|
|
| 43 |
"http://localhost:9000",
|
| 44 |
"http://127.0.0.1:9000",
|
| 45 |
"https://*.hf.space",
|
| 46 |
-
"https://*.
|
|
|
|
|
|
|
| 47 |
])
|
| 48 |
|
| 49 |
# Site URL (Used for email verification links)
|
|
@@ -142,7 +144,10 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
|
| 142 |
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
| 143 |
|
| 144 |
DATABASES = {
|
| 145 |
-
'default': env.db(
|
|
|
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
|
| 148 |
|
|
|
|
| 27 |
# SECURITY WARNING: don't run with debug turned on in production!
|
| 28 |
DEBUG = True
|
| 29 |
|
| 30 |
+
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "testserver", ".hf.space", ".ngrok-free.app", ".ngrok.io", ".ngrok-free.dev"])
|
| 31 |
|
| 32 |
# Subdomain Tenancy Settings
|
| 33 |
BASE_DOMAIN = env("BASE_DOMAIN", default="localhost:9000")
|
|
|
|
| 43 |
"http://localhost:9000",
|
| 44 |
"http://127.0.0.1:9000",
|
| 45 |
"https://*.hf.space",
|
| 46 |
+
"https://*.ngrok-free.app",
|
| 47 |
+
"https://*.ngrok.io",
|
| 48 |
+
"https://*.ngrok-free.dev",
|
| 49 |
])
|
| 50 |
|
| 51 |
# Site URL (Used for email verification links)
|
|
|
|
| 144 |
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
| 145 |
|
| 146 |
DATABASES = {
|
| 147 |
+
'default': env.db(
|
| 148 |
+
'DATABASE_URL',
|
| 149 |
+
default=f"sqlite:///{BASE_DIR / 'db.sqlite3'}"
|
| 150 |
+
)
|
| 151 |
}
|
| 152 |
|
| 153 |
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
db:
|
| 5 |
+
image: postgres:16-alpine
|
| 6 |
+
restart: always
|
| 7 |
+
environment:
|
| 8 |
+
POSTGRES_USER: postgres
|
| 9 |
+
POSTGRES_PASSWORD: postgres
|
| 10 |
+
POSTGRES_DB: saas_db
|
| 11 |
+
volumes:
|
| 12 |
+
- ./docker_pg_db:/var/lib/postgresql/data
|
| 13 |
+
ports:
|
| 14 |
+
- "5432:5432"
|
| 15 |
+
|
| 16 |
+
web:
|
| 17 |
+
build: .
|
| 18 |
+
command: python manage.py runserver 0.0.0.0:7860
|
| 19 |
+
volumes:
|
| 20 |
+
- .:/app
|
| 21 |
+
ports:
|
| 22 |
+
- "9000:7860"
|
| 23 |
+
environment:
|
| 24 |
+
- DATABASE_URL=postgres://postgres:postgres@db:5432/saas_db
|
| 25 |
+
- DJANGO_SETTINGS_MODULE=config.settings
|
| 26 |
+
depends_on:
|
| 27 |
+
- db
|
start_dev.ps1
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<#
|
| 2 |
+
.SYNOPSIS
|
| 3 |
+
Starts Docker Desktop, spins up the SaaS application via docker-compose, and launches ngrok.
|
| 4 |
+
#>
|
| 5 |
+
|
| 6 |
+
Write-Host "==========================================" -ForegroundColor Cyan
|
| 7 |
+
Write-Host " Starting SaaS Local Dev Environment" -ForegroundColor Cyan
|
| 8 |
+
Write-Host "==========================================" -ForegroundColor Cyan
|
| 9 |
+
|
| 10 |
+
# 1. Check if Docker is running
|
| 11 |
+
Write-Host "`n[1/3] Checking Docker daemon..." -ForegroundColor Yellow
|
| 12 |
+
$dockerInfo = docker info 2>&1
|
| 13 |
+
if ($LASTEXITCODE -ne 0) {
|
| 14 |
+
Write-Host "Docker is not running. Attempting to start Docker Desktop..." -ForegroundColor Yellow
|
| 15 |
+
$dockerPath = "C:\Program Files\Docker\Docker\Docker Desktop.exe"
|
| 16 |
+
if (Test-Path $dockerPath) {
|
| 17 |
+
Start-Process -FilePath $dockerPath
|
| 18 |
+
Write-Host "Waiting for Docker to start (this may take a minute)..."
|
| 19 |
+
while ($true) {
|
| 20 |
+
Start-Sleep -Seconds 3
|
| 21 |
+
docker info >$null 2>&1
|
| 22 |
+
if ($LASTEXITCODE -eq 0) {
|
| 23 |
+
Write-Host "Docker is now running!" -ForegroundColor Green
|
| 24 |
+
break
|
| 25 |
+
}
|
| 26 |
+
Write-Host "." -NoNewline
|
| 27 |
+
}
|
| 28 |
+
Write-Host ""
|
| 29 |
+
} else {
|
| 30 |
+
Write-Host "Error: Could not find Docker Desktop at $dockerPath. Please start Docker manually." -ForegroundColor Red
|
| 31 |
+
exit 1
|
| 32 |
+
}
|
| 33 |
+
} else {
|
| 34 |
+
Write-Host "Docker is already running!" -ForegroundColor Green
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
# 2. Start Application via Docker Compose
|
| 38 |
+
Write-Host "`n[2/3] Starting Database and Web Application via Docker Compose..." -ForegroundColor Yellow
|
| 39 |
+
docker-compose up -d --build
|
| 40 |
+
if ($LASTEXITCODE -ne 0) {
|
| 41 |
+
Write-Host "Failed to start docker containers!" -ForegroundColor Red
|
| 42 |
+
exit 1
|
| 43 |
+
}
|
| 44 |
+
Write-Host "Containers are up and running!" -ForegroundColor Green
|
| 45 |
+
|
| 46 |
+
# 3. Start ngrok
|
| 47 |
+
Write-Host "`n[3/3] Generating public ngrok URL..." -ForegroundColor Yellow
|
| 48 |
+
Write-Host "Starting ngrok on port 9000..." -ForegroundColor Green
|
| 49 |
+
ngrok http 9000
|
test_db.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
import psycopg2
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
print("Loading environment variables...")
|
| 6 |
-
# Load environment variables from .env
|
| 7 |
-
load_dotenv()
|
| 8 |
-
|
| 9 |
-
# Fetch variables
|
| 10 |
-
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 11 |
-
if not DATABASE_URL:
|
| 12 |
-
print("No DATABASE_URL found in .env! Using Supabase URL directly for test.")
|
| 13 |
-
DATABASE_URL = "postgresql://postgres:ngbksZaNkjulikrp@db.tyhlrlpebsgcciglxonc.supabase.co:5432/postgres"
|
| 14 |
-
|
| 15 |
-
print("Connecting to the database...")
|
| 16 |
-
try:
|
| 17 |
-
# Connect to the database
|
| 18 |
-
connection = psycopg2.connect(DATABASE_URL)
|
| 19 |
-
print("SUCCESS! Database connection string works perfectly!")
|
| 20 |
-
|
| 21 |
-
# Close connection
|
| 22 |
-
connection.close()
|
| 23 |
-
except Exception as e:
|
| 24 |
-
print("FAILED to connect!")
|
| 25 |
-
print("Error:", e)
|
| 26 |
-
print("\nReminder: Vercel does not support IPv6. If this URL works locally but fails on Vercel, you MUST use the IPv4 Connection Pooler URL from Supabase!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|