Use docker node to build

This commit is contained in:
Jonathan Ervine 2020-07-20 14:36:06 +08:00
parent 225fe6e4fd
commit e0b1a08c5a
2 changed files with 58 additions and 24 deletions

55
Jenkinsfile vendored
View File

@ -1,27 +1,34 @@
node("docker-node") {
docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') {
git branch: "master", url: "ssh://git@git.ervine.org/jonny/x86_64-alpine-htpcmgr", credentialsId: 'jenkins-to-git'
sh "git rev-parse HEAD > .git/commit-id"
def commit_id = readFile('.git/commit-id').trim()
println commit_id
try {
stage "build"
def app = docker.build "library/x86_64/alpine/htpc-mgr"
stage "publish"
app.push("${env.BUILD_NUMBER}")
app.push("latest")
podTemplate(yaml: """
kind: Pod
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug-539ddefcae3fd6b411a95982a830d987f4214251
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /kaniko/.docker
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: regcred
items:
- key: .dockerconfigjson
path: config.json
"""
) {
stage('Deploy on K8s'){
sh "/usr/local/bin/kubectl -n media delete po htpc-0"
}
}
catch (err) {
currentBuild.result = 'FAILURE'
}
node(POD_LABEL) {
stage('Build with Kaniko') {
git 'https://git.ervine.org/jonny/x86_64-alpine-htpcmgr.git'
container('kaniko') {
sh '/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --cache=true --destination=harbor.ervine.dev/library/x86_64/alpine/htpc-mgr:latest' --destination=harbor.ervine.dev/library/x86_64/alpine/htpc-mgr:2019'
}
}
}
}

27
Jenkinsfile.old Normal file
View File

@ -0,0 +1,27 @@
node("docker-node") {
docker.withRegistry('https://harbor.ervine.dev', 'jenkins-to-harbor') {
git branch: "master", url: "ssh://git@git.ervine.org/jonny/x86_64-alpine-htpcmgr", credentialsId: 'jenkins-to-git'
sh "git rev-parse HEAD > .git/commit-id"
def commit_id = readFile('.git/commit-id').trim()
println commit_id
try {
stage "build"
def app = docker.build "library/x86_64/alpine/htpc-mgr"
stage "publish"
app.push("${env.BUILD_NUMBER}")
app.push("latest")
stage('Deploy on K8s'){
sh "/usr/local/bin/kubectl -n media delete po htpc-0"
}
}
catch (err) {
currentBuild.result = 'FAILURE'
}
}
}