-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,162 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
def odsNamespace = '' | ||
def odsGitRef = '' | ||
def odsImageTag = '' | ||
def sharedLibraryRef = '' | ||
def agentImageTag = '' | ||
|
||
node { | ||
odsNamespace = env.ODS_NAMESPACE ?: 'ods' | ||
odsGitRef = env.ODS_GIT_REF ?: 'master' | ||
odsImageTag = env.ODS_IMAGE_TAG ?: 'latest' | ||
sharedLibraryRef = env.SHARED_LIBRARY_REF ?: odsImageTag | ||
agentImageTag = env.AGENT_IMAGE_TAG ?: odsImageTag | ||
} | ||
|
||
library("ods-jenkins-shared-library@${sharedLibraryRef}") | ||
|
||
odsQuickstarterPipeline( | ||
imageStreamTag: "${odsNamespace}/jenkins-agent-rust:${agentImageTag}", | ||
) { context -> | ||
|
||
// 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}", | ||
label: "Process Rust template" | ||
) | ||
sh( | ||
script: "mv ${context.sourceDir}/${context.projectId}-${context.componentId} ${context.sourceDir}/files", | ||
label: "Create files folder" | ||
) | ||
} | ||
|
||
odsQuickstarterStageCopyFiles(context) | ||
|
||
odsQuickstarterStageRenderJenkinsfile(context) | ||
|
||
odsQuickstarterStageRenderSonarProperties(context) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// See https://www.opendevstack.org/ods-documentation/ for usage and customization. | ||
|
||
@Library('ods-jenkins-shared-library@@shared_library_ref@') _ | ||
|
||
odsComponentPipeline( | ||
imageStreamTag: '@ods_namespace@/jenkins-agent-rust:@agent_image_tag@', | ||
branchToEnvironmentMapping: [ | ||
'master': 'dev', | ||
// 'release/': 'test' | ||
] | ||
) { context -> | ||
odsComponentFindOpenShiftImageOrElse(context) { | ||
stageTest(context) | ||
odsComponentStageScanWithSonar(context) | ||
stageBuild(context) | ||
odsComponentStageBuildOpenShiftImage(context) | ||
} | ||
odsComponentStageRolloutOpenShiftDeployment( | ||
context, [ | ||
'selector': "app.kubernetes.io/instance=${context.componentId}", | ||
'helmEnvBasedValuesFiles': ["values.env.yaml"], | ||
] | ||
) | ||
} | ||
|
||
def stageBuild(def context) { | ||
stage('Cargo Build') { | ||
sh "cargo build --release" | ||
sh "cp -r target/release/${context.projectId}-${context.componentId} docker/app" | ||
} | ||
} | ||
|
||
def stageTest(def context) { | ||
stage('Cargo Check') { | ||
sh """ | ||
cargo check --all-targets | ||
""" | ||
} | ||
stage('Cargo Format') { | ||
sh """ | ||
cargo fmt --all -- --check | ||
""" | ||
} | ||
stage('Cargo Clippy') { | ||
sh """ | ||
cargo clippy --all-features | ||
|
||
# Clippy reports for SonarQube | ||
mkdir -p build/test-results/clippy | ||
cargo clippy --message-format=json &> build/test-results/clippy/report.json | ||
""" | ||
} | ||
stage('Cargo Test') { | ||
sh """ | ||
# create report folders | ||
mkdir -p build/test-results/test | ||
mkdir -p build/test-results/coverage | ||
|
||
# Tests with JUnit XML report as defined in .config/nextest.toml | ||
cargo nextest run --profile ci | ||
|
||
# Coverage with LLVM lcov report from tests | ||
# generate the lcov.info report | ||
cargo llvm-cov --lcov --output-path ./build/test-results/coverage/lcov.info | ||
# generate the html report | ||
cargo llvm-cov report --html | ||
|
||
cp -r target/nextest/ci/results.xml build/test-results/test | ||
cp -r target/llvm-cov/html/ build/test-results/coverage | ||
""" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Rust Axum Quickstarter (be-rust-axum) | ||
|
||
Documentation is located in our [official documentation](https://www.opendevstack.org/ods-documentation/ods-quickstarters/latest/index.html) | ||
|
||
Please update documentation in the [antora page directory](https://github.com/opendevstack/ods-quickstarters/tree/master/docs/modules/ROOT/pages) | ||
|
||
Tested thru [automated tests](../tests/be-rust-axum) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MEMORY_LIMIT=128Mi | ||
MEMORY_REQUEST=64Mi | ||
CPU_LIMIT=100m | ||
CPU_REQUEST=50m |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[profile.ci.junit] | ||
path = "results.xml" | ||
store-success-output = true | ||
store-failure-output = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Editor configuration, see https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = tab | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/target | ||
/build | ||
.vscode | ||
.DS_Store | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
repos: | ||
- repo: https://github.com/gitleaks/gitleaks | ||
rev: v8.16.1 | ||
hooks: | ||
- id: gitleaks |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[package] | ||
name = "{{project-name}}" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "{{project-name}} - 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.35", features = ["rt-multi-thread", "macros"] } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
http = "1.0" | ||
http-body-util = "0.1" | ||
bytes = "1.5" | ||
thiserror = "1.0" | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3", features = ["tracing", "env-filter"] } | ||
lazy_static = "1.4" | ||
|
||
# Nice HTTP middlewares from Tower crate, check router.rs commented code. | ||
# Uncomment as per need, check official docs. | ||
# tower-http = { version = "0.5", features = [ | ||
# "trace", | ||
# "compression-br", | ||
# "propagate-header", | ||
# "sensitive-headers", | ||
# "cors", | ||
# ] } | ||
|
||
# SQLx is the recommended safe and performant package to work with relational DBs like PostgreSQL; check official docs | ||
# sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "postgres", "uuid", "json", "time", "macros", "migrate" ] } | ||
|
||
# One can use envy crate for more automated env vars management, see docs. | ||
# envy = "*" | ||
# One can use dotenvy crate for automating ingestion of env vars from .env file. | ||
# dotenvy = "*" | ||
|
||
[dev-dependencies] | ||
tower = { version = "0.4", features = ["util"] } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v2 | ||
name: {{project-name}} | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "0.1.0" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Component {{ .Values.componentId }} on version {{ .Values.imageTag }} released with Helm! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "chart.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "chart.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "chart.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "chart.labels" -}} | ||
helm.sh/chart: {{ include "chart.chart" . }} | ||
{{ include "chart.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "chart.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "chart.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "chart.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "chart.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
78 changes: 78 additions & 0 deletions
78
be-rust-axum/rust-template/chart/templates/deployment.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.componentId }} | ||
labels: | ||
{{- include "chart.labels" . | nindent 4 }} | ||
spec: | ||
{{- if not .Values.autoscaling.enabled }} | ||
replicas: {{ .Values.replicaCount }} | ||
{{- end }} | ||
strategy: | ||
type: RollingUpdate | ||
rollingUpdate: | ||
maxUnavailable: 0% | ||
maxSurge: 50% | ||
selector: | ||
matchLabels: | ||
{{- include "chart.selectorLabels" . | nindent 6 }} | ||
template: | ||
metadata: | ||
{{- with .Values.podAnnotations }} | ||
annotations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
labels: | ||
{{- include "chart.selectorLabels" . | nindent 8 }} | ||
spec: | ||
{{- with .Values.imagePullSecrets }} | ||
imagePullSecrets: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
serviceAccountName: {{ include "chart.serviceAccountName" . }} | ||
securityContext: | ||
{{- toYaml .Values.podSecurityContext | nindent 8 }} | ||
containers: | ||
- name: {{ .Values.componentId }} | ||
securityContext: | ||
{{- toYaml .Values.securityContext | nindent 12 }} | ||
image: "{{ .Values.registry }}/{{ .Values.imageNamespace }}/{{ .Values.componentId }}:{{ .Values.imageTag }}" | ||
imagePullPolicy: IfNotPresent | ||
ports: | ||
- name: http | ||
containerPort: {{ .Values.service.port }} | ||
protocol: TCP | ||
livenessProbe: | ||
failureThreshold: 3 | ||
httpGet: | ||
path: "/status" | ||
port: {{ .Values.service.port }} | ||
scheme: HTTP | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
successThreshold: 1 | ||
timeoutSeconds: 3 | ||
readinessProbe: | ||
failureThreshold: 1 | ||
httpGet: | ||
path: "/status" | ||
port: {{ .Values.service.port }} | ||
scheme: HTTP | ||
initialDelaySeconds: 3 | ||
periodSeconds: 5 | ||
successThreshold: 1 | ||
timeoutSeconds: 3 | ||
resources: | ||
{{- toYaml .Values.resources | nindent 12 }} | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{- toYaml . | nindent 8 }} | ||
{{- end }} |
Oops, something went wrong.