From cb25e9ba34d1ab42137a8ce8d3e3f69545bf03a4 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 30 Jan 2023 16:38:25 +0100 Subject: [PATCH 1/2] #96 Add docker and shell linter. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move functions from the ´dogu-build-lib´ to the ´ces-build-lib´ because components like the dogu-operator can use them. --- CHANGELOG.md | 5 ++++- README.md | 19 ++++++++++++++++++- vars/lintDockerfile.groovy | 8 ++++++++ vars/shellCheck.groovy | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 vars/lintDockerfile.groovy create mode 100644 vars/shellCheck.groovy diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b5fe058..85e68de3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## Added +- Function lintDockerfile to lint docker files #96. +- Function shellCheck to lint shell scripts #96. ## [1.60.1](https://github.com/cloudogu/ces-build-lib/releases/tag/1.60.1) - 2022-12-01 ### Fixed @@ -17,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.59.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.59.0) - 2022-11-28 ### Added -- Function `collectAndArchiveLogs` to collect dogu and resource information to help debugging k3s Jenkins buils. #89 +- Function `collectAndArchiveLogs` to collect dogu and resource information to help debugging k3s Jenkins builds. #89 - Function `applyDoguResource(String doguName, String doguNamespace, String doguVersion)` to apply a custom dogu resource into the cluster. This effectively installs a dogu if it is available. #89 diff --git a/README.md b/README.md index 04bcec6d..9026abf9 100644 --- a/README.md +++ b/README.md @@ -1140,7 +1140,7 @@ Example: # Markdown -`Markdown` provides function regardig the `Markdown Files` from the projects docs directory +`Markdown` provides function regarding the `Markdown Files` from the projects docs directory ```groovy Markdown markdown = new Markdown(this) @@ -1151,6 +1151,23 @@ Example: running a container with the latest https://github.com/tcort/markdown-link-check image and verifies that the links in the defined project directory are alive +### DockerLint + +```groovy +lintDockerfile() // uses Dockerfile as default; optional parameter +``` + +See [lintDockerFile](vars/lintDockerfile.groovy) + +### ShellCheck + +```groovy +shellCheck() // search for all .sh files in folder and runs shellcheck +shellCheck(fileList) // fileList="a.sh b.sh" execute shellcheck on a custom list +``` + +See [shellCheck](vars/shellCheck.groovy) + # Steps ## mailIfStatusChanged diff --git a/vars/lintDockerfile.groovy b/vars/lintDockerfile.groovy new file mode 100644 index 00000000..23b9bc52 --- /dev/null +++ b/vars/lintDockerfile.groovy @@ -0,0 +1,8 @@ +package com.cloudogu.ces.cesbuildlib + +def call(String dockerfile = "Dockerfile") { + // only latest version available + docker.image('projectatomic/dockerfile-lint:latest').inside({ + sh "dockerfile_lint -p -f ${dockerfile}" + }) +} diff --git a/vars/shellCheck.groovy b/vars/shellCheck.groovy new file mode 100644 index 00000000..02601b1b --- /dev/null +++ b/vars/shellCheck.groovy @@ -0,0 +1,35 @@ +/** + * shellcheck for jenkins-pipelines https://github.com/koalaman/shellcheck + * + */ +package com.cloudogu.ces.cesbuildlib + +/** + * run shellcheck with a custom fileList + * sample input "test1.sh", "test2.sh" + * + */ +def call(fileList) { + executeWithDocker(fileList) +} + +/** + * run shellcheck on every .sh file inside the project folder + * note: it ignores ./ecosystem folder for usage with ecosystem instances + * + */ +def call() { + def fileList = sh (script: 'find . -path ./ecosystem -prune -o -type f -regex .*\\.sh -print', returnStdout: true) + fileList='"' + fileList.trim().replaceAll('\n','" "') + '"' + executeWithDocker(fileList) +} + +/* +* run the alpine based shellcheck image +* note: we encountered some problems while using the minified docker image +*/ +private def executeWithDocker(fileList){ + docker.image('koalaman/shellcheck-alpine:stable').inside(){ + sh "/bin/shellcheck ${fileList}" + } +} From 31b837b5b69ec0931706bba321a138ec5196d4eb Mon Sep 17 00:00:00 2001 From: Jeremias Weber Date: Mon, 30 Jan 2023 17:05:12 +0100 Subject: [PATCH 2/2] Bump version to 1.62.0 --- CHANGELOG.md | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b680fb..3eafa967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [1.62.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.62.0) - 2023-01-30 ## Added - Function lintDockerfile to lint docker files #96. - Function shellCheck to lint shell scripts #96. diff --git a/pom.xml b/pom.xml index 05393be5..7c515c53 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.cloudogu.ces ces-build-lib ces-build-lib - 1.61.0 + 1.62.0 UTF-8