171 lines
6.6 KiB
Groovy
171 lines
6.6 KiB
Groovy
pipeline {
|
|
agent { label '构建机1' }
|
|
|
|
options {
|
|
timestamps()
|
|
disableConcurrentBuilds()
|
|
skipDefaultCheckout(true)
|
|
}
|
|
|
|
environment {
|
|
REGISTRY_URL = 'reg.nxsir.cn'
|
|
API_IMAGE_NAME = 'liverecorder/app-api'
|
|
WEB_IMAGE_NAME = 'liverecorder/app-web'
|
|
IMAGE_TAG = "${env.BUILD_ID}"
|
|
DOCKER_CREDS = 'harbor_key'
|
|
TARGET_PLATFORMS = 'linux/amd64,linux/arm64'
|
|
BUILDER_NAME = "liverecorder-buildx-${env.BUILD_ID}"
|
|
HTTP_PROXY = 'http://192.168.5.200:7890'
|
|
HTTPS_PROXY = 'http://192.168.5.200:7890'
|
|
NO_PROXY = '127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12'
|
|
NO_PROXY_DRIVER = '127.0.0.1\\,localhost\\,reg.nxsir.cn\\,gitea.nxsir.cn\\,192.168.0.0/16\\,10.0.0.0/8\\,172.16.0.0/12'
|
|
|
|
GIT_REPO_URL = 'https://gitea.nxsir.cn/nanxun/live_recorder.git'
|
|
GIT_BRANCH = 'main'
|
|
GIT_CREDS = ''
|
|
|
|
API_IMAGE_TAGGED = "${REGISTRY_URL}/${API_IMAGE_NAME}:${IMAGE_TAG}"
|
|
API_IMAGE_LATEST = "${REGISTRY_URL}/${API_IMAGE_NAME}:latest"
|
|
WEB_IMAGE_TAGGED = "${REGISTRY_URL}/${WEB_IMAGE_NAME}:${IMAGE_TAG}"
|
|
WEB_IMAGE_LATEST = "${REGISTRY_URL}/${WEB_IMAGE_NAME}:latest"
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
script {
|
|
def userRemoteConfig = [url: env.GIT_REPO_URL]
|
|
if (env.GIT_CREDS?.trim()) {
|
|
userRemoteConfig.credentialsId = env.GIT_CREDS.trim()
|
|
}
|
|
|
|
checkout([
|
|
$class: 'GitSCM',
|
|
branches: [[name: "*/${env.GIT_BRANCH}"]],
|
|
userRemoteConfigs: [userRemoteConfig]
|
|
])
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Prepare Buildx') {
|
|
steps {
|
|
sh """
|
|
set -e
|
|
sudo docker buildx version
|
|
sudo docker run --privileged --rm tonistiigi/binfmt --install arm64
|
|
sudo docker buildx rm ${BUILDER_NAME} >/dev/null 2>&1 || true
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Login Registry') {
|
|
steps {
|
|
withCredentials([
|
|
usernamePassword(
|
|
credentialsId: "${DOCKER_CREDS}",
|
|
usernameVariable: 'DOCKER_USERNAME',
|
|
passwordVariable: 'DOCKER_PASSWORD'
|
|
)
|
|
]) {
|
|
sh """
|
|
set -e
|
|
echo "\$DOCKER_PASSWORD" | sudo docker login ${REGISTRY_URL} -u "\$DOCKER_USERNAME" --password-stdin
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Build And Push API Image') {
|
|
steps {
|
|
sh """
|
|
set -e
|
|
if ! sudo docker buildx inspect --builder ${BUILDER_NAME} >/dev/null 2>&1; then
|
|
sudo docker buildx create \
|
|
--name ${BUILDER_NAME} \
|
|
--driver docker-container \
|
|
--driver-opt env.http_proxy=${HTTP_PROXY} \
|
|
--driver-opt env.https_proxy=${HTTPS_PROXY} \
|
|
--driver-opt env.no_proxy=${NO_PROXY_DRIVER} \
|
|
--use
|
|
fi
|
|
sudo docker buildx inspect --builder ${BUILDER_NAME} --bootstrap >/dev/null
|
|
echo 'Building and pushing multi-arch API image: ${API_IMAGE_TAGGED}'
|
|
sudo docker buildx build \
|
|
--builder ${BUILDER_NAME} \
|
|
--platform ${TARGET_PLATFORMS} \
|
|
--pull \
|
|
--network host \
|
|
--provenance=false \
|
|
--build-arg HTTP_PROXY=${HTTP_PROXY} \
|
|
--build-arg HTTPS_PROXY=${HTTPS_PROXY} \
|
|
--build-arg NO_PROXY=${NO_PROXY} \
|
|
--build-arg http_proxy=${HTTP_PROXY} \
|
|
--build-arg https_proxy=${HTTPS_PROXY} \
|
|
--build-arg no_proxy=${NO_PROXY} \
|
|
-f src/LiveRecorder.WebApi/Dockerfile \
|
|
-t ${API_IMAGE_TAGGED} \
|
|
-t ${API_IMAGE_LATEST} \
|
|
--push \
|
|
.
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Build And Push Web Image') {
|
|
steps {
|
|
sh """
|
|
set -e
|
|
if ! sudo docker buildx inspect --builder ${BUILDER_NAME} >/dev/null 2>&1; then
|
|
sudo docker buildx create \
|
|
--name ${BUILDER_NAME} \
|
|
--driver docker-container \
|
|
--driver-opt env.http_proxy=${HTTP_PROXY} \
|
|
--driver-opt env.https_proxy=${HTTPS_PROXY} \
|
|
--driver-opt env.no_proxy=${NO_PROXY_DRIVER} \
|
|
--use
|
|
fi
|
|
sudo docker buildx inspect --builder ${BUILDER_NAME} --bootstrap >/dev/null
|
|
echo 'Building and pushing multi-arch Web image: ${WEB_IMAGE_TAGGED}'
|
|
sudo docker buildx build \
|
|
--builder ${BUILDER_NAME} \
|
|
--platform ${TARGET_PLATFORMS} \
|
|
--pull \
|
|
--network host \
|
|
--provenance=false \
|
|
--build-arg HTTP_PROXY=${HTTP_PROXY} \
|
|
--build-arg HTTPS_PROXY=${HTTPS_PROXY} \
|
|
--build-arg NO_PROXY=${NO_PROXY} \
|
|
--build-arg http_proxy=${HTTP_PROXY} \
|
|
--build-arg https_proxy=${HTTPS_PROXY} \
|
|
--build-arg no_proxy=${NO_PROXY} \
|
|
-f frontend/Dockerfile \
|
|
--build-arg VITE_API_BASE_URL=/api \
|
|
-t ${WEB_IMAGE_TAGGED} \
|
|
-t ${WEB_IMAGE_LATEST} \
|
|
--push \
|
|
frontend
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo "Pipeline completed successfully."
|
|
}
|
|
failure {
|
|
echo "Pipeline failed. Please check the build log."
|
|
}
|
|
always {
|
|
sh """
|
|
set +e
|
|
sudo docker buildx rm ${BUILDER_NAME} >/dev/null 2>&1 || true
|
|
sudo docker logout ${REGISTRY_URL} >/dev/null 2>&1 || true
|
|
true
|
|
"""
|
|
deleteDir()
|
|
}
|
|
}
|
|
}
|