Better launchpad

This commit is contained in:
2025-12-13 16:16:15 +08:00
parent 0e0ff24195
commit 0d2f78b4e7
14 changed files with 989 additions and 283 deletions

View File

@@ -6,34 +6,54 @@ A modular service framework.
The `launchpad` is a CLI tool located in `pkg/launchpad` designed to simplify development and production workflows for the entire Turbine project. It acts as a process manager that can run all defined services concurrently for development and generate a `docker-compose.yml` file for production deployments.
### Configuration
### Configuration (`launchpad.toml`)
The launchpad is configured via a `launchpad.toml` file in the project root. This file defines all the services, including how to run them in development and how to build them for production.
The launchpad is configured via a `launchpad.toml` file in the project root. This file defines all the services, their configurations, and the networks they use.
**`launchpad.toml` example:**
```toml
# Defines variables required by the configuration.
# These should be supplied in a .env file.
[variables]
required = ["CACHE_PASSWORD", "QUEUE_PASSWORD", "RING_IMAGE", "RING_PORT"]
# Defines docker networks.
[networks]
aspire = {}
# Service definitions
[[services]]
name = "gateway"
type = "go"
path = "./pkg/gateway"
[services.dev]
command = "go run ./main.go"
name = "cache"
type = "docker" # For third-party docker images
[services.prod]
dockerfile = "./pkg/gateway/Dockerfile"
image = "turbine/gateway:latest"
ports = ["8080:8080"]
image = "docker.io/library/redis:7.4"
command = ["/bin/sh", "-c", "redis-server --requirepass $$REDIS_PASSWORD"]
environment = ["REDIS_PASSWORD=${CACHE_PASSWORD}"]
expose = ["6379"]
networks = ["aspire"]
[[services]]
name = "orders-api"
name = "ring"
type = "dotnet"
path = "../turbine-dotnet-services/orders-api"
path = "../turbine-dotnet-services/ring"
[services.dev]
command = "dotnet watch run"
[services.prod]
dockerfile = "../turbine-dotnet-services/orders-api/Dockerfile"
image = "turbine/orders-api:latest"
image = "${RING_IMAGE}"
environment = [
"HTTP_PORTS=${RING_PORT}",
"ConnectionStrings__cache=cache:6379,password=${CACHE_PASSWORD}",
]
volumes = ["./keys:/app/keys", "./settings/ring.json:/app/appsettings.json"]
expose = ["${RING_PORT}", "5001"]
networks = ["aspire"]
depends_on = ["cache", "queue"]
```
### Environment Variables (`.env`)
For the `deploy` command to work, you must create a `.env` file in the project root containing the variables defined in `launchpad.toml`. An example is provided in `.env.example`.
### Commands
To use the launchpad, run its `main.go` file with one of the following commands:
@@ -45,13 +65,14 @@ Starts all services defined in `launchpad.toml` in development mode. Each servic
go run ./pkg/launchpad/main.go dev
```
#### Production Docker Compose Generation (`prod-gen`)
Generates a `docker-compose.yml` file in the project root based on the `prod` configuration of all services in `launchpad.toml`. This file can be used to build and run all services as Docker containers.
#### Production Deployment (`deploy`)
Generates a `docker-compose.yml` file in the project root based on the `prod` configuration of all services in `launchpad.toml`. It substitutes variables from your `.env` file. This file can be used to build and run all services as Docker containers.
```bash
go run ./pkg/launchpad/main.go prod-gen
go run ./pkg/launchpad/main.go deploy
```
## Registrar
The Registrar is the service discovery system of the DysonNetwork.