Refactor Docker Compose and API configuration for improved service management

- Consolidated Redis service into the main `docker-compose.yml`, removing the separate API Docker Compose file.
- Added health checks for Redis and API services to ensure proper service readiness.
- Updated API router to include a public health check endpoint.
- Cleaned up the web Dockerfile by removing unnecessary environment variable copying.

These changes enhance service orchestration and improve the reliability of the application during development.
This commit is contained in:
dal 2025-01-07 16:20:59 -07:00
parent 176d5eb06b
commit 4679adf04a
5 changed files with 43 additions and 29 deletions

View File

@ -1,8 +0,0 @@
version: '3.8'
services:
redis:
image: redis
container_name: buster-redis
ports:
- "6379:6379"

View File

@ -47,13 +47,14 @@ async fn main() {
}
let protected_router = Router::new().nest("/api/v1", routes::protected_router());
let public_router = Router::new().route("/health", axum::routing::get(|| async { "OK" }));
let (shutdown_tx, _) = broadcast::channel::<()>(1);
let shutdown_tx = Arc::new(shutdown_tx);
let app = Router::new()
.merge(protected_router)
// .merge(public_router)
.merge(public_router)
.layer(TraceLayer::new_for_http())
.layer(cors())
.layer(CompressionLayer::new())

View File

@ -1,30 +1,41 @@
include:
- supabase/docker-compose.yml
services:
db:
image: supabase/postgres:15.1.0.117
restart: always
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-your-super-secret-password}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-buster}
volumes:
- db_data:/var/lib/postgresql/data
- ./migrations:/docker-entrypoint-initdb.d
redis:
image: redis
container_name: buster-redis
ports:
- "5432:5432"
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 3s
retries: 30
api:
build:
context: ./api
dockerfile: Dockerfile
env_file:
- .env
ports:
- "3001:3001"
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-your-super-secret-password}@db:5432/${POSTGRES_DB:-buster}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
interval: 30s
timeout: 10s
retries: 3
depends_on:
- db
redis:
condition: service_healthy
db:
condition: service_healthy
web:
build: ./web
env_file:
- .env
ports:
- "3000:3000"
environment:

15
start.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
echo "Starting Supabase..."
cd supabase
docker compose up -d
echo "Waiting for Supabase to be healthy..."
until curl -s http://localhost:54321/rest/v1/ > /dev/null; do
echo "Waiting for Supabase..."
sleep 5
done
echo "Supabase is ready! Starting main services..."
cd ..
docker compose up

View File

@ -6,11 +6,8 @@ WORKDIR /app
# Copy package files
COPY package*.json ./
# Copy environment variables for build
COPY .env ./
COPY next.config.mjs ./
# Install dependencies
RUN npm ci
@ -34,8 +31,6 @@ COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/next.config.mjs ./
# Copy environment files
COPY --from=builder /app/.env ./
# Expose the port your app runs on
EXPOSE 3000