Skip to content

Commit eac5fbe

Browse files
authored
Add Kaniko examples (jfrog#286)
1 parent 40dc863 commit eac5fbe

File tree

8 files changed

+119
-0
lines changed

8 files changed

+119
-0
lines changed

Diff for: jenkins-examples/pipeline-examples/declarative-examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To set up Jenkins to use the example, read [this](https://github.com/jfrog/proje
2020
* The [issues-collection-example](issues-collection-example) demonstrates how to collect the list of tracked project issues and add them to the build-info.
2121
* The [jfrog-distribution-example](jfrog-distribution-example) demonstrates how to create, update, sign, distribute, and delete a release bundle.
2222
* The [jfrog-pipelines-example](jfrog-pipelines-example) demonstrates how to collect output resources when using JFrog Pipelines integration.
23+
* The [kaniko-example](kaniko-example) demonstrate how to collect build info for Docker images created by Kaniko.
2324
* The [maven-example](maven-example) resolves dependencies, deploys artifacts and publishes build-info to Artifactory for a Maven build.
2425
* The [npm-container-example](npm-container-example) demonstrates how to run npm in a Docker container. Use this example only in **Multibranch Pipeline** or a **Pipeline from SCM**, as instructed [here](https://jenkins.io/doc/book/pipeline/syntax/#agent) under **dockerfile**.
2526
* The [npm-example](npm-example) resolves dependencies, deploys artifacts and publishes build-info to Artifactory for a npm build.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage ('Clone') {
5+
steps {
6+
git url: "https://github.com/jfrog/project-examples.git"
7+
}
8+
}
9+
10+
stage ('Exec Kaniko') {
11+
steps {
12+
withCredentials([usernamePassword(credentialsId: CREDENTIALS, usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
13+
dir('jenkins-examples/pipeline-examples/resources/kaniko') {
14+
sh '''
15+
eval "echo \"$(<kaniko-config-template.json)\"" > kaniko-config.json
16+
docker run --rm -v ${PWD}:/workspace -v ${PWD}/kaniko-config.json:/kaniko/.docker/config.json:ro gcr.io/kaniko-project/executor:latest --dockerfile=Dockerfile --destination=${ARTIFACTORY_DOCKER_REGISTRY}/artifactory-kaniko-example:latest --image-name-with-digest-file=image-file
17+
'''
18+
}
19+
}
20+
}
21+
}
22+
23+
stage ('Run create Docker build') {
24+
steps {
25+
rtCreateDockerBuild (
26+
serverId: SERVER_ID,
27+
sourceRepo: ARTIFACTORY_DOCKER_REPO,
28+
kanikoImageFile: "jenkins-examples/pipeline-examples/resources/kaniko/image-file"
29+
)
30+
}
31+
}
32+
33+
stage ('Publish build info') {
34+
steps {
35+
rtPublishBuildInfo (
36+
serverId: SERVER_ID
37+
)
38+
}
39+
}
40+
}
41+
42+
post {
43+
always {
44+
sh 'rm jenkins-examples/pipeline-examples/resources/kaniko/kaniko-config.json'
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Kaniko Example
2+
3+
## Prerequisites
4+
5+
* Make sure to have the following job parameters configured:
6+
* `SERVER_ID` - JFrog instance ID, defined in Jenkins --> Manage Jenkins --> Configure System
7+
* `CREDENTIALS` - Credentials parameter type with username and password
8+
* `ARTIFACTORY_DOCKER_REPO` - Artifactory virtual or remote docker repository (i.e. docker-virtual)
9+
* `ARTIFACTORY_DOCKER_REGISTRY` - Artifactory docker registry (i.e. acme-docker-virtual.jfrog.io)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM alpine
2+
RUN echo "created from standard input"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"\"auths\"": {
3+
"\"$ARTIFACTORY_DOCKER_REGISTRY\"": {
4+
"\"username\"": "\"$ARTIFACTORY_USER\"",
5+
"\"password\"": "\"$ARTIFACTORY_PASSWORD\""
6+
}
7+
}
8+
}

Diff for: jenkins-examples/pipeline-examples/scripted-examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To set up Jenkins to use the example, read [this](https://github.com/jfrog/proje
2020
* The [gradle-example](gradle-example) resolves dependencies, deploys artifacts and publishes build-info to Artifactory for a Gradle build. Unlike the [gradle-example-ci-server](gradle-example-ci-server), this examples assumes that the Gradle Artifactory Plugin in already applied in the Gradle build script.
2121
* The [issues-collection-example](issues-collection-example) demonstrates how to collect the list of tracked project issues and add them to the build-info.
2222
* The [jfrog-distribution-example](jfrog-distribution-example) demonstrates how to create, update, sign, distribute, and delete a release bundle.
23+
* The [kaniko-example](kaniko-example) demonstrate how to collect build info for Docker images created by Kaniko.
2324
* The [maven-container-example](maven-container-example) demonstrates how to run Maven in a Docker container.
2425
* The [maven-deploy-example](maven-deploy-example) demonstrates how to defer the build artifacts deployment to a separate stage.
2526
* The [maven-example](maven-example) resolves dependencies, deploys artifacts and publishes build-info to Artifactory for a Maven build.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
node {
2+
def server
3+
def rtDocker
4+
def buildInfo
5+
6+
cleanWs()
7+
stage ('Clone') {
8+
git url: 'https://github.com/jfrog/project-examples.git'
9+
}
10+
11+
stage ('Artifactory configuration') {
12+
// Obtain a JFrog instance, defined in Jenkins --> Manage Jenkins --> Configure System:
13+
def jfrogInstance = JFrog.instance SERVER_ID
14+
rtServer = jfrogInstance.artifactory
15+
16+
rtDocker = Artifactory.docker server: rtServer
17+
buildInfo = Artifactory.newBuildInfo()
18+
}
19+
20+
dir ('jenkins-examples/pipeline-examples/resources/kaniko') {
21+
stage ('Exec Kaniko') {
22+
withCredentials([usernamePassword(credentialsId: CREDENTIALS, usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
23+
try {
24+
sh '''
25+
eval "echo \"$(<kaniko-config-template.json)\"" > kaniko-config.json
26+
docker run --rm -v ${PWD}:/workspace -v ${PWD}/kaniko-config.json:/kaniko/.docker/config.json:ro gcr.io/kaniko-project/executor:latest --dockerfile=Dockerfile --destination=${ARTIFACTORY_DOCKER_REGISTRY}/artifactory-kaniko-example:latest --image-name-with-digest-file=image-file
27+
'''
28+
} finally {
29+
sh 'rm kaniko-config.json'
30+
}
31+
}
32+
}
33+
34+
stage ('Run create Docker build') {
35+
rtDocker.createDockerBuild sourceRepo: ARTIFACTORY_DOCKER_REPO, kanikoImageFile: "image-file", buildInfo: buildInfo
36+
}
37+
}
38+
39+
stage ('Publish build info') {
40+
rtServer.publishBuildInfo buildInfo
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Kaniko Example
2+
3+
## Prerequisites
4+
5+
* Make sure to have the following job parameters configured:
6+
* `SERVER_ID` - JFrog instance ID, defined in Jenkins --> Manage Jenkins --> Configure System
7+
* `CREDENTIALS` - Credentials parameter type with username and password
8+
* `ARTIFACTORY_DOCKER_REPO` - Artifactory virtual or remote docker repository (i.e. docker-virtual)
9+
* `ARTIFACTORY_DOCKER_REGISTRY` - Artifactory docker registry (i.e. acme-docker-virtual.jfrog.io)

0 commit comments

Comments
 (0)