Skip to content

Commit 88d1912

Browse files
committed
refactor: [torrust#851] rename env vars
``` TORRUST_TRACKER_BACK_ -> TORRUST_TRACKER_ TORRUST_TRACKER_DATABASE_DRIVER -> TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER TORRUST_TRACKER_API_ADMIN_TOKEN -> TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN TORRUST_TRACKER_CONFIG -> TORRUST_TRACKER_CONFIG_TOML TORRUST_TRACKER_PATH_CONFIG -> TORRUST_TRACKER_CONFIG_TOML_PATH ``` DB_DRIVER values: `MySQL`, `Sqlite3`. Removed lowercase values `mysql` and `sqlite3` used in containers. Some enums use lowercase. This is a braking change for container but not for configuration. IN the future we could use lowercase also in the configuration.
1 parent 7938433 commit 88d1912

File tree

14 files changed

+50
-49
lines changed

14 files changed

+50
-49
lines changed

Containerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ FROM gcr.io/distroless/cc-debian12:debug as runtime
9595
RUN ["/busybox/cp", "-sp", "/busybox/sh","/busybox/cat","/busybox/ls","/busybox/env", "/bin/"]
9696
COPY --from=gcc --chmod=0555 /usr/local/bin/su-exec /bin/su-exec
9797

98-
ARG TORRUST_TRACKER_PATH_CONFIG="/etc/torrust/tracker/tracker.toml"
99-
ARG TORRUST_TRACKER_DATABASE_DRIVER="sqlite3"
98+
ARG TORRUST_TRACKER_CONFIG_TOML_PATH="/etc/torrust/tracker/tracker.toml"
99+
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3"
100100
ARG USER_ID=1000
101101
ARG UDP_PORT=6969
102102
ARG HTTP_PORT=7070
103103
ARG API_PORT=1212
104104
ARG HEALTH_CHECK_API_PORT=1313
105105

106-
ENV TORRUST_TRACKER_PATH_CONFIG=${TORRUST_TRACKER_PATH_CONFIG}
107-
ENV TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER}
106+
ENV TORRUST_TRACKER_CONFIG_TOML_PATH=${TORRUST_TRACKER_CONFIG_TOML_PATH}
107+
ENV TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER}
108108
ENV USER_ID=${USER_ID}
109109
ENV UDP_PORT=${UDP_PORT}
110110
ENV HTTP_PORT=${HTTP_PORT}

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ cp ./share/default/config/tracker.development.sqlite3.toml ./storage/tracker/etc
8484
vim ./storage/tracker/etc/tracker.toml
8585

8686
# Run the tracker with the updated configuration:
87-
TORRUST_TRACKER_PATH_CONFIG="./storage/tracker/etc/tracker.toml" cargo run
87+
TORRUST_TRACKER_CONFIG_TOML_PATH="./storage/tracker/etc/tracker.toml" cargo run
8888
```
8989

9090
_Optionally, you may choose to supply the entire configuration as an environmental variable:_
9191

9292
```sh
9393
# Use a configuration supplied on an environmental variable:
94-
TORRUST_TRACKER_CONFIG=$(cat "./storage/tracker/etc/tracker.toml") cargo run
94+
TORRUST_TRACKER_CONFIG_TOML=$(cat "./storage/tracker/etc/tracker.toml") cargo run
9595
```
9696

9797
_For deployment, you **should** override the `api_admin_token` by using an environmental variable:_
@@ -102,8 +102,8 @@ gpg --armor --gen-random 1 10 | tee ./storage/tracker/lib/tracker_api_admin_toke
102102
chmod go-rwx ./storage/tracker/lib/tracker_api_admin_token.secret
103103

104104
# Override secret in configuration using an environmental variable:
105-
TORRUST_TRACKER_CONFIG=$(cat "./storage/tracker/etc/tracker.toml") \
106-
TORRUST_TRACKER_API_ADMIN_TOKEN=$(cat "./storage/tracker/lib/tracker_api_admin_token.secret") \
105+
TORRUST_TRACKER_CONFIG_TOML=$(cat "./storage/tracker/etc/tracker.toml") \
106+
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=$(cat "./storage/tracker/lib/tracker_api_admin_token.secret") \
107107
cargo run
108108
```
109109

compose.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ services:
44
image: torrust-tracker:release
55
tty: true
66
environment:
7-
- TORRUST_TRACKER_DATABASE_DRIVER=${TORRUST_TRACKER_DATABASE_DRIVER:-mysql}
8-
- TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken}
7+
- TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER:-MySQL}
8+
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
99
networks:
1010
- server_side
1111
ports:

docs/benchmarking.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Build and run the tracker:
3939

4040
```console
4141
cargo build --release
42-
TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" ./target/release/torrust-tracker
42+
TORRUST_TRACKER_CONFIG_TOML_PATH="./share/default/config/tracker.udp.benchmarking.toml" ./target/release/torrust-tracker
4343
```
4444

4545
Run the load test with:

docs/containers.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ Environmental variables are loaded through the `--env`, in the format `--env VAR
147147

148148
The following environmental variables can be set:
149149

150-
- `TORRUST_TRACKER_PATH_CONFIG` - The in-container path to the tracker configuration file, (default: `"/etc/torrust/tracker/tracker.toml"`).
151-
- `TORRUST_TRACKER_API_ADMIN_TOKEN` - Override of the admin token. If set, this value overrides any value set in the config.
152-
- `TORRUST_TRACKER_DATABASE_DRIVER` - The database type used for the container, (options: `sqlite3`, `mysql`, default `sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
153-
- `TORRUST_TRACKER_CONFIG` - Load config from this environmental variable instead from a file, (i.e: `TORRUST_TRACKER_CONFIG=$(cat tracker-tracker.toml)`).
150+
- `TORRUST_TRACKER_CONFIG_TOML_PATH` - The in-container path to the tracker configuration file, (default: `"/etc/torrust/tracker/tracker.toml"`).
151+
- `TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN` - Override of the admin token. If set, this value overrides any value set in the config.
152+
- `TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER` - The database type used for the container, (options: `Sqlite3`, `MySQL`, default `Sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
153+
- `TORRUST_TRACKER_CONFIG_TOML` - Load config from this environmental variable instead from a file, (i.e: `TORRUST_TRACKER_CONFIG_TOML=$(cat tracker-tracker.toml)`).
154154
- `USER_ID` - The user id for the runtime crated `torrust` user. Please Note: This user id should match the ownership of the host-mapped volumes, (default `1000`).
155155
- `UDP_PORT` - The port for the UDP tracker. This should match the port used in the configuration, (default `6969`).
156156
- `HTTP_PORT` - The port for the HTTP tracker. This should match the port used in the configuration, (default `7070`).
@@ -205,7 +205,7 @@ mkdir -p ./storage/tracker/lib/ ./storage/tracker/log/ ./storage/tracker/etc/
205205

206206
## Run Torrust Tracker Container Image
207207
docker run -it \
208-
--env TORRUST_TRACKER_API_ADMIN_TOKEN="MySecretToken" \
208+
--env TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MySecretToken" \
209209
--env USER_ID="$(id -u)" \
210210
--publish 0.0.0.0:7070:7070/tcp \
211211
--publish 0.0.0.0:6969:6969/udp \
@@ -227,7 +227,7 @@ mkdir -p ./storage/tracker/lib/ ./storage/tracker/log/ ./storage/tracker/etc/
227227

228228
## Run Torrust Tracker Container Image
229229
podman run -it \
230-
--env TORRUST_TRACKER_API_ADMIN_TOKEN="MySecretToken" \
230+
--env TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MySecretToken" \
231231
--env USER_ID="$(id -u)" \
232232
--publish 0.0.0.0:7070:7070/tcp \
233233
--publish 0.0.0.0:6969:6969/udp \
@@ -255,7 +255,7 @@ docker build --target release --tag torrust-tracker:release --file Containerfile
255255
mkdir -p ./storage/tracker/lib/ ./storage/tracker/log/ ./storage/tracker/etc/
256256

257257
USER_ID=$(id -u) \
258-
TORRUST_TRACKER_API_ADMIN_TOKEN="MySecretToken" \
258+
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MySecretToken" \
259259
docker compose up --build
260260
```
261261

docs/profiling.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ To generate the graph you will need to:
3535
```console
3636
cargo build --profile=release-debug --bin=profiling
3737
./target/release/aquatic_udp_load_test -c "load-test-config.toml"
38-
sudo TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" /home/USER/.cargo/bin/flamegraph -- ./target/release-debug/profiling 60
38+
sudo TORRUST_TRACKER_CONFIG_TOML_PATH="./share/default/config/tracker.udp.benchmarking.toml" /home/USER/.cargo/bin/flamegraph -- ./target/release-debug/profiling 60
3939
```
4040

4141
__NOTICE__: You need to install the `aquatic_udp_load_test` program.
@@ -92,7 +92,7 @@ Build and the binary for profiling:
9292

9393
```console
9494
RUSTFLAGS='-g' cargo build --release --bin profiling \
95-
&& export TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" \
95+
&& export TORRUST_TRACKER_CONFIG_TOML_PATH="./share/default/config/tracker.udp.benchmarking.toml" \
9696
&& valgrind \
9797
--tool=callgrind \
9898
--callgrind-out-file=callgrind.out \

packages/configuration/src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ pub const TORRENT_PEERS_LIMIT: usize = 74;
2424

2525
/// The whole `tracker.toml` file content. It has priority over the config file.
2626
/// Even if the file is not on the default path.
27-
const ENV_VAR_CONFIG: &str = "TORRUST_TRACKER_CONFIG";
27+
const ENV_VAR_CONFIG_TOML: &str = "TORRUST_TRACKER_CONFIG_TOML";
2828

2929
/// The `tracker.toml` file location.
30-
pub const ENV_VAR_PATH_CONFIG: &str = "TORRUST_TRACKER_PATH_CONFIG";
30+
pub const ENV_VAR_CONFIG_TOML_PATH: &str = "TORRUST_TRACKER_CONFIG_TOML_PATH";
3131

3232
/// Env var to overwrite API admin token.
33-
/// Deprecated: use `TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN`.
34-
const ENV_VAR_API_ADMIN_TOKEN: &str = "TORRUST_TRACKER_API_ADMIN_TOKEN";
33+
const ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN: &str = "TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN";
3534

3635
pub type Configuration = v1::Configuration;
3736
pub type UdpTracker = v1::udp_tracker::UdpTracker;
@@ -65,9 +64,9 @@ impl Info {
6564
///
6665
#[allow(clippy::needless_pass_by_value)]
6766
pub fn new(default_config_toml_path: String) -> Result<Self, Error> {
68-
let env_var_config_toml = ENV_VAR_CONFIG.to_string();
69-
let env_var_config_toml_path = ENV_VAR_PATH_CONFIG.to_string();
70-
let env_var_api_admin_token = ENV_VAR_API_ADMIN_TOKEN.to_string();
67+
let env_var_config_toml = ENV_VAR_CONFIG_TOML.to_string();
68+
let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string();
69+
let env_var_api_admin_token = ENV_VAR_HTTP_API_ACCESS_TOKENS_ADMIN.to_string();
7170

7271
let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) {
7372
println!("Loading configuration from environment variable {config_toml} ...");
@@ -146,7 +145,7 @@ impl AnnouncePolicy {
146145
pub enum Error {
147146
/// Unable to load the configuration from the environment variable.
148147
/// This error only occurs if there is no configuration file and the
149-
/// `TORRUST_TRACKER_CONFIG` environment variable is not set.
148+
/// `TORRUST_TRACKER_CONFIG_TOML` environment variable is not set.
150149
#[error("Unable to load from Environmental Variable: {source}")]
151150
UnableToLoadFromEnvironmentVariable {
152151
source: LocatedError<'static, dyn std::error::Error + Send + Sync>,

packages/configuration/src/v1/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! with the same content as the file.
1010
//!
1111
//! Configuration can not only be loaded from a file, but also from an
12-
//! environment variable `TORRUST_TRACKER_CONFIG`. This is useful when running
12+
//! environment variable `TORRUST_TRACKER_CONFIG_TOML`. This is useful when running
1313
//! the tracker in a Docker container or environments where you do not have a
1414
//! persistent storage or you cannot inject a configuration file. Refer to
1515
//! [`Torrust Tracker documentation`](https://docs.rs/torrust-tracker) for more

packages/primitives/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ pub struct NumberOfBytes(pub i64);
5252
/// For more information about persistence.
5353
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, derive_more::Display, Clone)]
5454
pub enum DatabaseDriver {
55-
// TODO: Move to the database crate once that gets its own crate.
55+
// TODO:
56+
// - Move to the database crate once that gets its own crate.
57+
// - Rename serialized values to lowercase: `sqlite3` and `mysql`.
5658
/// The Sqlite3 database driver.
5759
Sqlite3,
5860
/// The `MySQL` database driver.

share/container/entry_script_sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ chmod -R 2770 /var/lib/torrust /var/log/torrust /etc/torrust
2626

2727

2828
# Install the database and config:
29-
if [ -n "$TORRUST_TRACKER_DATABASE_DRIVER" ]; then
30-
if cmp_lc "$TORRUST_TRACKER_DATABASE_DRIVER" "sqlite3"; then
29+
if [ -n "$TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER" ]; then
30+
if cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER" "Sqlite3"; then
3131

32-
# Select sqlite3 empty database
32+
# Select Sqlite3 empty database
3333
default_database="/usr/share/torrust/default/database/tracker.sqlite3.db"
3434

35-
# Select sqlite3 default configuration
35+
# Select Sqlite3 default configuration
3636
default_config="/usr/share/torrust/default/config/tracker.container.sqlite3.toml"
3737

38-
elif cmp_lc "$TORRUST_TRACKER_DATABASE_DRIVER" "mysql"; then
38+
elif cmp_lc "$TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER" "MySQL"; then
3939

40-
# (no database file needed for mysql)
40+
# (no database file needed for MySQL)
4141

42-
# Select default mysql configuration
42+
# Select default MySQL configuration
4343
default_config="/usr/share/torrust/default/config/tracker.container.mysql.toml"
4444

4545
else
46-
echo "Error: Unsupported Database Type: \"$TORRUST_TRACKER_DATABASE_DRIVER\"."
47-
echo "Please Note: Supported Database Types: \"sqlite3\", \"mysql\"."
46+
echo "Error: Unsupported Database Type: \"$TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER\"."
47+
echo "Please Note: Supported Database Types: \"Sqlite3\", \"MySQL\"."
4848
exit 1
4949
fi
5050
else
51-
echo "Error: \"\$TORRUST_TRACKER_DATABASE_DRIVER\" was not set!"; exit 1;
51+
echo "Error: \"\$TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER\" was not set!"; exit 1;
5252
fi
5353

5454
install_config="/etc/torrust/tracker/tracker.toml"

src/bootstrap/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Initialize configuration from file or env var.
22
//!
3-
//! All environment variables are prefixed with `TORRUST_TRACKER_BACK_`.
3+
//! All environment variables are prefixed with `TORRUST_TRACKER_`.
44
55
use torrust_tracker_configuration::{Configuration, Info};
66

@@ -11,7 +11,7 @@ pub const DEFAULT_PATH_CONFIG: &str = "./share/default/config/tracker.developmen
1111
/// There are two methods to inject the configuration:
1212
///
1313
/// 1. By using a config file: `tracker.toml`.
14-
/// 2. Environment variable: `TORRUST_TRACKER_CONFIG`. The variable contains the same contents as the `tracker.toml` file.
14+
/// 2. Environment variable: `TORRUST_TRACKER_CONFIG_TOML`. The variable contains the same contents as the `tracker.toml` file.
1515
///
1616
/// Environment variable has priority over the config file.
1717
///
@@ -20,7 +20,7 @@ pub const DEFAULT_PATH_CONFIG: &str = "./share/default/config/tracker.developmen
2020
/// # Panics
2121
///
2222
/// Will panic if it can't load the configuration from either
23-
/// `./tracker.toml` file or the env var `TORRUST_TRACKER_CONFIG`.
23+
/// `./tracker.toml` file or the env var `TORRUST_TRACKER_CONFIG_TOML`.
2424
#[must_use]
2525
pub fn initialize_configuration() -> Configuration {
2626
let info = Info::new(DEFAULT_PATH_CONFIG.to_string()).expect("info to load configuration is not valid");

src/console/ci/e2e/runner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn run() {
4646
// Besides, if we don't use port 0 we should get the port numbers from the tracker configuration.
4747
// We could not use docker, but the intention was to create E2E tests including containerization.
4848
let options = RunOptions {
49-
env_vars: vec![("TORRUST_TRACKER_CONFIG".to_string(), tracker_config.to_string())],
49+
env_vars: vec![("TORRUST_TRACKER_CONFIG_TOML".to_string(), tracker_config.to_string())],
5050
ports: vec![
5151
"6969:6969/udp".to_string(),
5252
"7070:7070/tcp".to_string(),

src/console/profiling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//!
2828
//! ```text
2929
//! RUSTFLAGS='-g' cargo build --release --bin profiling \
30-
//! && export TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" \
30+
//! && export TORRUST_TRACKER_CONFIG_TOML_PATH="./share/default/config/tracker.udp.benchmarking.toml" \
3131
//! && valgrind \
3232
//! --tool=callgrind \
3333
//! --callgrind-out-file=callgrind.out \
@@ -40,7 +40,7 @@
4040
//!
4141
//! ```text
4242
//! RUSTFLAGS='-g' cargo build --release --bin profiling \
43-
//! && export TORRUST_TRACKER_PATH_CONFIG="./share/default/config/tracker.udp.benchmarking.toml" \
43+
//! && export TORRUST_TRACKER_CONFIG_TOML_PATH="./share/default/config/tracker.udp.benchmarking.toml" \
4444
//! && valgrind \
4545
//! --tool=callgrind \
4646
//! --callgrind-out-file=callgrind.out \

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@
213213
//! documentation for the [torrust-tracker-configuration crate](https://docs.rs/torrust-tracker-configuration).
214214
//!
215215
//! Alternatively to the `tracker.toml` file you can use one environment
216-
//! variable `TORRUST_TRACKER_CONFIG` to pass the configuration to the tracker:
216+
//! variable `TORRUST_TRACKER_CONFIG_TOML` to pass the configuration to the tracker:
217217
//!
218218
//! ```text
219-
//! TORRUST_TRACKER_CONFIG=$(cat ./share/default/config/tracker.development.sqlite3.toml) ./target/release/torrust-tracker
219+
//! TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.development.sqlite3.toml) ./target/release/torrust-tracker
220220
//! ```
221221
//!
222222
//! In the previous example you are just setting the env var with the contents
@@ -225,7 +225,7 @@
225225
//! The env var contains the same data as the `tracker.toml`. It's particularly
226226
//! useful in you are [running the tracker with docker](https://github.com/torrust/torrust-tracker/tree/develop/docker).
227227
//!
228-
//! > NOTICE: The `TORRUST_TRACKER_CONFIG` env var has priority over the `tracker.toml` file.
228+
//! > NOTICE: The `TORRUST_TRACKER_CONFIG_TOML` env var has priority over the `tracker.toml` file.
229229
//!
230230
//! By default, if you don’t specify any `tracker.toml` file, the application
231231
//! will use `./share/default/config/tracker.development.sqlite3.toml`.

0 commit comments

Comments
 (0)