Crates.io | rustack-launcher |
lib.rs | rustack-launcher |
version | 0.1.0 |
source | src |
created_at | 2024-05-17 12:38:29.482983 |
updated_at | 2024-05-17 12:38:29.482983 |
description | A Rust library for developing application launchers. It uses a single TOML configuration file to automatically transform it into .env and YAML files. This library also allows you to easily switch between Docker Compose and Podman Compose. |
homepage | |
repository | https://github.com/j-p-d-e-v/rustack-launcher |
max_upload_size | |
id | 1243091 |
size | 67,365 |
A Rust library for developing application launchers. It uses a single TOML configuration file to automatically transform it into .env and YAML files. This library also allows you to easily switch between Docker Compose and Podman Compose.
NOTE: This is a personal project created for practicing Rust development. Feel free to modify this library as you see fit.
The launcher takes a configuration using TOML. See TOML for the guidelines.
Provides insights into the launcher functionalities alongside frequently used configuration values.
Properties:
Property | Usage Example |
---|---|
name | Name of the application or stack ("Hello There") |
description | Description of the launcher ("MyAppStack launcher.") |
author | Author or creator of the launcher. Example: JP Mateo |
base_dir | Base directory for the launcher ("/mydirectory") |
deploy_dir | Directory where deployment artifacts are stored ("deploy") |
services_dir | Directory containing service configurations ("services") |
compose_executable | Executable used for Docker Compose. Values: "docker-compose", "podman-compose" |
compose_file | The compose file name used for deployment. Example: myapp-compose.yaml |
compose_detached | Whether to run Docker Compose in detached mode (true) |
Example:
[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
Comprises a list or array of services, structured in a format compatible with Docker Compose services. For further details, refer to: Docker Compose Services Documentation
Property | Description | Example |
---|---|---|
hostname | Hostname of the service | "db" |
image | Docker image to use for the service | "postgres" |
ports | Ports to expose (host:container) | ["5432:5432"] |
environment | Environment variables to set inside the container | { POSTGRES_USER = "admin", ... } |
env_file | Path to the environment file to load variables from | ["database"] |
networks | Networks the service is connected to | ["mynetwork"] |
volumes | Volumes to mount (kind, source, target) | [{ kind = "bind", source = ..., target = ... }] |
depends_on | Services this service depends on | ["myserviceapp"] |
restart | Restart policy for the service | "always" |
tty | Allocate a pseudo-TTY | true |
Example:
[[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
Consists of a list or array of networks, formatted in accordance with Docker Compose network specifications. For additional guidance, please consult: Docker Compose Network Documentation
Property | Description | Example |
---|---|---|
name | Name of the network | "mynetwork2" |
driver | Network driver: See. https://docs.docker.com/network/drivers/ | "bridge" |
labels | Labels associated with the network (key-value) | { "my.network.label.1" = ..., ... } |
external | Set to true if the network is external. Default: false | external = false |
Example:
[[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." }
Comprises a list or array of volumes, structured in a format compatible with Docker Compose volume specifications. For further information, refer to: Docker Compose Volume Documentation
Property | Description | Example | serde(default) |
---|---|---|---|
name | Name of the volume | "testvolumes" | |
driver | Volume driver. See: https://docs.docker.com/compose/compose-file/07-volumes/#driver | "nfs" | |
driver_opts | Options for the volume driver (name, value). See: https://docs.docker.com/compose/compose-file/07-volumes/#driver_opts | [{ name = "type", value = "nfs" }, ... ] | |
external | Indicates whether the volume is external. Default: false | false | |
labels | Labels associated with the volume (key-value) | { "my.volume.label1" = ..., ... } | |
Example: |
[[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." }
This encompasses a list or array of repositories that require pulling from the version control system.
Property | Description | Example | serde(default) |
---|---|---|---|
service | Service associated with the repository | "app" | |
mount_target | Target directory for mounting the repository | "/var/db" | |
name | Name of the repository | "execism-diffie-hellman" | |
url | URL of the repository | "https://github.com/j-p-d-e-v/execism-diffie-hellman" | |
branch | Branch of the repository to use | "master" | |
clone | Indicates whether to clone the repository | 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.
Example:
[[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
Pre-requisites:
//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();
Pre-requisites:
Example:
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