(this is an idea that was thrown around while discussing other things; I'm creating an issue to have a central place to discuss it)
Websites will often need some accompanying services, for example Keycloak (identity manager), MongoDB/Postgres/… (databases), caches.
It'd be great if the CLI could auto-start and auto-stop them.
To avoid Kobweb having to explicitly handle each possible case, we can rely on Docker.
Example scenario
File structure:
project/
site/
…
build.gradle.kts
services/
docker-compose.yml
Contents of docker-compose.yml:
name: MyApp
services:
mongo:
image: "mongo:7.0.31"
ports:
- "27017:27017"
When I run kobweb run, the CLI should discover that the services are declared, and start them. kobweb stop should stop them.
Implementation details
On start, run in the directory in which the docker-compose.yml is:
docker compose build: If the docker-compose.yml references custom Dockerfiles, this ensures they are rebuilt. If it doesn't, this is a no-op (docker prints a warning about it being a no-op).
docker compose up -d: Downloads & starts all services.
On stop, run in the directory in which the docker-compose.yml is:
docker compose down: Stops everything and frees resources
Possible failures
User doesn't have docker installed. Warn the user that the services couldn't be auto-started.
Crash when calling docker: for security reasons, docker may be installed but the current user may not be allowed to access it. Warn the user that the services couldn't be auto-started.
A growing alternative to Docker is Podman, which accepts the exact same commands, maybe users should be able to configure which one they want to use?
(this is an idea that was thrown around while discussing other things; I'm creating an issue to have a central place to discuss it)
Websites will often need some accompanying services, for example Keycloak (identity manager), MongoDB/Postgres/… (databases), caches.
It'd be great if the CLI could auto-start and auto-stop them.
To avoid Kobweb having to explicitly handle each possible case, we can rely on Docker.
Example scenario
File structure:
Contents of
docker-compose.yml:When I run
kobweb run, the CLI should discover that the services are declared, and start them.kobweb stopshould stop them.Implementation details
On start, run in the directory in which the
docker-compose.ymlis:docker compose build: If thedocker-compose.ymlreferences customDockerfiles, this ensures they are rebuilt. If it doesn't, this is a no-op (docker prints a warning about it being a no-op).docker compose up -d: Downloads & starts all services.On stop, run in the directory in which the
docker-compose.ymlis:docker compose down: Stops everything and frees resourcesPossible failures
User doesn't have
dockerinstalled. Warn the user that the services couldn't be auto-started.Crash when calling
docker: for security reasons, docker may be installed but the current user may not be allowed to access it. Warn the user that the services couldn't be auto-started.A growing alternative to Docker is Podman, which accepts the exact same commands, maybe users should be able to configure which one they want to use?