Skip to content

Commit aa241ca

Browse files
authored
Merge pull request #57 from linuxserver/rework-shell-cron
Rework shell scripts and cron logic
2 parents beda30c + a8822d2 commit aa241ca

File tree

7 files changed

+39
-49
lines changed

7 files changed

+39
-49
lines changed

Jenkinsfile

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ pipeline {
440440
}
441441
steps {
442442
echo "Running on node: ${NODE_NAME}"
443-
sh "docker build \
443+
sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile"
444+
sh "docker buildx build \
444445
--label \"org.opencontainers.image.created=${GITHUB_DATE}\" \
445446
--label \"org.opencontainers.image.authors=linuxserver.io\" \
446447
--label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-duckdns/packages\" \
@@ -453,7 +454,7 @@ pipeline {
453454
--label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \
454455
--label \"org.opencontainers.image.title=Duckdns\" \
455456
--label \"org.opencontainers.image.description=[Duckdns](https://duckdns.org/) is a free service which will point a DNS (sub domains of duckdns.org) to an IP of your choice. The service is completely free, and doesn't require reactivation or forum posts to maintain its existence.\" \
456-
--no-cache --pull -t ${IMAGE}:${META_TAG} \
457+
--no-cache --pull -t ${IMAGE}:${META_TAG} --platform=linux/amd64 \
457458
--build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ."
458459
}
459460
}
@@ -470,7 +471,8 @@ pipeline {
470471
stage('Build X86') {
471472
steps {
472473
echo "Running on node: ${NODE_NAME}"
473-
sh "docker build \
474+
sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile"
475+
sh "docker buildx build \
474476
--label \"org.opencontainers.image.created=${GITHUB_DATE}\" \
475477
--label \"org.opencontainers.image.authors=linuxserver.io\" \
476478
--label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-duckdns/packages\" \
@@ -483,7 +485,7 @@ pipeline {
483485
--label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \
484486
--label \"org.opencontainers.image.title=Duckdns\" \
485487
--label \"org.opencontainers.image.description=[Duckdns](https://duckdns.org/) is a free service which will point a DNS (sub domains of duckdns.org) to an IP of your choice. The service is completely free, and doesn't require reactivation or forum posts to maintain its existence.\" \
486-
--no-cache --pull -t ${IMAGE}:amd64-${META_TAG} \
488+
--no-cache --pull -t ${IMAGE}:amd64-${META_TAG} --platform=linux/amd64 \
487489
--build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ."
488490
}
489491
}
@@ -497,7 +499,8 @@ pipeline {
497499
sh '''#! /bin/bash
498500
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
499501
'''
500-
sh "docker build \
502+
sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile.armhf"
503+
sh "docker buildx build \
501504
--label \"org.opencontainers.image.created=${GITHUB_DATE}\" \
502505
--label \"org.opencontainers.image.authors=linuxserver.io\" \
503506
--label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-duckdns/packages\" \
@@ -510,7 +513,7 @@ pipeline {
510513
--label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \
511514
--label \"org.opencontainers.image.title=Duckdns\" \
512515
--label \"org.opencontainers.image.description=[Duckdns](https://duckdns.org/) is a free service which will point a DNS (sub domains of duckdns.org) to an IP of your choice. The service is completely free, and doesn't require reactivation or forum posts to maintain its existence.\" \
513-
--no-cache --pull -f Dockerfile.armhf -t ${IMAGE}:arm32v7-${META_TAG} \
516+
--no-cache --pull -f Dockerfile.armhf -t ${IMAGE}:arm32v7-${META_TAG} --platform=linux/arm/v7 \
514517
--build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ."
515518
sh "docker tag ${IMAGE}:arm32v7-${META_TAG} ghcr.io/linuxserver/lsiodev-buildcache:arm32v7-${COMMIT_SHA}-${BUILD_NUMBER}"
516519
retry(5) {
@@ -531,7 +534,8 @@ pipeline {
531534
sh '''#! /bin/bash
532535
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
533536
'''
534-
sh "docker build \
537+
sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile.aarch64"
538+
sh "docker buildx build \
535539
--label \"org.opencontainers.image.created=${GITHUB_DATE}\" \
536540
--label \"org.opencontainers.image.authors=linuxserver.io\" \
537541
--label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-duckdns/packages\" \
@@ -544,7 +548,7 @@ pipeline {
544548
--label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \
545549
--label \"org.opencontainers.image.title=Duckdns\" \
546550
--label \"org.opencontainers.image.description=[Duckdns](https://duckdns.org/) is a free service which will point a DNS (sub domains of duckdns.org) to an IP of your choice. The service is completely free, and doesn't require reactivation or forum posts to maintain its existence.\" \
547-
--no-cache --pull -f Dockerfile.aarch64 -t ${IMAGE}:arm64v8-${META_TAG} \
551+
--no-cache --pull -f Dockerfile.aarch64 -t ${IMAGE}:arm64v8-${META_TAG} --platform=linux/arm64 \
548552
--build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ."
549553
sh "docker tag ${IMAGE}:arm64v8-${META_TAG} ghcr.io/linuxserver/lsiodev-buildcache:arm64v8-${COMMIT_SHA}-${BUILD_NUMBER}"
550554
retry(5) {
@@ -573,26 +577,12 @@ pipeline {
573577
else
574578
LOCAL_CONTAINER=${IMAGE}:${META_TAG}
575579
fi
576-
if [ "${DIST_IMAGE}" == "alpine" ]; then
577-
docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\
578-
apk info -v > /tmp/package_versions.txt && \
579-
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
580-
chmod 777 /tmp/package_versions.txt'
581-
elif [ "${DIST_IMAGE}" == "ubuntu" ]; then
582-
docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\
583-
apt list -qq --installed | sed "s#/.*now ##g" | cut -d" " -f1 > /tmp/package_versions.txt && \
584-
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
585-
chmod 777 /tmp/package_versions.txt'
586-
elif [ "${DIST_IMAGE}" == "fedora" ]; then
587-
docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\
588-
rpm -qa > /tmp/package_versions.txt && \
589-
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
590-
chmod 777 /tmp/package_versions.txt'
591-
elif [ "${DIST_IMAGE}" == "arch" ]; then
592-
docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\
593-
pacman -Q > /tmp/package_versions.txt && \
594-
chmod 777 /tmp/package_versions.txt'
595-
fi
580+
touch ${TEMPDIR}/package_versions.txt
581+
docker run --rm \
582+
-v /var/run/docker.sock:/var/run/docker.sock:ro \
583+
-v ${TEMPDIR}:/tmp \
584+
ghcr.io/anchore/syft:latest \
585+
${LOCAL_CONTAINER} -o table=/tmp/package_versions.txt
596586
NEW_PACKAGE_TAG=$(md5sum ${TEMPDIR}/package_versions.txt | cut -c1-8 )
597587
echo "Package tag sha from current packages in buit container is ${NEW_PACKAGE_TAG} comparing to old ${PACKAGE_TAG} from github"
598588
if [ "${NEW_PACKAGE_TAG}" != "${PACKAGE_TAG}" ]; then

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
231231

232232
## Versions
233233

234+
* **02.03.23:** - Rework shell scripts and cron logic.
234235
* **13.02.23:** - Rebase to alpine 3.17.
235236
* **23.09.22:** - Rebase to alpine 3.16 and s6v3.
236237
* **19.09.22:** - Rebase to alpine 3.15.

readme-vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ app_setup_block: |
6464
6565
# changelog
6666
changelogs:
67+
- { date: "02.03.23:", desc: "Rework shell scripts and cron logic." }
6768
- { date: "13.02.23:", desc: "Rebase to alpine 3.17." }
6869
- { date: "23.09.22:", desc: "Rebase to alpine 3.16 and s6v3." }
6970
- { date: "19.09.22:", desc: "Rebase to alpine 3.15." }

root/app/duck.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

3-
# shellcheck source=/dev/null
4-
. /app/duck.conf
5-
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=")
6-
if [ "${RESPONSE}" = "OK" ]; then
7-
echo "Your IP was updated at $(date)"
4+
if [ "${LOG_FILE}" = "true" ]; then
5+
DUCK_LOG="/config/duck.log"
6+
touch "${DUCK_LOG}"
7+
touch /config/logrotate.status
8+
/usr/sbin/logrotate -s /config/logrotate.status /app/logrotate.conf
89
else
9-
echo -e "Something went wrong, please check your settings $(date)\nThe response returned was:\n${RESPONSE}"
10+
DUCK_LOG="/dev/null"
1011
fi
12+
13+
{
14+
RESPONSE=$(curl -sS --max-time 60 "https://www.duckdns.org/update?domains=${SUBDOMAINS}&token=${TOKEN}&ip=")
15+
if [ "${RESPONSE}" = "OK" ]; then
16+
echo "Your IP was updated at $(date)"
17+
else
18+
echo -e "Something went wrong, please check your settings $(date)\nThe response returned was:\n${RESPONSE}"
19+
fi
20+
} | tee -a "${DUCK_LOG}"

root/defaults/duckcron

Lines changed: 0 additions & 2 deletions
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-duckdns/run

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
#Check to make sure the subdomain and token are set
45
if [ -z "${SUBDOMAINS}" ] || [ -z "${TOKEN}" ]; then
56
echo "Please pass both your subdomain(s) and token as environment variables in your docker run command. See the readme for more details."
67
sleep infinity
7-
else
8-
echo "Retrieving subdomain and token from the environment variables"
9-
echo -e "SUBDOMAINS=\"${SUBDOMAINS}\" TOKEN=\"${TOKEN}\"" >/app/duck.conf
10-
fi
11-
12-
# modify crontab if logging to file
13-
if [ "${LOG_FILE}" = "true" ]; then
14-
crontab -u abc /defaults/duckcron
15-
echo "log will be output to file"
16-
else
17-
echo "log will be output to docker log"
188
fi
199

2010
# permissions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

3-
exec \
4-
/usr/sbin/crond -f -S -l 0 -c /etc/crontabs
4+
exec /usr/sbin/crond -f -S -l 5

0 commit comments

Comments
 (0)