Files
yggdrasil-go/Jenkinsfile
2023-10-06 16:12:48 +08:00

85 lines
2.4 KiB
Groovy

podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
restartPolicy: Never
containers:
- image: docker.sunxinao.cn/gardel/nodejs-ci:latest
name: nodejs
command:
- sleep
args:
- 99d
volumeMounts:
- name: npm-cache
mountPath: /root/.npm
- image: golang:1.19-alpine
name: golang
command:
- sleep
args:
- 99d
- image: gcr.io/kaniko-project/executor:debug
name: kaniko
command:
- /busybox/sleep
args:
- 99d
volumeMounts:
- name: kaniko-cache
mountPath: /cache
- name: docker-config
mountPath: /kaniko/.docker
readOnly: true
volumes:
- name: kaniko-cache
persistentVolumeClaim:
claimName: build-cache-docker
- name: npm-cache
persistentVolumeClaim:
claimName: build-cache-npm
- name: docker-config
secret:
secretName: docker-config
optional: false
items:
- key: config.json
path: config.json
''') {
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '4', artifactNumToKeepStr: '3', daysToKeepStr: '4', numToKeepStr: '5')),
disableConcurrentBuilds()
])
node(POD_LABEL) {
stage('克隆仓库') {
git branch: env.BRANCH_NAME, credentialsId: 'gardel', url: 'git@sunxinao.cn:gardel/yggdrasil-go.git'
}
stage('编译') {
container('nodejs') {
sh 'make assets'
}
container('golang') {
sh 'apk --no-cache add build-base'
sh 'make package'
}
archiveArtifacts artifacts: 'yggdrasil.tar.gz', fingerprint: true, followSymlinks: false, onlyIfSuccessful: true
}
stage('发布镜像') {
container('kaniko') {
stage('准备缓存') {
sh '/kaniko/warmer --cache-dir=/cache --image=alpine:latest ' +
'--registry-mirror=docker.sunxinao.cn'
}
stage('构建') {
sh "/kaniko/executor --cache-dir=/cache --context `pwd` " +
"--destination docker.sunxinao.cn/gardel/yggdrasil-go:latest " +
"--registry-mirror docker.sunxinao.cn " +
"--build-arg 'BINARY=yggdrasil-linux-amd64'"
}
}
}
}
}