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