@@ -269,8 +269,15 @@ pipeline {
269
269
set -e
270
270
TEMPDIR=$(mktemp -d)
271
271
docker pull ghcr.io/linuxserver/jenkins-builder:latest
272
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
273
- # Stage 1 - Jenkinsfile update
272
+ # Cloned repo paths for templating:
273
+ # ${TEMPDIR}/docker-${CONTAINER_NAME}: Cloned branch master of ${LS_USER}/${LS_REPO} for running the jenkins builder on
274
+ # ${TEMPDIR}/repo/${LS_REPO}: Cloned branch master of ${LS_USER}/${LS_REPO} for commiting various templated file changes and pushing back to Github
275
+ # ${TEMPDIR}/docs/docker-documentation: Cloned docs repo for pushing docs updates to Github
276
+ # ${TEMPDIR}/unraid/docker-templates: Cloned docker-templates repo to check for logos
277
+ # ${TEMPDIR}/unraid/templates: Cloned templates repo for commiting unraid template changes and pushing back to Github
278
+ git clone --branch master --depth 1 https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/docker-${CONTAINER_NAME}
279
+ docker run --rm -v ${TEMPDIR}/docker-${CONTAINER_NAME}:/tmp -e LOCAL=true ghcr.io/linuxserver/jenkins-builder:latest
280
+ echo "Starting Stage 1 - Jenkinsfile update"
274
281
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
275
282
mkdir -p ${TEMPDIR}/repo
276
283
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
@@ -282,13 +289,13 @@ pipeline {
282
289
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
283
290
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
284
291
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
285
- echo "Updating Jenkinsfile"
292
+ echo "Updating Jenkinsfile and exiting build, new one will trigger based on commit "
286
293
rm -Rf ${TEMPDIR}
287
294
exit 0
288
295
else
289
296
echo "Jenkinsfile is up to date."
290
297
fi
291
- # Stage 2 - Delete old templates
298
+ echo "Starting Stage 2 - Delete old templates"
292
299
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"
293
300
for i in ${OLD_TEMPLATES}; do
294
301
if [[ -f "${i}" ]]; then
@@ -307,13 +314,13 @@ pipeline {
307
314
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
308
315
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
309
316
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
310
- echo "Deleting old and deprecated templates "
317
+ echo "Deleting old/deprecated templates and exiting build, new one will trigger based on commit "
311
318
rm -Rf ${TEMPDIR}
312
319
exit 0
313
320
else
314
321
echo "No templates to delete"
315
322
fi
316
- # Stage 3 - Update templates
323
+ echo "Starting Stage 3 - Update templates"
317
324
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
318
325
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
319
326
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
@@ -337,23 +344,31 @@ pipeline {
337
344
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
338
345
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
339
346
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
347
+ echo "Updating templates and exiting build, new one will trigger based on commit"
348
+ rm -Rf ${TEMPDIR}
349
+ exit 0
340
350
else
341
351
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
352
+ echo "No templates to update"
342
353
fi
354
+ echo "Starting Stage 4 - External repo updates: Docs, Unraid Template and Readme Sync to Docker Hub"
343
355
mkdir -p ${TEMPDIR}/docs
344
356
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
345
357
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
346
358
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
347
359
cd ${TEMPDIR}/docs/docker-documentation
348
360
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
349
361
git add docs/images/docker-${CONTAINER_NAME}.md
362
+ echo "Updating docs repo"
350
363
git commit -m 'Bot Updating Documentation'
351
364
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
352
365
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
353
366
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
354
367
sleep $((RANDOM % MAXWAIT)) && \
355
368
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
356
369
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
370
+ else
371
+ echo "Docs update not needed, skipping"
357
372
fi
358
373
mkdir -p ${TEMPDIR}/unraid
359
374
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
@@ -364,6 +379,7 @@ pipeline {
364
379
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
365
380
fi
366
381
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
382
+ echo "Updating Unraid template"
367
383
cd ${TEMPDIR}/unraid/templates/
368
384
GH_TEMPLATES_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
369
385
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
@@ -383,16 +399,27 @@ pipeline {
383
399
sleep $((RANDOM % MAXWAIT)) && \
384
400
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH} --rebase && \
385
401
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/templates.git ${GH_TEMPLATES_DEFAULT_BRANCH})
402
+ else
403
+ echo "No updates to Unraid template needed, skipping"
386
404
fi
387
- # Stage 4 - Sync Readme to Docker Hub
388
405
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
389
- if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
406
+ if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) -gt 25000 ]]; then
390
407
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
391
408
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
392
409
else
393
410
echo "Syncing readme to Docker Hub"
394
411
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
395
412
fi
413
+ if curl -s https://hub.docker.com/v2/namespaces/${DOCKERHUB_IMAGE%%/*}/repositories/${DOCKERHUB_IMAGE##*/}/tags | jq -r '.message' | grep -q 404; then
414
+ echo "Docker Hub endpoint doesn't exist. Creating endpoint first."
415
+ 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')
416
+ curl -s \
417
+ -H "Authorization: JWT ${DH_TOKEN}" \
418
+ -H "Content-Type: application/json" \
419
+ -X POST \
420
+ -d '{"name":"'${DOCKERHUB_IMAGE##*/}'", "namespace":"'${DOCKERHUB_IMAGE%%/*}'"}' \
421
+ https://hub.docker.com/v2/repositories/ || :
422
+ fi
396
423
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')
397
424
curl -s \
398
425
-H "Authorization: JWT ${DH_TOKEN}" \
@@ -457,14 +484,16 @@ pipeline {
457
484
}
458
485
steps{
459
486
sh ''' curl -H "Content-Type: application/json" -H "Private-Token: ${GITLAB_TOKEN}" -X POST https://gitlab.com/api/v4/projects \
460
- -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
461
- "name":"'${LS_REPO}'",
462
- "mirror":true,\
463
- "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
464
- "issues_access_level":"disabled",\
465
- "merge_requests_access_level":"disabled",\
466
- "repository_access_level":"enabled",\
467
- "visibility":"public"}' '''
487
+ -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
488
+ "name":"'${LS_REPO}'",
489
+ "mirror":true,\
490
+ "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
491
+ "issues_access_level":"disabled",\
492
+ "merge_requests_access_level":"disabled",\
493
+ "repository_access_level":"enabled",\
494
+ "visibility":"public"}' '''
495
+ sh ''' curl -H "Private-Token: ${GITLAB_TOKEN}" -X PUT "https://gitlab.com/api/v4/projects/Linuxserver.io%2F${LS_REPO}" \
496
+ -d "mirror=true&import_url=https://github.com/linuxserver/${LS_REPO}.git" '''
468
497
}
469
498
}
470
499
/* ###############
0 commit comments