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