Before you can contribute to this project, you need to install and set up the following tools:
-
Rust: Install Rust through
rustup, which you can get from the official Rust website. After installation, you can verify it by runningcargo --versionin your terminal. -
Just: Install
just, a command runner that simplifies project workflows. You can find the installation instructions in the official just documentation. After installation, you can verify it by runningjust --versionin your terminal. -
Mozilla SOPS: Install SOPS for managing encrypted environment variables. You can find the installation instructions in the official SOPS documentation. After installation, you can verify it by running
sops --versionin your terminal. -
Age: Age is a simple, modern and secure file encryption tool, used by SOPS for encrypting secrets. You can install it from the official Age GitHub repository. After installation, you can verify it by running
age --versionin your terminal. -
Docker: Install Docker from the official Docker website. After installation, you can verify it by running
docker --versionin your terminal.
Please ensure you have all these prerequisites in place before you start contributing to the project.
Tip
You can run just --list to see all available development tasks.
Code formatting is automatically enforced using rustfmt.
Warning
Automatic imports formatting require the use of nightly Rust toolchain.
just fmtTo check Rust code formatting without making changes, you can use:
just fmt-checkCode linting is automatically enforced using clippy.
In the CI pipeline, we use the following command to run the linter:
just checkTip
Tests that require access to secrets should be run using the encrypted .env file.
Refer to the CI Secrets section for more information.
To run the project unit tests, you can use the following command:
just test-unitTo run the project integration tests, you can use the following command:
just test-itThis project uses pre-commit to automatically run code formatting checks before commits are made. Git hooks help ensure code quality and consistency by automatically running the formatting tools whenever you commit changes.
Note
Git hooks are optional and opt-in. You can contribute to the project without installing them, but they provide a convenient way to automatically format your code before commits.
Before setting up Git hooks, you need to install pre-commit. You can install it using your preferred package manager:
# Using pip
pip install pre-commit
# Using pacman (Arch Linux)
pacman -S pre-commit
# Using apt (Ubuntu/Debian)
apt-get install pre-commit
# Using Homebrew (macOS)
brew install pre-commitTo install the pre-commit hooks for this project, run:
just install-git-hooksThis command will:
- Check if
pre-commitis installed on your system - Install the pre-commit hooks defined in
.github/pre-commit-config.yaml
If you need to remove the Git hooks, you can run:
just remove-git-hooksYou can also run the pre-commit hooks manually without making a commit:
# Run all hooks on all files
pre-commit run --all-files --config .github/pre-commit-config.yaml
# Run specific hook
pre-commit run format --config .github/pre-commit-config.yamlTip
If you need to commit changes without running the hooks (not recommended), you can use git commit --no-verify.
In this project, we handle secrets through an encrypted .env file. This file holds various environment variables,
encrypted using Mozilla SOPS, a secure tool for managing and storing secrets. We
utilize Age, a simple, modern, and secure file encryption tool, as the encryption
backend for SOPS. This method allows us to manage secrets without the need for contributors to access GitHub Actions
secrets, offering a secure way to introduce new test credentials required by the tests.
-
Install Age and SOPS: Ensure you have both Age and SOPS installed on your machine. For more information refer to the Prerequisites section.
-
Generate a new key pair: Generate a new key pair using the following command:
age-keygen -o keys.txt
This command generates a new key pair and saves it to the
keys.txtfile. This key pair is used to encrypt and decrypt the.envfile.According to the SOPS documentation, by default SOPS will look for a
<user-config-dir>/sops/age/keys.txtfile under the user's configuration directory (e.g.,$XDG_CONFIG_HOME/sops/age/keys.txtin Linux).
To run the tests, you need to decrypt the .env file using the sops exec-env command. This command decrypts the
.env file and sets the environment variables for the command that follows it.
For example, to execute the project integration tests with the decrypted environment variables, you can use the following command:
sops exec-env .env "just test-it"The command above assumes that a valid keys.txt file is present in the user's configuration directory.
Alternatively, if you have a different key file or location, you can specify it using the SOPS_AGE_KEY_FILE
environment variable or passing the Age private key content directly to the sops exec-env command via
the SOPS_AGE_KEY environment variable.
SOPS_AGE_KEY_FILE=/path/to/keys.txt sops exec-env .env "just test-it"In order to any new contributor to be able to decrypt the .env file, the file needs to be encrypted using their public
key. To do so, we need to add the new contributor's public key as recipients to the .env file. To do so, you have to
ask a project maintainer to encrypt the .env file using the new contributor's public key. To do so, run the following
command:
sops --rotate --add-age <new-recipient-age-key> --in-place .envThe command above assumes that the .env file is already encrypted with the public keys of the project contributors,
and the project maintainer has the private keys to decrypt the file.
Once your Age public key is associated with the .env file, you can add new secrets to the file. To do so, you can use
the following command to add a new secret to the file:
sops --set '["<env-var-name>"] "<env-var-value>"' .envNote that the env-var-name and env-var-value should be replaced with the name and value of the new environment
variable you want to add to the .env file. If an environment variable with the same name already exists, the command
will update the value of the existing environment variable.
Warning
This procedure is completely discouraged due to the .env file.
Refer to the Adding new contributors public keys
or Adding new secrets sections for a safer way to manipulate the .env file.
To encrypt the .env file in-place, you can use the following command where <recipien-age-key> are the public keys
of the different project contributors:
sops --encrypt --age <recipient-age-key>[,<recipient-age-key>,...] .envAssuming that the .env file is encrypted with the public keys of the project contributors, and your private key is
present in the keys.txt file, you can decrypt the .env file using the following command:
sops --decrypt .envBoth commands will print the decrypted content to the standard output. If you want to save the decrypted content to a
file, you can redirect the output to a file, or use the --in-place flag to overwrite the file in-place.