@@ -278,8 +278,15 @@ pipeline {
278278 set -e
279279 TEMPDIR=$(mktemp -d)
280280 docker pull ghcr.io/linuxserver/jenkins-builder:latest
281- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=main -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
282- # Stage 1 - Jenkinsfile update
281+ # Cloned repo paths for templating:
282+ # ${TEMPDIR}/docker-${CONTAINER_NAME}: Cloned branch main of ${LS_USER}/${LS_REPO} for running the jenkins builder on
283+ # ${TEMPDIR}/repo/${LS_REPO}: Cloned branch main of ${LS_USER}/${LS_REPO} for commiting various templated file changes and pushing back to Github
284+ # ${TEMPDIR}/docs/docker-documentation: Cloned docs repo for pushing docs updates to Github
285+ # ${TEMPDIR}/unraid/docker-templates: Cloned docker-templates repo to check for logos
286+ # ${TEMPDIR}/unraid/templates: Cloned templates repo for commiting unraid template changes and pushing back to Github
287+ git clone --branch main --depth 1 https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/docker-${CONTAINER_NAME}
288+ docker run --rm -v ${TEMPDIR}/docker-${CONTAINER_NAME}:/tmp -e LOCAL=true ghcr.io/linuxserver/jenkins-builder:latest
289+ echo "Starting Stage 1 - Jenkinsfile update"
283290 if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
284291 mkdir -p ${TEMPDIR}/repo
285292 git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
@@ -291,13 +298,13 @@ pipeline {
291298 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
292299 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
293300 echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
294- echo "Updating Jenkinsfile"
301+ echo "Updating Jenkinsfile and exiting build, new one will trigger based on commit "
295302 rm -Rf ${TEMPDIR}
296303 exit 0
297304 else
298305 echo "Jenkinsfile is up to date."
299306 fi
300- # Stage 2 - Delete old templates
307+ echo "Starting Stage 2 - Delete old templates"
301308 OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml Dockerfile.armhf"
302309 for i in ${OLD_TEMPLATES}; do
303310 if [[ -f "${i}" ]]; then
@@ -316,13 +323,13 @@ pipeline {
316323 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
317324 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
318325 echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
319- echo "Deleting old and deprecated templates "
326+ echo "Deleting old/deprecated templates and exiting build, new one will trigger based on commit "
320327 rm -Rf ${TEMPDIR}
321328 exit 0
322329 else
323330 echo "No templates to delete"
324331 fi
325- # Stage 3 - Update templates
332+ echo "Starting Stage 3 - Update templates"
326333 CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
327334 cd ${TEMPDIR}/docker-${CONTAINER_NAME}
328335 NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
@@ -346,23 +353,31 @@ pipeline {
346353 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
347354 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git main
348355 echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
356+ echo "Updating templates and exiting build, new one will trigger based on commit"
357+ rm -Rf ${TEMPDIR}
358+ exit 0
349359 else
350360 echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
361+ echo "No templates to update"
351362 fi
363+ echo "Starting Stage 4 - External repo updates: Docs, Unraid Template and Readme Sync to Docker Hub"
352364 mkdir -p ${TEMPDIR}/docs
353365 git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
354366 if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]] && [[ (! -f ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
355367 cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
356368 cd ${TEMPDIR}/docs/docker-documentation
357369 GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
358370 git add docs/images/docker-${CONTAINER_NAME}.md
371+ echo "Updating docs repo"
359372 git commit -m 'Bot Updating Documentation'
360373 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
361374 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
362375 (MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
363376 sleep $((RANDOM % MAXWAIT)) && \
364377 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
365378 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
379+ else
380+ echo "Docs update not needed, skipping"
366381 fi
367382 mkdir -p ${TEMPDIR}/unraid
368383 git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
@@ -373,6 +388,7 @@ pipeline {
373388 sed -i "s|master/linuxserver.io/img/linuxserver-ls-logo.png|master/linuxserver.io/img/${CONTAINER_NAME}-icon.png|" ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml
374389 fi
375390 if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]] && [[ (! -f ${TEMPDIR}/unraid/templates/unraid/${CONTAINER_NAME}.xml) || ("$(md5sum ${TEMPDIR}/unraid/templates/unraid/${CONTAINER_NAME}.xml | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml | awk '{ print $1 }')") ]]; then
391+ echo "Updating Unraid template"
376392 cd ${TEMPDIR}/unraid/templates/
377393 GH_TEMPLATES_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
378394 if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
@@ -392,16 +408,27 @@ pipeline {
392408 sleep $((RANDOM % MAXWAIT)) && \
393409 git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH} --rebase && \
394410 git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH})
411+ else
412+ echo "No updates to Unraid template needed, skipping"
395413 fi
396- # Stage 4 - Sync Readme to Docker Hub
397414 if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
398- if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
415+ if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) -gt 25000 ]]; then
399416 echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
400417 DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
401418 else
402419 echo "Syncing readme to Docker Hub"
403420 DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
404421 fi
422+ if curl -s https://hub.docker.com/v2/namespaces/${DOCKERHUB_IMAGE%%/*}/repositories/${DOCKERHUB_IMAGE##*/}/tags | jq -r '.message' | grep -q 404; then
423+ echo "Docker Hub endpoint doesn't exist. Creating endpoint first."
424+ DH_TOKEN=$(curl -d '{"username":"linuxserverci", "password":"'${DOCKERHUB_TOKEN}'"}' -H "Content-Type: application/json" -X POST https://hub.docker.com/v2/users/login | jq -r '.token')
425+ curl -s \
426+ -H "Authorization: JWT ${DH_TOKEN}" \
427+ -H "Content-Type: application/json" \
428+ -X POST \
429+ -d '{"name":"'${DOCKERHUB_IMAGE##*/}'", "namespace":"'${DOCKERHUB_IMAGE%%/*}'"}' \
430+ https://hub.docker.com/v2/repositories/ || :
431+ fi
405432 DH_TOKEN=$(curl -d '{"username":"linuxserverci", "password":"'${DOCKERHUB_TOKEN}'"}' -H "Content-Type: application/json" -X POST https://hub.docker.com/v2/users/login | jq -r '.token')
406433 curl -s \
407434 -H "Authorization: JWT ${DH_TOKEN}" \
@@ -466,14 +493,16 @@ pipeline {
466493 }
467494 steps{
468495 sh ''' curl -H "Content-Type: application/json" -H "Private-Token: ${GITLAB_TOKEN}" -X POST https://gitlab.com/api/v4/projects \
469- -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
470- "name":"'${LS_REPO}'",
471- "mirror":true,\
472- "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
473- "issues_access_level":"disabled",\
474- "merge_requests_access_level":"disabled",\
475- "repository_access_level":"enabled",\
476- "visibility":"public"}' '''
496+ -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
497+ "name":"'${LS_REPO}'",
498+ "mirror":true,\
499+ "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
500+ "issues_access_level":"disabled",\
501+ "merge_requests_access_level":"disabled",\
502+ "repository_access_level":"enabled",\
503+ "visibility":"public"}' '''
504+ sh ''' curl -H "Private-Token: ${GITLAB_TOKEN}" -X PUT "https://gitlab.com/api/v4/projects/Linuxserver.io%2F${LS_REPO}" \
505+ -d "mirror=true&import_url=https://github.com/linuxserver/${LS_REPO}.git" '''
477506 }
478507 }
479508 /* ###############
0 commit comments