Skip to content

Commit 11b9b6e

Browse files
authored
Merge pull request #148 from DontShaveTheYak/develop
Release v0.11.1
2 parents 3d15c7d + ce848fc commit 11b9b6e

21 files changed

+274
-64
lines changed

.devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Sets the run context to one level up instead of the .devcontainer folder.
66
"context": "..",
77
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
8-
"dockerFile": "../.devcontainer/Dockerfile",
8+
"dockerFile": "../docker/dev/Dockerfile",
99
// Set *default* container specific settings.json values on container create.
1010
"settings": {
1111
"editor.insertSpaces": true,

.github/workflows/docker.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
paths:
8+
- 'docker/prod/*'
9+
10+
jobs:
11+
prod:
12+
name: Build and Push
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v1
18+
19+
- name: Login to DockerHub
20+
uses: docker/login-action@v1
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Build and push
26+
id: prod_image
27+
uses: docker/build-push-action@v2
28+
with:
29+
push: true
30+
tags: "dsty/jenkins:${{ contains(github.ref_name, 'SNAPSHOT') && github.ref_name || 'latest' }}"
31+
file: docker/prod/Dockerfile
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
34+
35+
- name: Build and push
36+
id: docker_build
37+
uses: docker/build-push-action@v2
38+
with:
39+
push: true
40+
tags: dsty/jenkins:demo
41+
file: docker/dev/Dockerfile
42+
cache-from: type=gha
43+
cache-to: type=gha,mode=max
44+
build-args: |
45+
"baseImage=${{ steps.prod_image.outputs.digest }}"

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515

1616
- name: Checkout Code
17-
uses: actions/checkout@v2.3.4
17+
uses: actions/checkout@v2.4.0
1818
with:
1919
fetch-depth: 0
2020

@@ -51,7 +51,7 @@ jobs:
5151
needs: tag
5252
steps:
5353
- name: Checkout Code
54-
uses: actions/checkout@v2.3.4
54+
uses: actions/checkout@v2.4.0
5555
with:
5656
ref: ${{ github.base_ref }}
5757

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Checkout Code
24-
uses: actions/checkout@v2.3.4
24+
uses: actions/checkout@v2.4.0
2525

2626
- name: Run FOSSA scan and upload build data
27-
uses: fossa-contrib/fossa-action@v1.1.4
27+
uses: fossa-contrib/fossa-action@v1.2.0
2828
with:
2929
fossa-api-key: 7c94ee8610054ec8084c954b58615e0e
3030

@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- name: Checkout Code
55-
uses: actions/checkout@v2.3.4
55+
uses: actions/checkout@v2.4.0
5656

5757
- name: Set up Python
5858
uses: actions/setup-python@v2.2.2

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"[groovy]": {
3+
"editor.tabSize": 4,
4+
"editor.insertSpaces": true,
5+
"editor.detectIndentation": false
6+
}
7+
}

CONTRIBUTING.md

-9
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,3 @@ If you are not using docker or vscode you can setup a development environment us
8686
pytest -s
8787
```
8888
7. Once all tests are passing commit your changes and open a PR.
89-
90-
### Custom Test runner
91-
We use [jenkinsfile-runner](https://github.com/jenkinsci/jenkinsfile-runner) to run our jobs that we use to test this library. The default image is pulled from [dockerhub](https://hub.docker.com/r/shadycuz/jenkins-std-lib) but you can also build it locally. You also might be forced to build it locally if your contribution needs something modified on the Jenkins to run. Such as a plugin or maybe a environment variable.
92-
93-
#### Building
94-
From the root of the repo you can run `docker build -t local-runner docker/` but it does take a few miniutes.
95-
96-
### Using
97-
To force the use of the local image you can run `CUSTOM_RUNNER=local-runner pytest`.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[DontShaveTheYak](https://github.com/DontShaveTheYak) presents the Jenkins Standard Library. A set of useful tools for every day CI/CD jobs.
77

88
Why use our library?
9-
* Portable! This library requires very few [plugins](./docker/lib-plugins.txt).
9+
* Portable! This library requires very few [plugins](./docker/prod/plugins.txt).
1010
* OpenSource and [Free to use](https://choosealicense.com/licenses/gpl-3.0/)
1111
* We fully [test][test-url] and [lint][test-url] this codebase.
1212
* Our [Releases][releases-url] and [Docs][doc-url] are automated.
@@ -43,7 +43,7 @@ We recommend the following plugins:
4343
```
4444
* [AnsiColor](https://plugins.jenkins.io/ansicolor/) - To get color coded log messages from our logging package.
4545

46-
The required plugins and versions to enable complete library functionality can be found in [lib-plugins.txt](./docker/lib-plugins.txt).
46+
The required plugins enable complete library functionality can be found in [plugins.txt](./docker/prod/plugins.txt).
4747

4848
*Note: Individual library functions may have their own requirements. See the [docs][doc-url]*
4949

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ configurations {
131131
dependencies {
132132
// Use the latest Groovy version for building this library
133133
compileOnly('org.codehaus.groovy:groovy-all:3.0.9')
134-
compileOnly('org.jenkins-ci.main:jenkins-core:2.316')
134+
compileOnly('org.jenkins-ci.main:jenkins-core:2.320')
135135
compileOnly('com.cloudbees:groovy-cps:1.32')
136136
}
137137

docker/Dockerfile

-26
This file was deleted.

docker/dev/Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG baseImage=dsty/jenkins
2+
3+
FROM ${baseImage}
4+
5+
ARG DEBIAN_FRONTEND=noninteractive
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
python3 \
10+
python3-pip && \
11+
python3 -m pip install --upgrade pip && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# Install pre-commit and dependencies
15+
COPY tests/requirements.txt /tmp
16+
RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
17+
18+
## Plugins
19+
RUN jenkins-plugin-cli --plugins job-dsl
20+
21+
## Setup init scripts
22+
COPY docker/dev/init_scripts/* /usr/share/jenkins/ref/init.groovy.d/
23+
24+
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
25+
ENV JENKINS_SLAVE_AGENT_PORT=
26+
ENV JENKINS_OPTS="--httpPort=80"
27+
ENV PATH="/root/.local/bin:$PATH"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!groovy
2+
/* groovylint-disable NoDef, NoWildcardImports, UnnecessaryGetter, UnnecessarySetter, VariableTypeRequired */
3+
import jenkins.model.*
4+
import hudson.security.*
5+
import hudson.util.*
6+
import jenkins.install.*
7+
import javaposse.jobdsl.plugin.GlobalJobDslSecurityConfiguration
8+
import jenkins.model.GlobalConfiguration
9+
10+
// You should not actually do this on your real jenkins.
11+
println('==== Disable Jenkins Security')
12+
13+
println('== Disable JobDSL Security')
14+
GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration).useScriptSecurity = false
15+
GlobalConfiguration.all().get(GlobalJobDslSecurityConfiguration).save()
16+
17+
final Jenkins jenkins = Jenkins.getInstance()
18+
19+
println('== Disable Setup Wizard')
20+
jenkins.setInstallState(InstallState.INITIAL_SETUP_COMPLETED)
21+
22+
println('== Disable Authentication')
23+
def strategy = new AuthorizationStrategy.Unsecured()
24+
jenkins.setAuthorizationStrategy(strategy)
25+
26+
jenkins.save()
27+
println('== Disable Security complete')
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!groovy
2+
/* groovylint-disable GStringExpressionWithinString, JavaIoPackageAccess, NoDef, NoWildcardImports, UnnecessaryGetter, UnnecessaryObjectReferences, UnnecessarySetter, VariableTypeRequired */
3+
import hudson.model.FreeStyleProject
4+
import hudson.triggers.SCMTrigger
5+
import javaposse.jobdsl.plugin.*
6+
import jenkins.model.Jenkins
7+
import hudson.plugins.filesystem_scm.FSSCM
8+
9+
println('==== Creating seed job')
10+
final String jobName = 'seed-job'
11+
final File jobsDir = new File('/var/jenkins_home/pipeline-library/jobs')
12+
13+
final String dslScript = '''\
14+
import java.nio.file.Path
15+
import java.nio.file.Files
16+
import java.nio.file.Paths
17+
18+
19+
Files.walk(Paths.get('/var/jenkins_home/pipeline-library/jobs')).findAll { Path item ->
20+
item.toString().contains('.groovy')
21+
}.forEach { Path item ->
22+
final String fileName = item.getFileName()
23+
final String jobName = fileName.replace('_', '-').replace('.groovy', '')
24+
final File jenkinsFile = item.toFile()
25+
println("Creating job for ${fileName}")
26+
27+
pipelineJob(jobName) {
28+
29+
definition {
30+
cpsScm {
31+
32+
lightweight(true)
33+
34+
scm {
35+
filesystem {
36+
37+
// The file path for the source code.
38+
path(jenkinsFile.getParent())
39+
// If true, the system will delete all existing files/sub-folders in workspace before checking-out.
40+
clearWorkspace(false)
41+
// If true, the system will copy hidden files and folders as well.
42+
copyHidden(false)
43+
filterSettings {
44+
includeFilter(false)
45+
}
46+
47+
}
48+
}
49+
50+
scriptPath(fileName)
51+
52+
}
53+
}
54+
}
55+
}
56+
'''
57+
58+
final FSSCM fileScm = new FSSCM(jobsDir.getPath(), false, false, false, false, null)
59+
60+
final Jenkins jenkins = Jenkins.getInstance()
61+
62+
def existingJob = jenkins.items.find { def job ->
63+
job.name == jobName
64+
}
65+
66+
if (existingJob) {
67+
println('== Existing seed job found, exiting')
68+
return
69+
}
70+
71+
final SCMTrigger scmTrigger = new SCMTrigger('* * * * *')
72+
final ExecuteDslScripts dslBuilder = new ExecuteDslScripts()
73+
74+
// dslBuilder.setSandbox(true)
75+
dslBuilder.setScriptText(dslScript)
76+
dslBuilder.setUseScriptText(true)
77+
dslBuilder.setIgnoreExisting(false)
78+
dslBuilder.setIgnoreMissingFiles(false)
79+
dslBuilder.setFailOnMissingPlugin(true)
80+
dslBuilder.setRemovedJobAction(RemovedJobAction.DELETE)
81+
dslBuilder.setRemovedViewAction(RemovedViewAction.DELETE)
82+
dslBuilder.setLookupStrategy(LookupStrategy.JENKINS_ROOT)
83+
84+
dslProject = new FreeStyleProject(jenkins, jobName)
85+
dslProject.scm = fileScm
86+
87+
88+
dslProject.addTrigger(scmTrigger)
89+
dslProject.createTransientActions()
90+
dslProject.getPublishersList().add(dslBuilder)
91+
92+
println('== Adding Seed Job to Jenkins')
93+
jenkins.add(dslProject, jobName)
94+
95+
println('== Triggering Seed Job polling')
96+
scmTrigger.start(dslProject, true)
97+
98+
println('== Seed Job setup complete')

docker/jenkins.yaml

-11
This file was deleted.

docker/jfr/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG baseImage=dsty/jenkins
2+
3+
FROM jenkins/jenkinsfile-runner:latest as jfr
4+
5+
FROM ${baseImage}
6+
7+
COPY --from=jfr /app /app
8+
9+
RUN cd /usr/share/jenkins && jar -xvf jenkins.war
10+
11+
ENV JENKINS_HOME="/usr/share/jenkins/ref/"
12+
ENV JAVA_OPTS="-Djenkins.model.Jenkins.slaveAgentPort=50000 -Djenkins.model.Jenkins.slaveAgentPortEnforce=true -Dhudson.model.LoadStatistics.clock=1000"
13+
14+
ENTRYPOINT ["/app/bin/jenkinsfile-runner", "-w", "/usr/share/jenkins/", "-p", "/usr/share/jenkins/ref/plugins", "--withInitHooks", "/usr/share/jenkins/ref/init.groovy.d/", "-f"]
15+
16+
CMD ["/workspace/Jenkinsfile"]

docker/lib-plugins.txt

-1
This file was deleted.

docker/prod/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM jenkins/jenkins:latest-jdk11
2+
3+
USER root
4+
5+
ARG DEBIAN_FRONTEND=noninteractive
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
wget \
10+
git \
11+
curl && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# Install and setup docker into the container
15+
RUN curl -fsSL https://get.docker.com -o get-docker.sh && \
16+
sh get-docker.sh
17+
18+
## Plugins for container
19+
RUN jenkins-plugin-cli --plugins filesystem_scm git
20+
21+
## Plugins required for library
22+
COPY docker/prod/plugins.txt /usr/share/jenkins/ref/plugins.txt
23+
RUN jenkins-plugin-cli -f /usr/share/jenkins/ref/plugins.txt
24+
25+
## Setup init scripts
26+
COPY docker/prod/init_scripts/* /usr/share/jenkins/ref/init.groovy.d/
27+
28+
ENV JENKINS_SLAVE_AGENT_PORT=
29+
ENV JENKINS_OPTS="--httpPort=80"

docker/prod/plugins.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
workflow-aggregator
2+
pipeline-utility-steps

docker/runner-plugins.txt

-4
This file was deleted.

0 commit comments

Comments
 (0)