DISCLAIMER: I am not a good rust dev, if you see some stuff that could be done better you can create a pull request.
The config-injector is a Rust-based tool that processes configuration files, replacing placeholders with environment
variable values. It reads files, searches for placeholders in the format {{VAR_NAME}}, and replaces them with the
respective values of environment variables. If a variable is not found, it logs a warning and leaves the placeholder
intact.
- Docker
- Rust installed locally (optional if you are using Docker for cross-compilation)
To build the project for Linux (even if you're on Windows), use the provided Docker environment:
Run the following command to build the Docker image:
docker build -t rust-cross-compilation .This will create a Docker image named rust-cross-compilation based on the provided Dockerfile.
Run the following command to start a Docker container and open an interactive shell:
docker run -it --rm -v ${PWD}:/usr/src/config-injector rust-cross-compilation /bin/bashThis mounts the current directory (${PWD}) into the container and starts an interactive shell. The directory inside
the container will be /usr/src/config-injector.
Inside the Docker container, run the following command to add the necessary target for Linux cross-compilation:
rustup target add x86_64-unknown-linux-gnuNow, compile the project for the Linux target:
cargo build --release --target x86_64-unknown-linux-gnuThis will generate the compiled binary in the path
/usr/src/config-injector/target/x86_64-unknown-linux-gnu/release/config-injector.
To retrieve the compiled binary from the Docker container, use the following command, replacing <container_id> with
the actual container ID (you can get it using docker ps):
docker cp <container_id>:/usr/src/config-injector/target/x86_64-unknown-linux-gnu/release/config-injector ${PWD}/output/config-injectorThis will copy the config-injector binary from the container to a local directory (${PWD}/output).
After building the binary, you can use the config-injector tool by following these steps:
-
Set Environment Variables
Set the environment variables that the tool will use for substitution. For example:
export SERVER_LICENSEKEY="your_license_key" export FILES_TO_PROCESS="server-data/server.cfg,txData/default/config.json"
-
Run the Binary
Run the
config-injectorbinary, which will replace placeholders in the specified files:.config-injector
The tool will process the files specified in the
FILES_TO_PROCESSenvironment variable. Any placeholder in the format{{VAR_NAME}}will be replaced with the corresponding environment variable value.If an environment variable is not found, it logs a warning and leaves the placeholder intact.
This environment variable specifies which files should be processed. The files are separated by commas. For example:
export FILES_TO_PROCESS="server-data/server.cfg,txData/default/config.json"The tool searches for placeholders using the following pattern: {{VAR_NAME}}, where VAR_NAME is an uppercase
environment variable name.