1 个不稳定版本
0.1.0 | 2024年5月17日 |
---|
#400 在 配置
38KB
518 行
ruStack Launcher
一个用于开发应用程序启动器的 Rust 库。它使用单个 TOML 配置文件,自动将其转换为 .env 和 YAML 文件。此库还允许您轻松地在 Docker Compose 和 Podman Compose 之间切换。
NOTE: This is a personal project created for practicing Rust development. Feel free to modify this library as you see fit.
配置文件
启动器使用 TOML 格式来接收配置。有关指南,请参阅 TOML。
表格
[settings]
提供对启动器功能及其常用配置值的洞察。
属性
属性 | 使用示例 |
---|---|
name | 应用程序或堆栈的名称 ("Hello There") |
description | 启动器的描述 ("MyAppStack 启动器。") |
author | 启动器的作者或创建者。例如:JP Mateo |
base_dir | 启动器的基目录 ("/mydirectory") |
deploy_dir | 存储部署工件的自定义目录 ("deploy") |
services_dir | 包含服务配置的自定义目录 ("services") |
compose_executable | 用于 Docker Compose 的可执行文件。值:"docker-compose"、"podman-compose" |
compose_file | 用于部署的 compose 文件名。例如:myapp-compose.yaml |
compose_detached | 是否以分离模式运行 Docker Compose(true) |
示例
[settings]
name = "Hello There"
description = "MyAppStack launcher."
author = "JP Mateo"
base_dir = "/mydirectory"
deploy_dir = "deploy"
services_dir = "services"
compose_executable = "docker-compose"
compose_file = "docker-compose-test.yaml"
compose_detached = true
[[services]]
包含一个服务列表或数组,格式与 Docker Compose 服务兼容。有关更多详细信息,请参阅: Docker Compose 服务文档
属性 | 描述 | 示例 |
---|---|---|
hostname | 服务的计算机名 | "db" |
image | 用于服务的 Docker 镜像 | "postgres" |
ports | 要公开的端口(主机:容器) | ["5432:5432"] |
environment | 在容器内设置的环境变量 | { POSTGRES_USER = "admin", ... } |
env_file | 从其中加载变量的环境文件路径 | ["database"] |
networks | 服务连接到的网络 | ["mynetwork"] |
volumes | 要挂载的卷(类型、源、目标) | [{ kind = "bind", source = ..., target = ... }] |
depends_on | 依赖于此服务的服务 | ["myserviceapp"] |
restart | 服务的重启策略 | "always" |
tty | 分配伪 TTY | true |
示例
[[services]]
#This is the app service.
hostname = "db"
image = "postgres"
ports = [
"5432:5432"
]
environment = { POSTGRES_USER = "admin", POSTGRES_PASSWORD = "admin123", PGDATA="/var/lib/postgresql/data/pgdata" }
env_file = [
"database",
]
networks = [
"mynetwork"
]
volumes = [
{ kind = "bind", source = "/Users/jpmateo/Codes/rust/rustack-launcher/tests/testapp/data", target = "/var/lib/postgresql/data/pgdata"}
]
depends_on = [
"myserviceapp"
]
restart = "always"
tty = true
[[networks]]
包含一个网络列表或数组,格式符合 Docker Compose 网络规范。有关更多指导,请参阅: Docker Compose 网络文档
属性 | 描述 | 示例 |
---|---|---|
name | 网络名称 | "mynetwork2" |
驱动程序 | 网络驱动程序:参见。 https://docs.docker.net.cn/network/drivers/ | "bridge" |
标签 | 与网络关联的标签(键值对) | { "my.network.label.1" = ..., ... } |
外部 | 如果网络是外部的,则设置为 true。默认:false | external = false |
示例
[[networks]]
name = "mynetwork2"
driver = "bridge"
external = false
labels = { "my.network.label.1" = "This is a network label 1.", "my.network.label.2" = "This is a network label 2." }
[[volumes]]
包含一个与 Docker Compose 体积规范兼容的体积列表或数组。有关更多信息,请参阅:Docker Compose 体积文档
属性 | 描述 | 示例 | serde(default) |
---|---|---|---|
name | 体积名称 | "testvolumes" | |
驱动程序 | 体积驱动程序。参见:https://docs.docker.net.cn/compose/compose-file/07-volumes/#driver | "nfs" | |
driver_opts | 体积驱动程序选项(名称,值)。参见:https://docs.docker.net.cn/compose/compose-file/07-volumes/#driver_opts | [{ name = "type", value = "nfs" }, ... ] | |
外部 | 指示体积是否为外部。默认:false | false | |
标签 | 与体积关联的标签(键值对) | { "my.volume.label1" = ..., ... } | |
示例 |
[[volumes]]
name = "testvolumes"
driver = "nfs"
driver_opts = [
{ name = "type", value = "nfs" },
{ name = "o", value = "addr=10.40.0.199,nolock,soft,rw" },
{ name = "device", value = ":/docker/example" },
]
external = false
labels = { "my.volume.label1" = "This is a volume label 1.", "my.volume.label2" = "This is a volume label 2." }
[[repositories]]
这包括需要从版本控制系统拉取的存储库列表或数组。
属性 | 描述 | 示例 | serde(default) |
---|---|---|---|
服务 | 与存储库关联的服务 | "app" | |
mount_target | 挂载存储库的目标目录 | "/var/db" | |
name | 存储库名称 | "execism-diffie-hellman" | |
url | 存储库的 URL | "https://github.com/j-p-d-e-v/execism-diffie-hellman" | |
branch | 要使用的存储库分支 | "master" | |
clone | 指示是否克隆存储库 | false |
Note: I did not include the authentication method. It is generally better to establish a connection between your machine/server and the desired Git server before proceeding.
示例
[[repositories]]
service = "app"
mount_target = "/var/db"
name = "execism-diffie-hellman"
url = "https://github.com/j-p-d-e-v/execism-diffie-hellman"
branch = "master"
clone = false
使用 Docker-Compose
先决条件
- Docker 引擎必须在您的系统中安装。参见:https://docs.docker.net.cn/
- Docker-Compose 必须在您的系统中安装:参见:https://docs.docker.net.cn/compose/install/podman-compose
//Load the toml configuration file.
let config = Config::load("config-test-docker.toml".to_string());
let deploy_dir: String = format!("{}/{}",config.settings.base_dir,&config.settings.deploy_dir);
config.validate();
let env_file_paths: Vec<String> = EnvironmentFile::generate(&config.env_files,&deploy_dir);
let compose: Compose = Compose::new(config);
compose.up();
compose.down();
使用 Podman-Compose
先决条件
- Podman 必须在您的系统中安装。参见:https://podman.io/
- Podman-Compose 必须在您的系统中安装:参见:https://github.com/containers/podman-compose
示例
let config = Config::load("config-test-podman.toml".to_string());
let deploy_dir: String = format!("{}/{}",config.settings.base_dir,&config.settings.deploy_dir);
config.validate();
let env_file_paths: Vec<String> = EnvironmentFile::generate(&config.env_files,&deploy_dir);
let compose: Compose = Compose::new(config);
compose.up();
compose.down();
单元测试
cargo test -- --test-threads 1 --nocapture
开发者
- JP Mateo
依赖关系
~13MB
~315K SLoC