Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ jobs:
working-directory: common/jenkins-agents/rust/docker
run: |
docker build --tag agent-rust-test-ubi8 --file Dockerfile.ubi8 \
--build-arg rustVersion=1.83.0 \
--build-arg rustVersion=1.88.0 \
--build-arg rustToolchain=x86_64-unknown-linux-gnu \
--build-arg cargoNextestVersion=0.9.87 \
--build-arg cargoLlvmCovVersion=0.6.15 \
--build-arg cargoGenerateVersion=0.22.1 \
--build-arg cargoDenyVersion=0.16.3 \
--build-arg cargoNextestVersion=0.9.94 \
--build-arg cargoLlvmCovVersion=0.6.16 \
--build-arg cargoGenerateVersion=0.23.3 \
--build-arg cargoDenyVersion=0.18.2 \
.

jenkins-agent-terraform-2306-ubi8:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

### Added


### Changed
- Use npm ci in e2e-cypress quickstarter & Better TypeScript support in e2e-cypress quickstarter ([#1114](https://github.com/opendevstack/ods-quickstarters/pull/1114))
- e2e-cypress get rid of additional chrome installation and switch to edge for pdf generation ([#1112](https://github.com/opendevstack/ods-quickstarters/pull/1112))
- Fix for the integration of the Python Quickstarter and Zephyr ODS integration ([#1125](https://github.com/opendevstack/ods-quickstarters/pull/1125))
- Rust QS flag to enable or disable cargo-deny for dependency linting, default to true ([#1107](https://github.com/opendevstack/ods-quickstarters/issues/1107))
- Rust QS enable dynamic toolchain/version support ([#1119](https://github.com/opendevstack/ods-quickstarters/issues/1119))
- Added e2e-cypress specific versioning ([#1128](https://github.com/opendevstack/ods-quickstarters/pull/1128))

### Fixed
Expand Down
23 changes: 14 additions & 9 deletions be-rust-axum/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ odsComponentPipeline(
]
) { context ->
odsComponentFindOpenShiftImageOrElse(context) {
stageCI(context)
stageCI(context, false) // set `auditDependencies` to true if using cargo-deny
odsComponentStageScanWithSonar(context)
stageBuild(context)
odsComponentStageBuildOpenShiftImage(context)
Expand All @@ -27,7 +27,7 @@ def stageBuild(def context) {
}
}

def stageCI(def context) {
def stageCI(def context, def auditDependencies) {
stage('Cargo Check') {
sh """
cargo --version
Expand All @@ -51,20 +51,25 @@ def stageCI(def context) {
cargo clippy --message-format=json &> build/test-results/clippy/report.json
"""
}
stage('Cargo Deny') {
sh """
mkdir -p build/test-results/deny
cargo deny --format json check &> build/test-results/deny/cargo-deny-report.json
cat build/test-results/deny/cargo-deny-report.json
"""
archiveArtifacts artifacts: 'build/test-results/deny/cargo-deny-report.json', fingerprint: true
if (auditDependencies) {
stage('Cargo Deny') {
sh """
mkdir -p build/test-results/deny
cargo deny --format json check &> build/test-results/deny/cargo-deny-report.json
cat build/test-results/deny/cargo-deny-report.json
"""
archiveArtifacts artifacts: 'build/test-results/deny/cargo-deny-report.json', fingerprint: true
}
}
stage('Cargo Test') {
sh """
# create report folders
mkdir -p build/test-results/test
mkdir -p build/test-results/coverage

# If required, pre-install llvm-tools-preview to avoid interactive prompt when not using default Jenkins agent toolchain
# rustup component add llvm-tools-preview --toolchain ${RUST_VERSION}

# Tests with JUnit XML report, as defined in .config/nextest.toml, and coverage LLVM cov report
cargo llvm-cov nextest --profile ci --lcov --output-path ./build/test-results/coverage/lcov.info
cp -r target/nextest/ci/results.xml build/test-results/test
Expand Down
4 changes: 2 additions & 2 deletions be-rust-axum/rust-template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
rev: v8.25.1
hooks:
- id: gitleaks
- repo: https://github.com/EmbarkStudios/cargo-deny
rev: 0.16.3
rev: 0.18.2
hooks:
- id: cargo-deny
args: ["--all-features", "check"] # optionally modify the arguments for cargo-deny (default arguments shown here)
Expand Down
47 changes: 38 additions & 9 deletions be-rust-axum/rust-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@
# Here the project-name (Rust project) is your ODS component name
name = "{{project-name}}"
version = "0.1.0"
edition = "2021"
edition = "2024"
rust-version = "1.88"
description = "{{project-name}} component - from the OpenDevStack Rust QuickStarter."
license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# one can add more dependencies via cargo to Cargo.toml as shown next: cargo add axum -F axum/http2
axum = { version = "0.8", features = ["http2"] }
tokio = { version = "1.40", features = ["rt-multi-thread", "macros", "signal"] }
axum = { version = "0.8", features = ["http2", "macros", "multipart"] }
tokio = { version = "1.44", features = ["rt-multi-thread", "macros", "signal"] }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

http = "1.1"
http = "1.3"
http-body-util = "0.1"
# Highly encouraged to use URL encoding when working with any URI string
# urlencoding = "2.1"
bytes = "1.7"

thiserror = "2.0"

tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["tracing", "env-filter"] }
tracing-subscriber = { version = "0.3", features = ["tracing", "env-filter", "json", "ansi", "fmt"] }

lazy_static = "1.5"

envy = "0.4"
dotenvy = "0.15"

# Nice HTTP middlewares from Tower crate, to be added to router.rs.
# Uncomment as per need, check official docs.
# HTTP middlewares from Tower crate, to be added to router.rs.
# tower-http = { version = "0.6", features = [
# "trace",
# "compression-br",
Expand All @@ -40,9 +42,36 @@ dotenvy = "0.15"
# ] }

# SQLx is the recommended safe and performant package to work with relational DBs like PostgreSQL; check official docs
# sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-rustls", "postgres", "uuid", "json", "time", "macros", "migrate" ] }
# sqlx = { version = "0.8", features = [
# "runtime-tokio",
# "tls-rustls-ring-native-roots",
# "postgres",
# "uuid",
# "json",
# "chrono",
# "macros",
# "migrate"
# ]}

# OTEL; check official docs
# opentelemetry = { version = "0.29", features = ["trace", "metrics"] }
# opentelemetry_sdk = { version = "0.29", features = ["rt-tokio"] }
# opentelemetry-otlp = { version = "0.29", features = ["http-proto", "reqwest-client", "reqwest-rustls"] }
# opentelemetry-http = { version = "0.29" }
# opentelemetry-stdout = { version = "0.29", features = ["trace"] }
# opentelemetry-appender-tracing = { version = "0.29" }
# opentelemetry-semantic-conventions = { version = "0.29" }
# tracing-opentelemetry = { version = "0.30" }

# OpenAPI; check official docs
# utoipa = { version = "5.3", features = ["axum_extras", "uuid", "chrono"] }
# utoipa-axum = "0.2"
# utoipa-swagger-ui = { version = "9.0", features = ["axum"] }
# # utoipa-redoc = { version = "5.0", features = ["axum"] }
# # utoipa-rapidoc = { version = "5.0", features = ["axum"] }
# # utoipa-scalar = { version = "0.2", features = ["axum"] }

[dev-dependencies]
# mockito = "1.5" # mockito is recommended when requiring mocking network requests to either external or internal services
# mockito = "1.7" # mockito is recommended when requiring mocking network requests to either external or internal services
temp-env = { version = "0.3", features = ["async_closure"] } # it is highly recommended the usage of cargo nextest run instead of cargo test; this way each test runs on its own process
tower = { version = "0.5", features = ["util"] }
10 changes: 10 additions & 0 deletions be-rust-axum/rust-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The official OpenDevStack documentation for this QuickStarter can be found [here](https://www.opendevstack.org/ods-documentation/opendevstack/latest/quickstarters/be-rust-axum.html).

Check also the official docs of the [Jenkins Rust Agent](https://www.opendevstack.org/ods-documentation/opendevstack/latest/jenkins-agents/rust.html) this Quickstarter makes use of. There you can see the setup and tools it provides.

## Pre-commit hooks

This project uses [pre-commit](https://pre-commit.com).
Expand All @@ -11,6 +13,14 @@ This project uses [pre-commit](https://pre-commit.com).
pre-commit install
```

The provided pre-commit hooks are:
- gitleaks (check for secrets)
- cargo-deny (dependency auditing, see/update `deny.toml` config file)
- cargo-fmt (formatter, see/update `rustfmt.toml` config file)
- cargo-clippy (linter)

**NOTE**: the cargo hooks also run in Jenkins CICD, but cargo deny is disabled by default, see Jenkinsfile.

## Adding caching in your CICD

One can improve the build pipeline time by implementing a caching mechanism as shown next:
Expand Down
2 changes: 2 additions & 0 deletions be-rust-axum/rust-template/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[template]
exclude = ["chart/templates/*"]
2 changes: 1 addition & 1 deletion be-rust-axum/rust-template/metadata.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Axum - Rust web framework
description: "Axum is an ergonomic and modular web framework built with Tokio, Tower, and Hyper; written in Rust. Technologies: Axum 0.8.x, Rust 1.83.x"
description: "Axum is an ergonomic and modular web framework built with Tokio, Tower, and Hyper; written in Rust. Technologies: Axum 0.8.x, Rust 1.88.x"
supplier: https://github.com/tokio-rs/axum
version: 4.x
type: ods
2 changes: 2 additions & 0 deletions be-rust-axum/rust-template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.88.0"
28 changes: 23 additions & 5 deletions be-rust-axum/rust-template/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# rustfmt configurations from master branch, check rustfmt version
# (cargo fmt --version).
# https://github.com/rust-lang/rustfmt/blob/master/Configurations.md

edition = "2021"
tab_spaces = 2
# ─────────────────────────────────────────────
# 📦 Edition
edition = "2024"
# ─────────────────────────────────────────────
# 📚 Import organization
# group_imports = "StdExternalCrate" # Group: std, external crates, then local
# imports_granularity = "Module" # One use per module line (avoids merge conflicts)
reorder_imports = true # Ensure deterministic ordering
# ─────────────────────────────────────────────
# 📐 Formatting rules
use_field_init_shorthand = true # Use shorthand: { foo } instead of { foo: foo }
match_block_trailing_comma = true # Add trailing commas in multiline match arms
# trailing_comma = "Always" # Always use trailing commas in multiline
newline_style = "Unix" # Use \n (LF) for line endings
tab_spaces = 2 # Use 2 spaces per indentation level
max_width = 100 # Line length limit
# ─────────────────────────────────────────────
# 🧼 Style preferences
# normalize_doc_attributes = true # Normalize #[doc] to /// comments
# wrap_comments = true # Automatically wrap long doc/comments
# format_code_in_doc_comments = true # Format Rust code inside doc comments
# blank_lines_upper_bound = 1 # Avoid excessive vertical whitespace
# blank_lines_lower_bound = 0 # Allow compact block spacing when possible
2 changes: 1 addition & 1 deletion be-rust-axum/rust-template/src/api/router.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use axum::{Json, Router};
use http::StatusCode;
use std::net::SocketAddr;
use tokio::signal::unix::{signal, SignalKind};
use tokio::signal::unix::{SignalKind, signal};
use tracing::info;

use crate::api::routes;
Expand Down
2 changes: 1 addition & 1 deletion be-rust-axum/rust-template/src/api/routes/status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use axum::{routing::get, Json, Router};
use axum::{Json, Router, routing::get};
use http::StatusCode;
use tracing::debug;

Expand Down
5 changes: 1 addition & 4 deletions be-rust-axum/rust-template/src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl Settings {
pub fn new() -> Result<Self, envy::Error> {
dotenv().ok();

let settings = match envy::from_env::<Settings>() {
Ok(config) => config,
Err(error) => return Err(error),
};
let settings = envy::from_env::<Settings>()?;
Ok(settings)
}
}
2 changes: 1 addition & 1 deletion be-rust-axum/rust-template/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {{crate_name}}::api::router::serve;
use {{crate_name}}::config::settings::SETTINGS;

use std::net::SocketAddr;
use tracing_subscriber::{layer::SubscriberExt, Layer, Registry};
use tracing_subscriber::{Layer, Registry, layer::SubscriberExt};

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion be-rust-axum/rust-template/tests/status_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tower::ServiceExt; // for `call`, `oneshot`, and `ready`
use {{crate_name}}::{api::router::app, models::status::Status};

mod common;
use common::{response_json, RequestBuilderExt};
use common::{RequestBuilderExt, response_json};

#[tokio::test]
async fn get_status_route_ok() {
Expand Down
4 changes: 0 additions & 4 deletions be-rust-axum/testdata/golden/jenkins-build-stages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
"stage": "Cargo Clippy",
"status": "SUCCESS"
},
{
"stage": "Cargo Deny",
"status": "SUCCESS"
},
{
"stage": "Cargo Test",
"status": "SUCCESS"
Expand Down
19 changes: 8 additions & 11 deletions common/jenkins-agents/rust/docker/Dockerfile.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@ ENV USER="rust-agent"
ENV CARGO_NEXTEST_VERSION=${cargoNextestVersion} \
CARGO_LLVM_COV_VERSION=${cargoLlvmCovVersion} \
CARGO_GENERATE_VERSION=${cargoGenerateVersion} \
CARGO_DENY_VERSION=${cargoDenyVersion}
CARGO_DENY_VERSION=${cargoDenyVersion} \
RUST_VERSION=${rustVersion}

RUN yum install -y binutils cpp gcc glibc-devel glibc-headers isl kernel-headers libasan libatomic \
libgomp libmpc libpkgconf libubsan libxcrypt-devel llvm-libs pkgconf pkgconf-m4 pkgconf-pkg-config \
openssl-devel cpan perl-IPC-Cmd && \
cpan install FindBin

RUN cd /tmp && \
curl -LfSsO https://static.rust-lang.org/dist/rust-${rustVersion}-${rustToolchain}.tar.gz && \
tar -xzf rust-${rustVersion}-${rustToolchain}.tar.gz && \
rm -f rust-${rustVersion}-${rustToolchain}.tar.gz && \
cd rust-${rustVersion}-${rustToolchain} && \
./install.sh && \
RUN mkdir -p $HOME/.cargo/bin $HOME/.rustup && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
-y --profile complete --default-toolchain ${rustVersion} -t ${rustToolchain} && \
cargo -V && \
mkdir -p $HOME/.cargo/bin && \
# Download binaries and install to $HOME/.cargo/bin
curl --proto '=https' --tlsv1.2 -fsSL https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-$CARGO_NEXTEST_VERSION/cargo-nextest-$CARGO_NEXTEST_VERSION-$rustToolchain.tar.gz | tar xzf - -C "$HOME/.cargo/bin" && \
curl --proto '=https' --tlsv1.2 -fsSL https://github.com/cargo-generate/cargo-generate/releases/download/v$CARGO_GENERATE_VERSION/cargo-generate-v$CARGO_GENERATE_VERSION-$rustToolchain.tar.gz | tar xzf - -C "$HOME/.cargo/bin" && \
# curl --proto '=https' --tlsv1.2 -fsSL https://github.com/taiki-e/cargo-llvm-cov/releases/download/v$CARGO_LLVM_COV_VERSION/cargo-llvm-cov-$rustToolchain.tar.gz | tar xzf - -C "$HOME/.cargo/bin" && \
# cargo LLVM coverage crate is recommended to be compiled as it takes care to add the OS lib dependencies the proper way
# cargo LLVM coverage crate is recommended to be compiled as it takes care to add the OS lib dependencies the proper way
cargo install cargo-llvm-cov --locked --version $CARGO_LLVM_COV_VERSION && \
# install cargo deny as release sources do not provide our rust toolchain target
cargo install cargo-deny --locked --version $CARGO_DENY_VERSION && \
Expand All @@ -43,5 +40,5 @@ RUN cd /tmp && \
cargo generate --version && \
cargo deny --version

RUN chgrp -R 0 $HOME/.cargo && \
chmod -R g=u $HOME/.cargo
RUN chgrp -R 0 $HOME/.cargo $HOME/.rustup && \
chmod -R g=u $HOME/.cargo $HOME/.rustup
10 changes: 5 additions & 5 deletions common/jenkins-agents/rust/ocp-config/bc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ parameters:
- name: RUST_VERSION
description: "The Rust version"
required: true
value: "1.83.0"
value: "1.88.0"
- name: RUST_TOOLCHAIN
description: "The Rust target toolchain"
required: true
value: "x86_64-unknown-linux-gnu"
- name: CARGO_NEXTEST_VERSION
description: "The Cargo Nextest testing framework version"
required: true
value: "0.9.87"
value: "0.9.94"
- name: CARGO_LLVM_COV_VERSION
description: "The Cargo LLVM Coverage tool version"
required: true
value: "0.6.15"
value: "0.6.16"
- name: CARGO_GENERATE_VERSION
description: "The Cargo Generate tool version"
required: true
value: "0.22.1"
value: "0.23.3"
- name: CARGO_DENY_VERSION
description: "The Cargo Deny tool version"
required: true
value: "0.16.3"
value: "0.18.2"
objects:
- apiVersion: build.openshift.io/v1
kind: BuildConfig
Expand Down
Loading