Skip to content

Commit

Permalink
[#1061] rust lint dependency graph and maintenance update
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardcl committed Sep 17, 2024
1 parent 3f34cea commit 5c67cd5
Show file tree
Hide file tree
Showing 16 changed files with 354 additions and 49 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ jobs:
working-directory: common/jenkins-agents/rust/docker
run: |
docker build --tag agent-rust-test-ubi8 --file Dockerfile.ubi8 \
--build-arg rustVersion=1.80.1 \
--build-arg rustVersion=1.81.0 \
--build-arg rustToolchain=x86_64-unknown-linux-gnu \
--build-arg cargoNextestVersion=0.9.72 \
--build-arg cargoLlvmCovVersion=0.6.11 \
--build-arg cargoGenerateVersion=0.21.3 \
--build-arg cargoNextestVersion=0.9.78 \
--build-arg cargoLlvmCovVersion=0.6.13 \
--build-arg cargoGenerateVersion=0.22.0 \
--build-arg cargoDenyVersion=0.16.1 \
.
jenkins-agent-terraform-ubi8:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fix permissions in Golang agent for the golden tests ([#1052](https://github.com/opendevstack/ods-quickstarters/pull/1052))
- Fix ETL Python QS: AWS Test codepipeline Status Managment and update cryptography dependency([#1056](https://github.com/opendevstack/ods-quickstarters/pull/1052))
- Fix for npm based jenkins agents to support private nexus repositories ([#1059](https://github.com/opendevstack/ods-quickstarters/issues/1059))
- Introduce Rust Quickstarter dependency graph linting (cargo-deny) and upgrade maintenance ([#1061](https://github.com/opendevstack/ods-quickstarters/issues/1061))

### Added

Expand Down
4 changes: 2 additions & 2 deletions be-rust-axum/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ odsQuickstarterPipeline(
// https://cargo-generate.github.io/cargo-generate/index.html
stage('Cargo Generate project') {
sh(
script: "cargo generate --path ${context.sourceDir}/rust-template --name ${context.projectId}-${context.componentId}",
script: "cargo generate --path ${context.sourceDir}/rust-template --name ${context.componentId}",
label: "Process Rust template"
)
sh(
script: "mv ${context.projectId}-${context.componentId} ${context.sourceDir}/files",
script: "mv ${context.componentId} ${context.sourceDir}/files",
label: "Create files folder"
)
}
Expand Down
24 changes: 14 additions & 10 deletions be-rust-axum/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,30 @@ odsComponentPipeline(
]
) { context ->
odsComponentFindOpenShiftImageOrElse(context) {
stageTest(context)
stageCI(context)
odsComponentStageScanWithSonar(context)
stageBuild(context)
odsComponentStageBuildOpenShiftImage(context)
}
odsComponentStageRolloutOpenShiftDeployment(
context, [
'selector': "app=${context.componentId}",
// uncomment this to use values.<ENV>.yaml files to override defaults on values.yaml
// 'helmEnvBasedValuesFiles': ["values.env.yaml"],
]
)
odsComponentStageRolloutOpenShiftDeployment(context, [
'selector': "app.kubernetes.io/name=${context.componentId}"
])
}

def stageBuild(def context) {
stage('Cargo Build') {
sh "cargo build --release"
sh "cp -r target/release/${context.projectId}-${context.componentId} docker/app"
sh "cp -r target/release/${context.componentId} docker/app"
}
}

def stageTest(def context) {
def stageCI(def context) {
stage('Cargo Check') {
sh """
cargo --version
cargo nextest --version
cargo llvm-cov --version
cargo deny --version
cargo check --all-targets
"""
}
Expand All @@ -54,6 +51,13 @@ def stageTest(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
cargo deny check
"""
}
stage('Cargo Test') {
sh """
# create report folders
Expand Down
4 changes: 2 additions & 2 deletions be-rust-axum/ocp.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MEMORY_LIMIT=128Mi
MEMORY_REQUEST=64Mi
MEMORY_LIMIT=64Mi
MEMORY_REQUEST=32Mi
CPU_LIMIT=100m
CPU_REQUEST=50m
21 changes: 20 additions & 1 deletion be-rust-axum/rust-template/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
rev: v8.19.1
hooks:
- id: gitleaks
- repo: https://github.com/EmbarkStudios/cargo-deny
rev: 0.16.1
hooks:
- id: cargo-deny
args: ["--all-features", "check"] # optionally modify the arguments for cargo-deny (default arguments shown here)
- repo: local
hooks:
- id: cargo-fmt
name: Cargo formatter (cargo fmt)
entry: bash -c 'cargo fmt'
language: system
types: [rust]
pass_filenames: false
- id: cargo-clippy
name: Cargo linter (cargo clippy)
entry: bash -c 'cargo clippy'
language: system
types: [rust]
pass_filenames: false
4 changes: 2 additions & 2 deletions be-rust-axum/rust-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
name = "{{project-name}}"
version = "0.1.0"
edition = "2021"
description = "{{project-name}} - from the OpenDevStack Rust QuickStarter."
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.7", features = ["http2"] }
tokio = { version = "1.39", features = ["rt-multi-thread", "macros", "signal"] }
tokio = { version = "1.40", features = ["rt-multi-thread", "macros", "signal"] }

serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
22 changes: 15 additions & 7 deletions be-rust-axum/rust-template/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# {{project-name}} - from the OpenDevStack Rust QuickStarter (be-rust-axum)


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

## Pre-commit hooks

This project uses [pre-commit](https://pre-commit.com).
[Install it](https://pre-commit.com/#install) and apply the already provided pre-commit hooks (see `.pre-commit-config.yaml`) configurations:

```bash
pre-commit install
```

## Adding caching in your CICD

One can improve the build pipeline time by implementing a caching mechanism as shown next:
Expand All @@ -19,15 +27,15 @@ One can improve the build pipeline time by implementing a caching mechanism as s
]
) { context ->
...
stageTest(context)
stageCI(context)
...
stageBuild(context)
...
def stageBuild(def context) {
...
def stageTest(def context) {
def stageCI(def context) {
...
sh "cp -r target/release/${context.projectId}-${context.componentId} docker/app"
sh "cp -r target/release/${context.componentId} docker/app"
...
cp -r target/llvm-cov/html/ build/test-results/coverage
```
Expand Down Expand Up @@ -69,15 +77,15 @@ One can improve the build pipeline time by implementing a caching mechanism as s
]
) { context ->
...
stageTest(context, cachePath)
stageCI(context, cachePath)
...
stageBuild(context, cachePath)
...
def stageBuild(def context, def cachePath) {
...
def stageTest(def context, def cachePath) {
def stageCI(def context, def cachePath) {
...
sh "cp -r ${cachePath}/release/${context.projectId}-${context.componentId} docker/app"
sh "cp -r ${cachePath}/release/${context.componentId} docker/app"
...
cp -r ${cachePath}/llvm-cov/html/ build/test-results/coverage
```
Expand Down
1 change: 0 additions & 1 deletion be-rust-axum/rust-template/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
Selector labels
*/}}
{{- define "chart.selectorLabels" -}}
app: {{ .Values.componentId }}
app.kubernetes.io/name: {{ include "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions be-rust-axum/rust-template/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ securityContext: {}
resources:
limits:
cpu: 100m
memory: 128Mi
memory: 64Mi
requests:
cpu: 50m
memory: 64Mi
memory: 32Mi

autoscaling:
enabled: false
Expand Down
Loading

0 comments on commit 5c67cd5

Please sign in to comment.