@@ -279,8 +279,15 @@ pipeline {
279
279
set -e
280
280
TEMPDIR=$(mktemp -d)
281
281
docker pull ghcr.io/linuxserver/jenkins-builder:latest
282
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
283
- # Stage 1 - Jenkinsfile update
282
+ # Cloned repo paths for templating:
283
+ # ${TEMPDIR}/docker-${CONTAINER_NAME}: Cloned branch master of ${LS_USER}/${LS_REPO} for running the jenkins builder on
284
+ # ${TEMPDIR}/repo/${LS_REPO}: Cloned branch master of ${LS_USER}/${LS_REPO} for commiting various templated file changes and pushing back to Github
285
+ # ${TEMPDIR}/docs/docker-documentation: Cloned docs repo for pushing docs updates to Github
286
+ # ${TEMPDIR}/unraid/docker-templates: Cloned docker-templates repo to check for logos
287
+ # ${TEMPDIR}/unraid/templates: Cloned templates repo for commiting unraid template changes and pushing back to Github
288
+ git clone --branch master --depth 1 https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/docker-${CONTAINER_NAME}
289
+ docker run --rm -v ${TEMPDIR}/docker-${CONTAINER_NAME}:/tmp -e LOCAL=true ghcr.io/linuxserver/jenkins-builder:latest
290
+ echo "Starting Stage 1 - Jenkinsfile update"
284
291
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
285
292
mkdir -p ${TEMPDIR}/repo
286
293
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
@@ -292,13 +299,13 @@ pipeline {
292
299
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
293
300
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
294
301
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
295
- echo "Updating Jenkinsfile"
302
+ echo "Updating Jenkinsfile and exiting build, new one will trigger based on commit "
296
303
rm -Rf ${TEMPDIR}
297
304
exit 0
298
305
else
299
306
echo "Jenkinsfile is up to date."
300
307
fi
301
- # Stage 2 - Delete old templates
308
+ echo "Starting Stage 2 - Delete old templates"
302
309
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"
303
310
for i in ${OLD_TEMPLATES}; do
304
311
if [[ -f "${i}" ]]; then
@@ -317,13 +324,13 @@ pipeline {
317
324
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
318
325
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
319
326
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
320
- echo "Deleting old and deprecated templates "
327
+ echo "Deleting old/deprecated templates and exiting build, new one will trigger based on commit "
321
328
rm -Rf ${TEMPDIR}
322
329
exit 0
323
330
else
324
331
echo "No templates to delete"
325
332
fi
326
- # Stage 3 - Update templates
333
+ echo "Starting Stage 3 - Update templates"
327
334
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
328
335
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
329
336
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
@@ -347,23 +354,31 @@ pipeline {
347
354
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
348
355
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
349
356
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
357
+ echo "Updating templates and exiting build, new one will trigger based on commit"
358
+ rm -Rf ${TEMPDIR}
359
+ exit 0
350
360
else
351
361
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
362
+ echo "No templates to update"
352
363
fi
364
+ echo "Starting Stage 4 - External repo updates: Docs, Unraid Template and Readme Sync to Docker Hub"
353
365
mkdir -p ${TEMPDIR}/docs
354
366
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
355
367
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
356
368
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
357
369
cd ${TEMPDIR}/docs/docker-documentation
358
370
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
359
371
git add docs/images/docker-${CONTAINER_NAME}.md
372
+ echo "Updating docs repo"
360
373
git commit -m 'Bot Updating Documentation'
361
374
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
362
375
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
363
376
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
364
377
sleep $((RANDOM % MAXWAIT)) && \
365
378
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
366
379
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
380
+ else
381
+ echo "Docs update not needed, skipping"
367
382
fi
368
383
mkdir -p ${TEMPDIR}/unraid
369
384
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
@@ -374,6 +389,7 @@ pipeline {
374
389
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
375
390
fi
376
391
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
392
+ echo "Updating Unraid template"
377
393
cd ${TEMPDIR}/unraid/templates/
378
394
GH_TEMPLATES_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
379
395
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
@@ -393,16 +409,27 @@ pipeline {
393
409
sleep $((RANDOM % MAXWAIT)) && \
394
410
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH} --rebase && \
395
411
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH})
412
+ else
413
+ echo "No updates to Unraid template needed, skipping"
396
414
fi
397
- # Stage 4 - Sync Readme to Docker Hub
398
415
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
399
- if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
416
+ if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) -gt 25000 ]]; then
400
417
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
401
418
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
402
419
else
403
420
echo "Syncing readme to Docker Hub"
404
421
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
405
422
fi
423
+ if curl -s https://hub.docker.com/v2/namespaces/${DOCKERHUB_IMAGE%%/*}/repositories/${DOCKERHUB_IMAGE##*/}/tags | jq -r '.message' | grep -q 404; then
424
+ echo "Docker Hub endpoint doesn't exist. Creating endpoint first."
425
+ 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')
426
+ curl -s \
427
+ -H "Authorization: JWT ${DH_TOKEN}" \
428
+ -H "Content-Type: application/json" \
429
+ -X POST \
430
+ -d '{"name":"'${DOCKERHUB_IMAGE##*/}'", "namespace":"'${DOCKERHUB_IMAGE%%/*}'"}' \
431
+ https://hub.docker.com/v2/repositories/ || :
432
+ fi
406
433
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')
407
434
curl -s \
408
435
-H "Authorization: JWT ${DH_TOKEN}" \
@@ -467,14 +494,16 @@ pipeline {
467
494
}
468
495
steps{
469
496
sh ''' curl -H "Content-Type: application/json" -H "Private-Token: ${GITLAB_TOKEN}" -X POST https://gitlab.com/api/v4/projects \
470
- -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
471
- "name":"'${LS_REPO}'",
472
- "mirror":true,\
473
- "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
474
- "issues_access_level":"disabled",\
475
- "merge_requests_access_level":"disabled",\
476
- "repository_access_level":"enabled",\
477
- "visibility":"public"}' '''
497
+ -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
498
+ "name":"'${LS_REPO}'",
499
+ "mirror":true,\
500
+ "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
501
+ "issues_access_level":"disabled",\
502
+ "merge_requests_access_level":"disabled",\
503
+ "repository_access_level":"enabled",\
504
+ "visibility":"public"}' '''
505
+ sh ''' curl -H "Private-Token: ${GITLAB_TOKEN}" -X PUT "https://gitlab.com/api/v4/projects/Linuxserver.io%2F${LS_REPO}" \
506
+ -d "mirror=true&import_url=https://github.com/linuxserver/${LS_REPO}.git" '''
478
507
}
479
508
}
480
509
/* ###############
0 commit comments