From 4ea250ae23178a3e7840c61e3029ae5344775179 Mon Sep 17 00:00:00 2001 From: nanxun Date: Thu, 30 Apr 2026 02:40:03 +0800 Subject: [PATCH] ci: keep buildx logs alive for jenkins --- Jenkinsfile | 134 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 99 insertions(+), 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 45a4dbe..0efceff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 """ } }