diff --git a/.env.example b/.env.example index 7c21712..b85f289 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,6 @@ PORT=8080 -CONSOLE_IMAGE=ghcr.io/agentlabs-dev/agentlabs-poc/console:latest -FRONTEND_IMAGE=ghcr.io/agentlabs-dev/agentlabs-poc/frontend:latest - -SERVER_IMAGE=ghcr.io/agentlabs-dev/agentlabs-poc/server:latest # ---------------------- # Database configuration @@ -24,12 +20,6 @@ POSTGRES_PORT=5432 # You should not have to change this unless you are using an external database. POSTGRES_HOST=postgres -# ---------------------- -# Misc configuration -# ---------------------- - -OPENAI_API_KEY= - # ---------------------- # Backend Server Configuration # ---------------------- @@ -44,9 +34,31 @@ PUBLIC_AI_AGENT_DOMAIN=app.agentlabs.dev # ---------------------- # For development only - if you are not contributing to Agentlabs, you can freely ignore this! +# - Image configuration - +# Unless you really know what you are doing you probaby do not want to +# mess with that. # ---------------------- +CONSOLE_IMAGE=ghcr.io/agentlabs-inc/agentlabs/console:latest + +FRONTEND_IMAGE=ghcr.io/agentlabs-inc/agentlabs/frontend:latest + +SERVER_IMAGE=ghcr.io/agentlabs-inc/agentlabs/server:latest + +CADDY_IMAGE=caddy:2.7.4-alpine + +POSTGRES_IMAGE=postgres:16rc1-alpine3.18 + DEV_FRONTEND_PORT=3000 DEV_CONSOLE_PORT=3002 DEV_SERVER_PORT=3001 DEV_POSTGRES_PORT=5432 + +# ---------------------- +# - Agentlabs cloud configuration options - +# Unless you work at Agentlabs this part is not for you. +# ---------------------- + +CLOUD_APP_WILDCARD_DOMAIN= +CLOUD_CONSOLE_URL= +CLOUD_APP_WILDCARD_DOMAIN_DNS_API_KEY= diff --git a/.gitignore b/.gitignore index 5b8a07e..7442010 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .env.local node_modules -gen-api \ No newline at end of file +gen-api +caddy/data diff --git a/caddy/config/Caddyfile b/caddy/config/Caddyfile new file mode 100644 index 0000000..61629a9 --- /dev/null +++ b/caddy/config/Caddyfile @@ -0,0 +1,17 @@ +:80 { + handle_path /api/* { + reverse_proxy server:3000 + } + + handle /socket.io/* { + reverse_proxy server:3000 + } + + handle /console/* { + reverse_proxy console:3000 + } + + handle { + reverse_proxy frontend:3000 + } +} diff --git a/cloud-proxy/Caddyfile b/cloud-proxy/Caddyfile new file mode 100644 index 0000000..ace4ae9 --- /dev/null +++ b/cloud-proxy/Caddyfile @@ -0,0 +1,30 @@ +{$CLOUD_APP_WILDCARD_DOMAIN}:443 { + tls { + dns godaddy {$CLOUD_APP_WILDCARD_DOMAIN_DNS_API_KEY} + } + + reverse_proxy gateway +} + +{$CLOUD_CONSOLE_URL}:443 { + @console { + path /console/* + } + + @api { + path /api/* + } + + handle @console { + reverse_proxy gateway + } + + handle @api { + reverse_proxy gateway + } + + handle { + rewrite * /console{path} + reverse_proxy gateway + } +} diff --git a/cloud-proxy/Dockerfile b/cloud-proxy/Dockerfile new file mode 100644 index 0000000..e40c849 --- /dev/null +++ b/cloud-proxy/Dockerfile @@ -0,0 +1,8 @@ +FROM caddy:2.7.4-builder-alpine as builder + +RUN xcaddy build \ + --with github.com/caddy-dns/godaddy + +FROM caddy:2.7.4-alpine + +COPY --from=builder /usr/bin/caddy /usr/bin/caddy diff --git a/docker-compose.cloud.yml b/docker-compose.cloud.yml new file mode 100644 index 0000000..50b2b73 --- /dev/null +++ b/docker-compose.cloud.yml @@ -0,0 +1,64 @@ +version: '3.8' + +volumes: + postgres-data: + +services: + + cloud-proxy: + # TODO: build cloud proxy image in a pipeline and turn it into a proper package + # Not urgent as this is used only to host the cloud version. + build: + context: cloud-proxy + volumes: + - ./cloud-proxy/Caddyfile:/etc/caddy/Caddyfile + ports: + - 80:80 + - 443:443 + depends_on: + - gateway + environment: + - CLOUD_CONSOLE_URL=${CLOUD_CONSOLE_URL} + - CLOUD_APP_WILDCARD_DOMAIN=${CLOUD_APP_WILDCARD_DOMAIN} + - CLOUD_APP_WILDCARD_DOMAIN_DNS_API_KEY=${CLOUD_APP_WILDCARD_DOMAIN_DNS_API_KEY} + restart: unless-stopped + + gateway: + image: ${CADDY_IMAGE} + volumes: + - ./caddy/config/Caddyfile:/etc/caddy/Caddyfile + depends_on: + - frontend + - server + restart: unless-stopped + + postgres: + image: ${POSTGRES_IMAGE} + environment: + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - postgres-data:/var/lib/postgresql/data + restart: unless-stopped + + server: + image: ${SERVER_IMAGE} + environment: + - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT} + - USERS_ACCESS_TOKEN_SECRET=${USERS_ACCESS_TOKEN_SECRET} + depends_on: + - postgres + restart: unless-stopped + + frontend: + image: ${FRONTEND_IMAGE} + depends_on: + - server + restart: unless-stopped + + console: + image: ${CONSOLE_IMAGE} + depends_on: + - server + restart: unless-stopped diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 6f6bdee..11ff8ee 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,24 +1,22 @@ version: '3.8' +volumes: + postgres-data-dev: + services: gateway: - image: nginx:1.25.2-alpine - hostname: gateway + image: ${CADDY_IMAGE} container_name: gateway-dev volumes: - - ./nginx/nginx.conf:/etc/nginx/nginx.conf - ports: - - ${PORT}:80 + - ./caddy/config/Caddyfile:/etc/caddy/Caddyfile depends_on: - frontend - - console - server restart: unless-stopped postgres: - image: postgres:16rc1-alpine3.18 - hostname: postgres + image: ${POSTGRES_IMAGE} container_name: postgres-dev environment: - POSTGRES_USER=${POSTGRES_USER} @@ -32,7 +30,6 @@ services: server: container_name: server-dev - hostname: server build: context: ./server dockerfile: Dockerfile.dev @@ -47,7 +44,6 @@ services: frontend: container_name: frontend-dev - hostname: frontend build: context: ./frontend dockerfile: Dockerfile.dev @@ -74,6 +70,3 @@ services: depends_on: - server restart: unless-stopped - -volumes: - postgres-data-dev: diff --git a/docker-compose.yml b/docker-compose.yml index 1b63611..2afca36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,14 @@ version: '3.8' +volumes: + postgres-data: + services: gateway: - image: nginx:1.25.2-alpine - hostname: gateway - container_name: gateway + image: ${CADDY_IMAGE} volumes: - - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./caddy/config/Caddyfile:/etc/caddy/Caddyfile ports: - ${PORT}:80 depends_on: @@ -15,10 +16,20 @@ services: - server restart: unless-stopped + frontend: + image: ${FRONTEND_IMAGE} + depends_on: + - server + restart: unless-stopped + + console: + image: ${CONSOLE_IMAGE} + depends_on: + - server + restart: unless-stopped + postgres: - image: postgres:16rc1-alpine3.18 - hostname: postgres - container_name: postgres + image: ${POSTGRES_IMAGE} environment: - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - POSTGRES_USER=${POSTGRES_USER} @@ -28,8 +39,6 @@ services: restart: unless-stopped server: - container_name: server - hostname: server image: ${SERVER_IMAGE} environment: - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT} @@ -37,22 +46,3 @@ services: depends_on: - postgres restart: unless-stopped - - frontend: - container_name: frontend - hostname: frontend - image: ${FRONTEND_IMAGE} - depends_on: - - server - restart: unless-stopped - - console: - container_name: console - hostname: console - image: ${CONSOLE_IMAGE} - depends_on: - - server - restart: unless-stopped - -volumes: - postgres-data: