@@ -278,8 +278,15 @@ pipeline {
278
278
set -e
279
279
TEMPDIR=$(mktemp -d)
280
280
docker pull ghcr.io/linuxserver/jenkins-builder:latest
281
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -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 master of ${LS_USER}/${LS_REPO} for running the jenkins builder on
283
+ # ${TEMPDIR}/repo/${LS_REPO}: Cloned branch master 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 master --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"
283
290
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
284
291
mkdir -p ${TEMPDIR}/repo
285
292
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
@@ -291,13 +298,13 @@ pipeline {
291
298
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
292
299
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
293
300
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 "
295
302
rm -Rf ${TEMPDIR}
296
303
exit 0
297
304
else
298
305
echo "Jenkinsfile is up to date."
299
306
fi
300
- # Stage 2 - Delete old templates
307
+ echo "Starting Stage 2 - Delete old templates"
301
308
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"
302
309
for i in ${OLD_TEMPLATES}; do
303
310
if [[ -f "${i}" ]]; then
@@ -316,13 +323,13 @@ pipeline {
316
323
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
317
324
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
318
325
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 "
320
327
rm -Rf ${TEMPDIR}
321
328
exit 0
322
329
else
323
330
echo "No templates to delete"
324
331
fi
325
- # Stage 3 - Update templates
332
+ echo "Starting Stage 3 - Update templates"
326
333
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
327
334
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
328
335
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
@@ -346,23 +353,31 @@ pipeline {
346
353
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
347
354
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
348
355
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
349
359
else
350
360
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
361
+ echo "No templates to update"
351
362
fi
363
+ echo "Starting Stage 4 - External repo updates: Docs, Unraid Template and Readme Sync to Docker Hub"
352
364
mkdir -p ${TEMPDIR}/docs
353
365
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
354
366
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
355
367
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
356
368
cd ${TEMPDIR}/docs/docker-documentation
357
369
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
358
370
git add docs/images/docker-${CONTAINER_NAME}.md
371
+ echo "Updating docs repo"
359
372
git commit -m 'Bot Updating Documentation'
360
373
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
361
374
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
362
375
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
363
376
sleep $((RANDOM % MAXWAIT)) && \
364
377
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
365
378
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"
366
381
fi
367
382
mkdir -p ${TEMPDIR}/unraid
368
383
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
@@ -373,6 +388,7 @@ pipeline {
373
388
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
374
389
fi
375
390
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"
376
392
cd ${TEMPDIR}/unraid/templates/
377
393
GH_TEMPLATES_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
378
394
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
@@ -392,16 +408,27 @@ pipeline {
392
408
sleep $((RANDOM % MAXWAIT)) && \
393
409
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH} --rebase && \
394
410
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"
395
413
fi
396
- # Stage 4 - Sync Readme to Docker Hub
397
414
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
399
416
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
400
417
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
401
418
else
402
419
echo "Syncing readme to Docker Hub"
403
420
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
404
421
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
405
432
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')
406
433
curl -s \
407
434
-H "Authorization: JWT ${DH_TOKEN}" \
@@ -466,14 +493,16 @@ pipeline {
466
493
}
467
494
steps{
468
495
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" '''
477
506
}
478
507
}
479
508
/* ###############
0 commit comments