Last active
August 22, 2024 04:24
-
-
Save LukeMathWalker/d98fa8d0fc5394b347adf734ef0e85ec to your computer and use it in GitHub Desktop.
GitLab CI - Rust setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: "rust:latest" | |
default: | |
before_script: | |
- rustc --version | |
- cargo --version | |
stages: | |
- test | |
test-code: | |
stage: test | |
script: | |
- cargo test | |
- cargo install cargo-tarpaulin | |
- cargo tarpaulin --ignore-tests | |
lint-code: | |
stage: test | |
script: | |
- rustup component add clippy | |
- cargo clippy -- -D warnings | |
format-code: | |
stage: test | |
script: | |
- rustup component add rustfmt | |
- cargo fmt -- --check | |
audit-code: | |
stage: test | |
script: | |
- cargo install cargo-audit | |
- cargo audit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Valmirius , you can use Gitlab CI services for the tests and coverage jobs:
the way it works is that gitlab runner instantiates another container (the service), and you can make requests to it with a hostname the same as the service name. The
variables
section allows you to set whatever the service requires to work. At hub.docker.com for postgres image, you can find that you require thosePOSTGRES_
suffixed variables.I added
DATABASE_URL
variable to override what the.env
file has as default, you may recall that it uses localhost as hostname. For that t o work I needed to add the following line to tests/health_check.rs so that the configuration read from the yaml overrides the url string that gets built when configuration is read using yaml:let connection_string = configuration.database.connection_string(); + let env_connection_string = std::env::var("DATABASE_URL").unwrap_or(connection_string); let mut connection = PgConnection::connect(&env_connection_string)
I know that config allows env variables to get this same effect, but haven't found how to make it work. This solution at least works for me currently.