docker build test

This commit is contained in:
2023-01-17 02:39:55 +08:00
parent 128cdcee52
commit 209930f295
3 changed files with 72 additions and 2 deletions

View File

@@ -5,8 +5,9 @@ LABEL "Description"="Go Yggdrasil Server"
ARG TARGETOS
ARG TARGETARCH
ARG BINARY="yggdrasil-${TARGETOS}-${TARGETARCH}"
RUN mkdir -p /app
COPY "build/yggdrasil-${TARGETOS}-${TARGETARCH}" /app/yggdrasil
COPY $BINARY /app/yggdrasil
EXPOSE 8080
VOLUME /app/data

69
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,69 @@
podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
restartPolicy: Never
containers:
- 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: 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('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'"
}
}
}
}
}

View File

@@ -4,7 +4,7 @@ GO_CLEAN = $(GO_CMD) clean
GO_TEST = $(GO_CMD) test
GO_GET = $(GO_CMD) get
BINARY = yggdrasil
BINARY = yggdrasil-linux-amd64
PACKAGE_NAME = yggdrasil.tar.gz