Skip to content

Commit 8b02693

Browse files
authored
improve examples to add support for .dockercfg credentials format (#11)
1 parent 7d1fc93 commit 8b02693

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

jenkins/jenkins-openshift-internal-registry/Jenkinsfile

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,48 @@ metadata:
99
spec:
1010
containers:
1111
- name: jnlp
12+
workingDir: /tmp
1213
volumeMounts:
1314
# Mount the Openshift SA dockercfg secret as .dockercfg
14-
- mountPath: /home/jenkins/agent/.dockercfg
15+
- mountPath: /tmp/.dockercfg
1516
name: sa-dockercfg
1617
subPath: .dockercfg
1718
- name: maven
1819
image: maven:3.6-jdk-11
1920
command: ['cat']
2021
tty: true
22+
workingDir: /tmp
2123
- name: builder
2224
image: gcr.io/kaniko-project/executor:debug
2325
command: ['cat']
2426
tty: true
27+
workingDir: /tmp
2528
env:
2629
- name: DOCKER_CONFIG
27-
value: /home/jenkins/agent
28-
- name: inline-scan
30+
value: /tmp
31+
- name: inline-scan-option1-with-configjson
2932
image: quay.io/sysdig/secure-inline-scan:2
3033
command: ['cat']
3134
tty: true
35+
workingDir: /tmp
36+
- name: inline-scan-option2-with-dockercfg
37+
image: quay.io/sysdig/secure-inline-scan:2
38+
command: ['cat']
39+
tty: true
40+
workingDir: /tmp
41+
volumeMounts:
42+
# Mount the Openshift SA dockercfg secret as .dockercfg
43+
- mountPath: /tmp/.dockercfg
44+
name: sa-dockercfg
45+
subPath: .dockercfg
3246
volumes:
3347
- name: sa-dockercfg
3448
secret:
3549
defaultMode: 420
3650
# Name of the secret in Kubernetes used by the Service Account
3751
# Requires push and pull access to the internal registry.
3852
# See https://docs.openshift.com/container-platform/4.6/registry/accessing-the-registry.html
39-
secretName: jenkins-dockercfg-nr7sd
53+
secretName: builder-dockercfg-r2gc4
4054
"""
4155
}
4256
}
@@ -46,7 +60,7 @@ spec:
4660
}
4761

4862
environment {
49-
SECURE_API_KEY = credentials('sysdig-secure-airadier')
63+
SECURE_API_KEY = credentials('sysdig-secure')
5064
}
5165

5266
stages {
@@ -59,10 +73,10 @@ spec:
5973

6074
stage('Prepare internal registry credentials') {
6175
steps {
62-
// We need to convert old .dockercfg format to config.json wrapping in "auth" field
63-
sh "echo -n \"{ \\\"auths\\\": \" > /home/jenkins/agent/config.json"
64-
sh "cat /home/jenkins/agent/.dockercfg >> /home/jenkins/agent/config.json"
65-
sh "echo \"}\" >>/home/jenkins/agent/config.json"
76+
// We need to convert old .dockercfg format to config.json wrapping in "auth" field for Kaniko
77+
sh "echo -n \"{ \\\"auths\\\": \" > /tmp/config.json"
78+
sh "cat /tmp/.dockercfg >> /tmp/config.json"
79+
sh "echo \"}\" >>/tmp/config.json"
6680
}
6781
}
6882

@@ -88,13 +102,25 @@ EOF
88102
}
89103
}
90104

91-
stage('Scanning Image pulled from repository') {
105+
stage('Option 1: Scanning Image pulled from repository using config.json format') {
92106
steps {
93-
container("inline-scan") {
94-
sh "/sysdig-inline-scan.sh -k ${SECURE_API_KEY_PSW} --registry-skip-tls --registry-auth-file /home/jenkins/agent/config.json ${IMAGE_NAME}"
107+
container("inline-scan-option1-with-configjson") {
108+
sh "id"
109+
sh "/sysdig-inline-scan.sh -k ${SECURE_API_KEY_PSW} --registry-skip-tls --registry-auth-file /tmp/config.json ${IMAGE_NAME}"
95110
}
96111
}
97112
}
98113

114+
stage('Option 2: Scanning Image pulled from repository using .dockercfg format') {
115+
steps {
116+
container("inline-scan-option2-with-dockercfg") {
117+
sh "id"
118+
// Instead of using --registry-auth-file, we can just provide the .dockercfg file at /tmp/sysdyg-inline-scan/home/.dockercfg
119+
sh "mkdir -p /tmp/sysdig-inline-scan/home"
120+
sh "cp /tmp/.dockercfg /tmp/sysdig-inline-scan/home"
121+
sh "/sysdig-inline-scan.sh -k ${SECURE_API_KEY_PSW} --registry-skip-tls ${IMAGE_NAME}"
122+
}
123+
}
124+
}
99125
}
100126
}

jenkins/jenkins-openshift-internal-registry/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This [example pipeline](Jenkinsfile) shows how to build, push, and then scan the Docker image in Openshift, using the service account credentials to push and scan from the Openshift internal registry.
44

55
The podTemplate in the example is composed by 4 containers:
6-
* **jnlp** container. Required for the Jenkins agent. Also, we mount the service account secret in `/home/jenkins/agent/.dockercfg` to convert the old dockercfg format to the new config.json format required by Kaniko and the Inline Scanner:
6+
* **jnlp** container. Required for the Jenkins agent. Also, we mount the service account secret in `/home/jenkins/agent/.dockercfg` to convert the old dockercfg format to the new config.json format required by Kaniko:
77

88
```
99
sh "echo -n \"{ \\\"auths\\\": \" > /home/jenkins/agent/config.json"
@@ -13,6 +13,6 @@ The podTemplate in the example is composed by 4 containers:
1313

1414
* **maven** container for building a Java application.
1515
* **builder** container, using [Kaniko](https://github.com/GoogleContainerTools/kaniko) to build a Docker image without requiring the Docker daemon. Once build, the image is pushed to the internal Openshift registry, using the credentials at `/home/jenkins/agent/config.json`.
16-
* **inline-scan** container, where the pipeline executes the `inline-scan.sh` script to analyze the image pushed to the internal Openshift registry, using the credentials from /home/jenkins/agent/config.json.
16+
* **inline-scan** container, where the pipeline executes the `inline-scan.sh` script to analyze the image pushed to the internal Openshift registry, using the credentials from /home/jenkins/agent/config.json or using the .dockercfg file (two alternatives are provided).
1717

1818
See [Jenkins examples README.md](../README.md) for common usage tips and troubleshooting.

jenkins/jenkins-scan-from-repo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build, push and scan from Openshift internal registry
22

3-
This minimalistic e[example pipeline](Jenkinsfile) shows how to execute the inline-scan container as part of a podTemplate.
3+
This minimalistic [example pipeline](Jenkinsfile) shows how to execute the inline-scan container as part of a podTemplate.
44

55
The podTemplate in the example is composed by 2 containers:
66
* **jnlp** container. Required for the Jenkins agent.

0 commit comments

Comments
 (0)