docker-compose.yml
Smarter Platform is a Docker-based Python-Django micro-service application that runs in Kubernetes. Below is a docker-compose.yml that strongly resembles the Kubernetes run-time configuration. You can use this file to synch your local development environment with the Smarter Platform.
---
#------------------------------------------------------------------------------
# For local development, you can use the following docker-compose file
# to run the application. This file will start a MariaDB database, a Redis
# server, Celery and Beat workers, and the application itself. The application
# will be available at http://localhost:9357.
#------------------------------------------------------------------------------
services:
smarter-mariadb:
container_name: smarter-mariadb
mem_limit: 2g
cpus: 0.5
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: smarter
MYSQL_DATABASE: smarter
MYSQL_USER: smarter
MYSQL_PASSWORD: smarter
ports:
- 3306:3306
volumes:
- ./mariadb-data:/var/lib/mysql
smarter-redis:
container_name: smarter-redis
cpus: 0.25
mem_limit: 1g
image: redis:latest
command: redis-server --requirepass smarter
ports:
- 6379:6379
smarter-app:
container_name: smarter-app
mem_limit: 4g
cpus: 1
user: smarter_user
x-build:
type: docker
build:
context: .
dockerfile: Dockerfile
args:
# future use. The worker and beat services use the same Dockerfile as this app service,
# but we can optionally set the SCHEMA build argument to something other than "APP"
# in order to fine tune the build requirements.
SCHEMA: APP
ENVIRONMENT: ${ENVIRONMENT}
DOCKER_COLLECT_STATIC_FILES: ${DOCKER_COLLECT_STATIC_FILES}
image: smarter
command: watchmedo auto-restart --directory=./smarter --pattern=*.py --recursive -- uvicorn smarter.asgi:application --host 0.0.0.0 --port 9357
# volumes:
# - type: bind
# source: ./smarter
# target: /smarter
# consistency: cached
ports:
- 9357:9357
depends_on:
- smarter-mariadb
- smarter-redis
env_file:
- ./.env
environment:
- PYTHONUNBUFFERED=1
- SERVICE_TYPE=app
smarter-worker:
container_name: smarter-worker
mem_limit: 2g
cpus: 0.5
user: smarter_user
x-build:
type: docker
build:
context: .
dockerfile: Dockerfile
args:
# future use. The worker and beat services use the same Dockerfile as the app service,
# but we can optionally set the SCHEMA build argument to something other than "APP"
# in order to fine tune the build requirements.
SCHEMA: APP
ENVIRONMENT: ${ENVIRONMENT}
DOCKER_COLLECT_STATIC_FILES: ${DOCKER_COLLECT_STATIC_FILES}
image: smarter
command: celery -A smarter.workers.celery.app worker --concurrency=4 --loglevel=info -Q default_celery_task_queue -E
depends_on:
- smarter-mariadb
- smarter-redis
- smarter-app
env_file:
- ./.env
environment:
- PYTHONUNBUFFERED=1
- SERVICE_TYPE=worker
# volumes:
# - type: bind
# source: ./smarter
# target: /smarter
# consistency: cached
healthcheck:
test: ["CMD", "celery", "-A", "smarter.workers.celery.app", "inspect", "ping"]
interval: 30s
timeout: 30s
retries: 3
# Serves the infrastructure queue: tasks that deploy, verify and destroy cloud, Kubernetes and
# DNS resources, which can take many minutes. Its own worker, so that they never block the
# operational tasks of smarter-worker, such as prompt history, charges and budgets.
smarter-worker-infrastructure:
container_name: smarter-worker-infrastructure
mem_limit: 2g
cpus: 0.5
user: smarter_user
x-build:
type: docker
build:
context: .
dockerfile: Dockerfile
args:
# future use. The worker and beat services use the same Dockerfile as the app service,
# but we can optionally set the SCHEMA build argument to something other than "APP"
# in order to fine tune the build requirements.
SCHEMA: APP
ENVIRONMENT: ${ENVIRONMENT}
DOCKER_COLLECT_STATIC_FILES: ${DOCKER_COLLECT_STATIC_FILES}
image: smarter
command: celery -A smarter.workers.celery.app worker --concurrency=4 --loglevel=info -Q infrastructure_celery_task_queue -E -n infrastructure@%h
depends_on:
- smarter-mariadb
- smarter-redis
- smarter-app
env_file:
- ./.env
environment:
- PYTHONUNBUFFERED=1
- SERVICE_TYPE=worker
# volumes:
# - type: bind
# source: ./smarter
# target: /smarter
# consistency: cached
healthcheck:
test: ["CMD", "celery", "-A", "smarter.workers.celery.app", "inspect", "ping"]
interval: 30s
timeout: 30s
retries: 3
smarter-beat:
container_name: smarter-beat
mem_limit: 1g
cpus: 0.5
user: smarter_user
x-build:
type: docker
build:
context: .
dockerfile: Dockerfile
args:
# future use. The worker and beat services use the same Dockerfile as the app service,
# but we can optionally set the SCHEMA build argument to something other than "APP"
# in order to fine tune the build requirements.
SCHEMA: APP
ENVIRONMENT: ${ENVIRONMENT}
DOCKER_COLLECT_STATIC_FILES: ${DOCKER_COLLECT_STATIC_FILES}
image: smarter
command: celery -A smarter.workers.celerybeat beat --loglevel=info
depends_on:
- smarter-mariadb
- smarter-redis
- smarter-app
env_file:
- ./.env
environment:
- PYTHONUNBUFFERED=1
- SERVICE_TYPE=beat
# volumes:
# - type: bind
# source: ./smarter
# target: /smarter
# consistency: cached
healthcheck:
test: ["CMD", "celery", "-A", "smarter.workers.celerybeat", "inspect", "ping"]
interval: 30s
timeout: 30s
retries: 3