Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ COPY app/ ./app/
# Copy built frontend from GitHub Actions build
COPY ui/dist ./ui/dist

# Expose port
EXPOSE 8000
# Create startup script that properly handles runtime PORT variable
RUN echo '#!/bin/sh\n\
PORT="${PORT:-8080}"\n\
echo "Starting server on port $PORT"\n\
exec /app/.venv/bin/uvicorn app.main:app --host 0.0.0.0 --port "$PORT"' > /app/start.sh && \
chmod +x /app/start.sh

# Expose port 8080 (Cloud Run default)
EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/ || exit 1
CMD curl -f http://localhost:${PORT:-8080}/ || exit 1

# Run the application
CMD ["/app/.venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
CMD ["/app/start.sh"]
9 changes: 8 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ class DevelopmentConfig(BaseConfig):
"http://127.0.0.1:5173", # Vite dev server alternative
"http://localhost:4173", # Vite preview server
"http://127.0.0.1:4173", # Vite preview server alternative
"http://localhost:8080", # Docker local
"http://localhost:8000", # Alternative local
]


class ProductionConfig(BaseConfig):
DEBUG = False
CORS_ORIGINS = [""]
# For Cloud Run, you need to add your actual domain
CORS_ORIGINS = os.getenv("CORS_ORIGINS", "").split(",") if os.getenv("CORS_ORIGINS") else ["*"]


def get_config():
# Check for DEBUG env var first, then APP_ENV
if os.getenv("DEBUG", "").lower() == "true":
return DevelopmentConfig

env = os.getenv("APP_ENV", "development")
if env == "production":
return ProductionConfig
Expand Down
57 changes: 57 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Local development script for pathways-api

echo "🚀 Starting Pathways API local development environment..."

# Function to cleanup on exit
cleanup() {
echo "🛑 Stopping services..."
docker-compose down
exit
}

# Set trap to cleanup on script exit
trap cleanup EXIT INT TERM

# Check if running in Docker mode or local mode
if [ "$1" = "docker" ]; then
echo "📦 Running in Docker mode..."

# Build and run with docker-compose
docker-compose build
docker-compose up -d

echo "✅ API running at http://localhost:8080"
echo "📝 Logs: docker-compose logs -f pathways-api"

# Wait for services
docker-compose logs -f

elif [ "$1" = "local" ]; then
echo "💻 Running in local development mode..."

# Start backend
echo "🔧 Starting backend..."
cd /Users/carlos_cruz/projects/ot/pathways-api
PORT=8080 uvicorn app.main:app --reload --host 0.0.0.0 --port 8080 &
BACKEND_PID=$!

# Start frontend
echo "🎨 Starting frontend..."
cd ui
npm run dev &
FRONTEND_PID=$!

echo "✅ Backend running at http://localhost:8080"
echo "✅ Frontend running at http://localhost:5173"

# Wait for both processes
wait $BACKEND_PID $FRONTEND_PID

else
echo "Usage: $0 [docker|local]"
echo " docker - Run everything in Docker"
echo " local - Run backend and frontend locally"
exit 1
fi
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ services:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
- "8080:8080"
environment:
- DEBUG=false
- CORS_ORIGINS=http://localhost:3000,http://localhost:8000
- PORT=8080
- DEBUG=true
- APP_ENV=development
- CORS_ORIGINS=http://localhost:3000,http://localhost:5173,http://127.0.0.1:5173,http://localhost:8080
volumes:
# Mount data directory for development
- ./app/data:/app/app/data:ro
restart: unless-stopped
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:8000/" ]
test: [ "CMD", "curl", "-f", "http://localhost:8080/" ]
interval: 30s
timeout: 10s
retries: 3
Expand Down
2 changes: 2 additions & 0 deletions ui/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add a .env file for local development
VITE_API_URL=http://localhost:8080
1 change: 1 addition & 0 deletions ui/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_URL=http://localhost:8080
25 changes: 14 additions & 11 deletions ui/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
12 changes: 11 additions & 1 deletion ui/src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
const API_BASE_URL = 'http://localhost:8000';
const getApiBaseUrl = () => {
// For production (when served from the same domain)
if (window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
return ''; // Use relative URLs in production
}

// For local development
return import.meta.env.VITE_API_URL || 'http://localhost:8080';
};

const API_BASE_URL = getApiBaseUrl();

export type Pathway = Record<string, any>;

Expand Down