Skip to content

Commit

Permalink
Merge branch 'release/1.67.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jelemux committed Sep 4, 2023
2 parents 2ecaf0f + 3787386 commit fc649b9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


## [Unreleased]
## [1.67.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.67.0) - 2023-09-04
### Changed
- Switch to hadolint Dockerfile linter; #111

### Added
- Add Dockerfile class with new linting functions; #111
- `lint()` lints with default hadolint config parameters. Only fails on errors
- `lintWithConfig()` lets you specify the hadolint configuration

### Deprecated
- `lintDockerfile()` function should be replaced by the Dockerfile `lint()` function

## [1.66.0](https://github.com/cloudogu/ces-build-lib/releases/tag/1.66.1) - 2023-09-04
## [1.66.1](https://github.com/cloudogu/ces-build-lib/releases/tag/1.66.1) - 2023-09-04
### Fixed
- Split helm-repo-config in separate values #113

Expand Down
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Jenkins Pipeline Shared library, that contains additional features for Git, Mave
- [Additional features provided by the `Docker` class](#additional-features-provided-by-the-docker-class)
- [`Docker.Image` methods provided by the docker plugin](#dockerimage-methods-provided-by-the-docker-plugin)
- [Additional features provided by the `Docker.Image` class](#additional-features-provided-by-the-dockerimage-class)
- [Dockerfile](#dockerfile)
- [SonarQube](#sonarqube)
- [Constructors](#constructors)
- [A complete example](#a-complete-example)
Expand Down Expand Up @@ -79,10 +80,10 @@ Jenkins Pipeline Shared library, that contains additional features for Git, Mave
* Install [Pipeline: GitHub Groovy Libraries](https://wiki.jenkins.io/display/JENKINS/Pipeline+GitHub+Library+Plugin)
* Use the Library in any Jenkinsfile like so
```
@Library('github.com/cloudogu/ces-build-lib@6cd41e0')
@Library('github.com/cloudogu/ces-build-lib@1.67.0')
import com.cloudogu.ces.cesbuildlib.*
```
* Best practice: Use a defined version (e.g. a git commit hash or a git tag, such as `6cd41e0` or `1.49.0` in the example above) and not a branch such as `develop`. Otherwise, your build might change when the there is a new commit on the branch. Using branches is like using snapshots!
* Best practice: Use a defined version (e.g. a git commit hash or a git tag, such as `6cd41e0` or `1.67.0` in the example above) and not a branch such as `develop`. Otherwise, your build might change when the there is a new commit on the branch. Using branches is like using snapshots!
* When build executors are docker containers and you intend to use their Docker host in the Pipeline: Please see [#8](https://github.com/cloudogu/ces-build-lib/issues/8#issuecomment-353584252).

# Syntax completion
Expand Down Expand Up @@ -712,6 +713,22 @@ new Docker(this).image('kkarczmarczyk/node-yarn:8.0-wheezy')
}
```

# Dockerfile

The `Dockerfile` class provides functions to lint Dockerfiles. For example:

```groovy
stage('Lint') {
Dockerfile dockerfile = new Dockerfile(this)
dockerfile.lint() // Lint with default configuration
dockerfile.lintWithConfig() // Use your own hadolint configuration with a .hadolint.yaml configuration file
}
```

The tool [hadolint](https://github.com/hadolint/hadolint) is used for linting. It has a lot of configuration parameters
which can be set by creating a `.hadolint.yaml` file in your working directory.
See https://github.com/hadolint/hadolint#configure

# SonarQube

When analyzing code with SonarQube there are a couple of challenges that are solved using ces-build-lib's
Expand Down Expand Up @@ -1159,7 +1176,10 @@ Additionally, the markdown link checker can be used with a specific version (def
markdown.check()
```

### DockerLint
### DockerLint (Deprecated)

Use Dockerfile.lint() instead of lintDockerfile()!
See [Dockerfile](#dockerfile)

```groovy
lintDockerfile() // uses Dockerfile as default; optional parameter
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.cloudogu.ces</groupId>
<artifactId>ces-build-lib</artifactId>
<name>ces-build-lib</name>
<version>1.66.1</version>
<version>1.67.0</version>


<properties>
Expand Down
39 changes: 39 additions & 0 deletions src/com/cloudogu/ces/cesbuildlib/Dockerfile.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.cloudogu.ces.cesbuildlib

class Dockerfile {
private script

Dockerfile(script) {
this.script = script
}

/**
* Lints the Dockerfile with hadolint using a configuration file
*
* To configure hadelint, add a ".hadolint.yaml" file to your working directory
* See https://github.com/hadolint/hadolint#configure
*
* @param dockerfile Path to the Dockerfile that should be linted
* @param configuration Path to the hadolint configuration file
* @param hadolintVersion Version of the hadolint/hadolint container image
*/
void lintWithConfig(String dockerfile = "Dockerfile", String configuration = ".hadolint.yaml", hadolintVersion = "latest-debian"){
script.docker.image("hadolint/hadolint:${hadolintVersion}").inside(){
script.sh "hadolint --no-color -c ${configuration} ${dockerfile}"
}
}

/**
* Lints the Dockerfile with the latest version of hadolint
* Only fails on errors, ignores warnings etc.
* Trusts registries docker.io, gcr.io and registry.cloudogu.com
*
* @param dockerfile Path to the Dockerfile that should be linted
* @param hadolintVersion Version of the hadolint/hadolint container image
*/
void lint(String dockerfile = "Dockerfile", hadolintVersion = "latest-debian"){
script.docker.image("hadolint/hadolint:${hadolintVersion}").inside(){
script.sh "hadolint -t error --no-color --trusted-registry docker.io --trusted-registry gcr.io --trusted-registry registry.cloudogu.com ${dockerfile}"
}
}
}
10 changes: 6 additions & 4 deletions vars/lintDockerfile.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.cloudogu.ces.cesbuildlib

@Deprecated
def call(String dockerfile = "Dockerfile") {
// only latest version available
docker.image('projectatomic/dockerfile-lint:latest').inside({
sh "dockerfile_lint -p -f ${dockerfile}"
})
docker.image('hadolint/hadolint:latest-debian').inside(){
sh "hadolint --no-color -t error " +
"--trusted-registry docker.io --trusted-registry gcr.io --trusted-registry registry.cloudogu.com " +
"${WORKSPACE}/${dockerfile}"
}
}

0 comments on commit fc649b9

Please sign in to comment.