ci: keep buildx logs alive for jenkins

This commit is contained in:
2026-04-30 02:40:03 +08:00
parent 24b901dddd
commit 4ea250ae23
Vendored
+99 -35
View File
@@ -77,6 +77,36 @@ pipeline {
steps {
sh """
set -e
run_with_heartbeat() {
log_file="\$1"
shift
rm -f "\$log_file"
: > "\$log_file"
"\$@" >"\$log_file" 2>&1 &
cmd_pid=\$!
last_line=0
while kill -0 "\$cmd_pid" >/dev/null 2>&1; do
if [ -f "\$log_file" ]; then
total_lines=\$(wc -l < "\$log_file" || echo 0)
else
total_lines=0
fi
if [ "\$total_lines" -gt "\$last_line" ]; then
sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file"
last_line=\$total_lines
else
echo "[heartbeat] API multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)"
fi
sleep 20
done
wait "\$cmd_pid"
if [ -f "\$log_file" ]; then
total_lines=\$(wc -l < "\$log_file" || echo 0)
if [ "\$total_lines" -gt "\$last_line" ]; then
sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file"
fi
fi
}
if ! sudo docker buildx inspect --builder ${BUILDER_NAME} >/dev/null 2>&1; then
sudo docker buildx create \
--name ${BUILDER_NAME} \
@@ -92,22 +122,24 @@ pipeline {
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} \
--network host \
--provenance=false \
--build-arg HTTP_PROXY=http://192.168.5.200:7890 \
--build-arg HTTPS_PROXY=http://192.168.5.200:7890 \
--build-arg NO_PROXY=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
--build-arg http_proxy=http://192.168.5.200:7890 \
--build-arg https_proxy=http://192.168.5.200:7890 \
--build-arg no_proxy=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
-f src/LiveRecorder.WebApi/Dockerfile \
-t ${API_IMAGE_TAGGED} \
-t ${API_IMAGE_LATEST} \
--push \
.
run_with_heartbeat .jenkins-api-buildx.log \
sudo docker buildx build \
--builder ${BUILDER_NAME} \
--platform ${TARGET_PLATFORMS} \
--network host \
--progress=plain \
--provenance=false \
--build-arg HTTP_PROXY=http://192.168.5.200:7890 \
--build-arg HTTPS_PROXY=http://192.168.5.200:7890 \
--build-arg NO_PROXY=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
--build-arg http_proxy=http://192.168.5.200:7890 \
--build-arg https_proxy=http://192.168.5.200:7890 \
--build-arg no_proxy=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
-f src/LiveRecorder.WebApi/Dockerfile \
-t ${API_IMAGE_TAGGED} \
-t ${API_IMAGE_LATEST} \
--push \
.
"""
}
}
@@ -116,6 +148,36 @@ pipeline {
steps {
sh """
set -e
run_with_heartbeat() {
log_file="\$1"
shift
rm -f "\$log_file"
: > "\$log_file"
"\$@" >"\$log_file" 2>&1 &
cmd_pid=\$!
last_line=0
while kill -0 "\$cmd_pid" >/dev/null 2>&1; do
if [ -f "\$log_file" ]; then
total_lines=\$(wc -l < "\$log_file" || echo 0)
else
total_lines=0
fi
if [ "\$total_lines" -gt "\$last_line" ]; then
sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file"
last_line=\$total_lines
else
echo "[heartbeat] Web multi-arch build still running at \$(date -u +%Y-%m-%dT%H:%M:%SZ)"
fi
sleep 20
done
wait "\$cmd_pid"
if [ -f "\$log_file" ]; then
total_lines=\$(wc -l < "\$log_file" || echo 0)
if [ "\$total_lines" -gt "\$last_line" ]; then
sed -n "\$((last_line + 1)),\${total_lines}p" "\$log_file"
fi
fi
}
if ! sudo docker buildx inspect --builder ${BUILDER_NAME} >/dev/null 2>&1; then
sudo docker buildx create \
--name ${BUILDER_NAME} \
@@ -131,25 +193,27 @@ pipeline {
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} \
--network host \
--provenance=false \
--build-arg NODE_IMAGE=${WEB_NODE_IMAGE} \
--build-arg NGINX_IMAGE=${WEB_NGINX_IMAGE} \
--build-arg HTTP_PROXY=http://192.168.5.200:7890 \
--build-arg HTTPS_PROXY=http://192.168.5.200:7890 \
--build-arg NO_PROXY=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
--build-arg http_proxy=http://192.168.5.200:7890 \
--build-arg https_proxy=http://192.168.5.200:7890 \
--build-arg no_proxy=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
-f frontend/Dockerfile \
--build-arg VITE_API_BASE_URL=/api \
-t ${WEB_IMAGE_TAGGED} \
-t ${WEB_IMAGE_LATEST} \
--push \
frontend
run_with_heartbeat .jenkins-web-buildx.log \
sudo docker buildx build \
--builder ${BUILDER_NAME} \
--platform ${TARGET_PLATFORMS} \
--network host \
--progress=plain \
--provenance=false \
--build-arg NODE_IMAGE=${WEB_NODE_IMAGE} \
--build-arg NGINX_IMAGE=${WEB_NGINX_IMAGE} \
--build-arg HTTP_PROXY=http://192.168.5.200:7890 \
--build-arg HTTPS_PROXY=http://192.168.5.200:7890 \
--build-arg NO_PROXY=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
--build-arg http_proxy=http://192.168.5.200:7890 \
--build-arg https_proxy=http://192.168.5.200:7890 \
--build-arg no_proxy=127.0.0.1,localhost,reg.nxsir.cn,gitea.nxsir.cn \
-f frontend/Dockerfile \
--build-arg VITE_API_BASE_URL=/api \
-t ${WEB_IMAGE_TAGGED} \
-t ${WEB_IMAGE_LATEST} \
--push \
frontend
"""
}
}