Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically

Create jenkins docker images and build them periodicaly and scan using trivy
https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically

configuration-as-code docker dockerfile dockerhub groovy jenkins plugins trivy

Last synced: about 1 month ago
JSON representation

Create jenkins docker images and build them periodicaly and scan using trivy

Awesome Lists containing this project

README

        

# create-jenkins-docker-image-and-publish-periodically
Create jenkins docker images and build them periodicaly and scan using trivy

[![Generic badge](https://img.shields.io/badge/maintained-yes-6acb14.svg)](https://shields.io/)
[![Generic badge](https://img.shields.io/badge/maintained%20by-githubofkrishnadhas-6acb14.svg)](https://shields.io/)

[![build-publish-jenkins-jdk11-image](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-image.yaml/badge.svg)](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-image.yaml)
[![build-publish-jenkins-jdk17-image](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-jdk17-image.yaml/badge.svg)](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-jdk17-image.yaml)
[![build-publish-jenkins-jdk21-image](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-jdk21-image.yaml/badge.svg)](https://github.com/devwithkrishna/create-jenkins-docker-image-and-publish-periodically/actions/workflows/build-publish-jenkins-jdk21-image.yaml)

![Github stars](https://badgen.net/github/stars/devwithkrishna/create-jenkins-docker-image-and-publish-periodically?icon=github&label=stars)
![Github forks](https://badgen.net/github/forks/devwithkrishna/create-jenkins-docker-image-and-publish-periodically?icon=github&label=forks)
![Github issues](https://img.shields.io/github/issues/devwithkrishna/create-jenkins-docker-image-and-publish-periodically)
![Github last commit](https://img.shields.io/github/last-commit/devwithkrishna/create-jenkins-docker-image-and-publish-periodically)

[![Docker Pulls](https://badgen.net/docker/pulls/dockerofkrishnadhas/jenkins-core-image?icon=docker&label=jenkins-core-image%20pulls)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-image/)
[![Docker Pulls](https://badgen.net/docker/pulls/dockerofkrishnadhas/jenkins-core-jdk17-image?icon=docker&label=jenkins-core-jdk17-image%20pulls)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-jdk17-image/)
[![Docker Pulls](https://badgen.net/docker/pulls/dockerofkrishnadhas/jenkins-core-jdk21-image?icon=docker&label=jenkins-core-jdk21-image%20pulls)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-jdk21-image/)

[![Docker Image Size](https://badgen.net/docker/size/dockerofkrishnadhas/jenkins-core-image?icon=docker&label=jenkins-core-image-image%20size)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-image/)
[![Docker Image Size](https://badgen.net/docker/size/dockerofkrishnadhas/jenkins-core-jdk17-image?icon=docker&label=jenkins-core-jdk17-image%20size)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-jdk17-image/)
[![Docker Image Size](https://badgen.net/docker/size/dockerofkrishnadhas/jenkins-core-jdk21-image?icon=docker&label=jenkins-core-jdk21-image%20size)](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-jdk21-image/)

# Images being built and updated

| Image Name | jdk version |
|----------------------------------------------|--------------|
| dockerofkrishnadhas/jenkins-core-image | jdk11 |
| dockerofkrishnadhas/jenkins-core-jdk17-image | jdk17 |
| dockerofkrishnadhas/jenkins-core-jdk21-image | jdk21 |

# How everything works

* Dockerfile --> The core instructions on building jenkins docker image

* plugins.yaml --> The list of plugins installed in java once booted by default. its file name should be either plugins.yaml or plugins.txt

* user.groovy --> This creates a user with name as of `JENKINS_USER` and with password `JENKINS_PASS` who will be the default user and security will be enabled using `Jenkins OWN Databse` by default.

* number_of_executors.groovy --> this script is used to increase the `numOfExecutors` in Jenkins from 2 to `x` where `x` is the value of numberOfExecutors provided in the script.

* get_latest_version_create_tag.sh --> gets the tag to create on github and set it as a github env variable and push tag to github

* config-as-code.yaml --> This uses Configuration as Code plugin from Jenkins to set up some default settings like setting up a GitHub App as a credential.

* **To use JCasC, you need to install the Configuration as Code plugin.** [configuration-as-code](https://plugins.jenkins.io/configuration-as-code/)

* examples of how to use config as code plugin [jenkinsci/configuration-as-code-plugin](https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos/role-strategy-auth)

* The jenkins/jenkins image allows you to enable or disable the setup wizard by passing in a system property named `jenkins.install.runSetupWizard` via the JAVA_OPTS environment variable. Users of the image can pass in the JAVA_OPTS environment variable at runtime using the --env flag to docker run. However, this approach would put the bonus of disabling the setup wizard on the user of the image. Instead, you should disable the setup wizard at build time, so that the setup wizard is disabled by default.

# Softwares Installed in Jenkins

* Docker Latest available version for Debian.

* Azure CLI latest available version for Debian.

* Latest Jenkins CLI version to install plugin manager and install plugins.

# How to run the code locally
* make sure docker and docker-compose are present on your machine
* clone the repo
* cd to the repo directory
* To build the image locally, use

` docker build --build-arg JENKINS_USER= --build-arg JENKINS_PASS= -t .`

Replace the **JENKINS_USER** , **JENKINS_PASS** with your values.

Eg: docker build --build-arg JENKINS_USER=user --build-arg JENKINS_PASS=password -t devwithkrishna-jenkins-image:latest .

***The . at the end of docker build command is mandatory***

:round_pushpin: **GITHUB_APP_KEY** , **GITHUB_APP_ID** are required by configuration as code plugin to set up GitHub app credentials :round_pushpin:

:pushpin:These values **GITHUB_APP_KEY** , **GITHUB_APP_ID** will be passed as environment variables on deployment time either through docker compose file or as -e flag.

# Things to remember
* When configuring up the GitHub app credential in Jenkins, it needs to be in a specific format .
Details can be found here - [github-app-auth](https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/github-app-auth)

* Post generating the Private key of GitHub app, this needs to be converted into a specific format
Use the command [here](https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/github-app-auth#_converting_the_private_key_for_jenkins) , This will be the value we will be passing as `GITHUB_APP_KEY`

```
openssl pkcs8 -topk8 -inform PEM -outform PEM -in -out -nocrypt
```
* --> Replace with your pem file path of app private key.
* --> The converted output which you need to update to jenkins.

I am passing the `GITHUB_APP_KEY` & `GITHUB_APP_ID` at build time from github secrets and storing it as env variables in image.

# Image 👉 [jenkins-core-image available here](https://hub.docker.com/r/dockerofkrishnadhas/jenkins-core-image)