From ef4e830f46edea63b3ea91a02cb156f02df54636 Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Thu, 2 Mar 2023 19:54:46 -0600 Subject: [PATCH] Allow user customizable cron --- Jenkinsfile | 46 ++++++++----------- README.md | 1 + readme-vars.yml | 1 + root/app/feed2toot-cron.sh | 4 ++ root/etc/crontabs/root | 2 +- ...-feed2toot-config => init-crontabs-config} | 0 .../dependencies.d/init-feed2toot-config | 0 .../s6-rc.d/init-crontabs-config/run | 22 +++++++++ .../s6-rc.d/init-crontabs-config/type | 1 + .../s6-rc.d/init-crontabs-config/up | 1 + .../s6-rc.d/init-feed2toot-config/run | 5 +- root/etc/s6-overlay/s6-rc.d/svc-cron/run | 4 +- .../user/contents.d/init-crontabs-config | 0 13 files changed, 52 insertions(+), 35 deletions(-) create mode 100755 root/app/feed2toot-cron.sh rename root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/{init-feed2toot-config => init-crontabs-config} (100%) create mode 100644 root/etc/s6-overlay/s6-rc.d/init-crontabs-config/dependencies.d/init-feed2toot-config create mode 100755 root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run create mode 100644 root/etc/s6-overlay/s6-rc.d/init-crontabs-config/type create mode 100644 root/etc/s6-overlay/s6-rc.d/init-crontabs-config/up create mode 100644 root/etc/s6-overlay/s6-rc.d/user/contents.d/init-crontabs-config diff --git a/Jenkinsfile b/Jenkinsfile index 3430944..ce8bf57 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -442,7 +442,8 @@ pipeline { } steps { echo "Running on node: ${NODE_NAME}" - sh "docker build \ + sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile" + sh "docker buildx build \ --label \"org.opencontainers.image.created=${GITHUB_DATE}\" \ --label \"org.opencontainers.image.authors=linuxserver.io\" \ --label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-feed2toot/packages\" \ @@ -455,7 +456,7 @@ pipeline { --label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \ --label \"org.opencontainers.image.title=Feed2toot\" \ --label \"org.opencontainers.image.description=[Feed2toot](https://gitlab.com/chaica/feed2toot) automatically parses rss feeds, identifies new posts and posts them on the Mastodon social network.\" \ - --no-cache --pull -t ${IMAGE}:${META_TAG} \ + --no-cache --pull -t ${IMAGE}:${META_TAG} --platform=linux/amd64 \ --build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ." } } @@ -472,7 +473,8 @@ pipeline { stage('Build X86') { steps { echo "Running on node: ${NODE_NAME}" - sh "docker build \ + sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile" + sh "docker buildx build \ --label \"org.opencontainers.image.created=${GITHUB_DATE}\" \ --label \"org.opencontainers.image.authors=linuxserver.io\" \ --label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-feed2toot/packages\" \ @@ -485,7 +487,7 @@ pipeline { --label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \ --label \"org.opencontainers.image.title=Feed2toot\" \ --label \"org.opencontainers.image.description=[Feed2toot](https://gitlab.com/chaica/feed2toot) automatically parses rss feeds, identifies new posts and posts them on the Mastodon social network.\" \ - --no-cache --pull -t ${IMAGE}:amd64-${META_TAG} \ + --no-cache --pull -t ${IMAGE}:amd64-${META_TAG} --platform=linux/amd64 \ --build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ." } } @@ -499,7 +501,8 @@ pipeline { sh '''#! /bin/bash echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin ''' - sh "docker build \ + sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile.armhf" + sh "docker buildx build \ --label \"org.opencontainers.image.created=${GITHUB_DATE}\" \ --label \"org.opencontainers.image.authors=linuxserver.io\" \ --label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-feed2toot/packages\" \ @@ -512,7 +515,7 @@ pipeline { --label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \ --label \"org.opencontainers.image.title=Feed2toot\" \ --label \"org.opencontainers.image.description=[Feed2toot](https://gitlab.com/chaica/feed2toot) automatically parses rss feeds, identifies new posts and posts them on the Mastodon social network.\" \ - --no-cache --pull -f Dockerfile.armhf -t ${IMAGE}:arm32v7-${META_TAG} \ + --no-cache --pull -f Dockerfile.armhf -t ${IMAGE}:arm32v7-${META_TAG} --platform=linux/arm/v7 \ --build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ." sh "docker tag ${IMAGE}:arm32v7-${META_TAG} ghcr.io/linuxserver/lsiodev-buildcache:arm32v7-${COMMIT_SHA}-${BUILD_NUMBER}" retry(5) { @@ -533,7 +536,8 @@ pipeline { sh '''#! /bin/bash echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin ''' - sh "docker build \ + sh "sed -r -i 's|(^FROM .*)|\\1\\n\\nENV LSIO_FIRST_PARTY=true|g' Dockerfile.aarch64" + sh "docker buildx build \ --label \"org.opencontainers.image.created=${GITHUB_DATE}\" \ --label \"org.opencontainers.image.authors=linuxserver.io\" \ --label \"org.opencontainers.image.url=https://github.com/linuxserver/docker-feed2toot/packages\" \ @@ -546,7 +550,7 @@ pipeline { --label \"org.opencontainers.image.ref.name=${COMMIT_SHA}\" \ --label \"org.opencontainers.image.title=Feed2toot\" \ --label \"org.opencontainers.image.description=[Feed2toot](https://gitlab.com/chaica/feed2toot) automatically parses rss feeds, identifies new posts and posts them on the Mastodon social network.\" \ - --no-cache --pull -f Dockerfile.aarch64 -t ${IMAGE}:arm64v8-${META_TAG} \ + --no-cache --pull -f Dockerfile.aarch64 -t ${IMAGE}:arm64v8-${META_TAG} --platform=linux/arm64 \ --build-arg ${BUILD_VERSION_ARG}=${EXT_RELEASE} --build-arg VERSION=\"${VERSION_TAG}\" --build-arg BUILD_DATE=${GITHUB_DATE} ." sh "docker tag ${IMAGE}:arm64v8-${META_TAG} ghcr.io/linuxserver/lsiodev-buildcache:arm64v8-${COMMIT_SHA}-${BUILD_NUMBER}" retry(5) { @@ -575,26 +579,12 @@ pipeline { else LOCAL_CONTAINER=${IMAGE}:${META_TAG} fi - if [ "${DIST_IMAGE}" == "alpine" ]; then - docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\ - apk info -v > /tmp/package_versions.txt && \ - sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \ - chmod 777 /tmp/package_versions.txt' - elif [ "${DIST_IMAGE}" == "ubuntu" ]; then - docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\ - apt list -qq --installed | sed "s#/.*now ##g" | cut -d" " -f1 > /tmp/package_versions.txt && \ - sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \ - chmod 777 /tmp/package_versions.txt' - elif [ "${DIST_IMAGE}" == "fedora" ]; then - docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\ - rpm -qa > /tmp/package_versions.txt && \ - sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \ - chmod 777 /tmp/package_versions.txt' - elif [ "${DIST_IMAGE}" == "arch" ]; then - docker run --rm --entrypoint '/bin/sh' -v ${TEMPDIR}:/tmp ${LOCAL_CONTAINER} -c '\ - pacman -Q > /tmp/package_versions.txt && \ - chmod 777 /tmp/package_versions.txt' - fi + touch ${TEMPDIR}/package_versions.txt + docker run --rm \ + -v /var/run/docker.sock:/var/run/docker.sock:ro \ + -v ${TEMPDIR}:/tmp \ + ghcr.io/anchore/syft:latest \ + ${LOCAL_CONTAINER} -o table=/tmp/package_versions.txt NEW_PACKAGE_TAG=$(md5sum ${TEMPDIR}/package_versions.txt | cut -c1-8 ) echo "Package tag sha from current packages in buit container is ${NEW_PACKAGE_TAG} comparing to old ${PACKAGE_TAG} from github" if [ "${NEW_PACKAGE_TAG}" != "${PACKAGE_TAG}" ]; then diff --git a/README.md b/README.md index ec901bc..19ef4fa 100644 --- a/README.md +++ b/README.md @@ -224,5 +224,6 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64 ## Versions +* **02.03.23:** - Allow user customizable cron. * **22.12.22:** - Rebase to alpine 3.17. * **14.11.22:** - Initial Release. diff --git a/readme-vars.yml b/readme-vars.yml index 5c33130..543efb2 100644 --- a/readme-vars.yml +++ b/readme-vars.yml @@ -52,5 +52,6 @@ app_setup_block: | # changelog changelogs: + - { date: "02.03.23:", desc: "Allow user customizable cron." } - { date: "22.12.22:", desc: "Rebase to alpine 3.17." } - { date: "14.11.22:", desc: "Initial Release." } diff --git a/root/app/feed2toot-cron.sh b/root/app/feed2toot-cron.sh new file mode 100755 index 0000000..10c290f --- /dev/null +++ b/root/app/feed2toot-cron.sh @@ -0,0 +1,4 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +s6-setuidgid abc python3 /usr/bin/feed2toot -l "${FEED_LIMIT:-5}" -c /config/feed2toot.ini diff --git a/root/etc/crontabs/root b/root/etc/crontabs/root index 2667bf0..fca22f4 100644 --- a/root/etc/crontabs/root +++ b/root/etc/crontabs/root @@ -1 +1 @@ -*/15 * * * * s6-setuidgid abc python3 /usr/bin/feed2toot -l 5 -c /config/feed2toot.ini 2>&1 \ No newline at end of file +*/15 * * * * /app/feed2toot-cron.sh 2>&1 diff --git a/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-feed2toot-config b/root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-crontabs-config similarity index 100% rename from root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-feed2toot-config rename to root/etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-crontabs-config diff --git a/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/dependencies.d/init-feed2toot-config b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/dependencies.d/init-feed2toot-config new file mode 100644 index 0000000..e69de29 diff --git a/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run new file mode 100755 index 0000000..1080bb6 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/run @@ -0,0 +1,22 @@ +#!/usr/bin/with-contenv bash +# shellcheck shell=bash + +# make folders +mkdir -p \ + /config/crontabs + +## root +# if crontabs do not exist in config +if [[ ! -f /config/crontabs/root ]]; then + # copy crontab from system + if crontab -l -u root; then + crontab -l -u root >/config/crontabs/root + fi + + # if crontabs still do not exist in config (were not copied from system) + # copy crontab from included defaults (using -n, do not overwrite an existing file) + cp -n /etc/crontabs/root /config/crontabs/ +fi +# set permissions and import user crontabs +lsiown root:root /config/crontabs/root +crontab -u root /config/crontabs/root diff --git a/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/type b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/type new file mode 100644 index 0000000..bdd22a1 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/type @@ -0,0 +1 @@ +oneshot diff --git a/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/up b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/up new file mode 100644 index 0000000..006d814 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/init-crontabs-config/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-crontabs-config/run diff --git a/root/etc/s6-overlay/s6-rc.d/init-feed2toot-config/run b/root/etc/s6-overlay/s6-rc.d/init-feed2toot-config/run index d185b66..3917e4a 100755 --- a/root/etc/s6-overlay/s6-rc.d/init-feed2toot-config/run +++ b/root/etc/s6-overlay/s6-rc.d/init-feed2toot-config/run @@ -1,4 +1,5 @@ #!/usr/bin/with-contenv bash +# shellcheck shell=bash if [[ ! -f /config/feed2toot.ini ]]; then cp /defaults/feed2toot.ini /config/feed2toot.ini @@ -6,10 +7,6 @@ fi touch /config/hashtags.txt -if [[ -n ${FEED_LIMIT} ]]; then - sed -i "s/-l [[:digit:]]\+/-l ${FEED_LIMIT:-5}/" /etc/crontabs/root -fi - # permissions lsiown -R abc:abc \ /config diff --git a/root/etc/s6-overlay/s6-rc.d/svc-cron/run b/root/etc/s6-overlay/s6-rc.d/svc-cron/run index 2afc3b0..5eaadfd 100755 --- a/root/etc/s6-overlay/s6-rc.d/svc-cron/run +++ b/root/etc/s6-overlay/s6-rc.d/svc-cron/run @@ -1,4 +1,4 @@ #!/usr/bin/with-contenv bash +# shellcheck shell=bash -exec \ - /usr/sbin/crond -f -S -l 0 -c /etc/crontabs +exec /usr/sbin/crond -f -S -l 5 diff --git a/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-crontabs-config b/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-crontabs-config new file mode 100644 index 0000000..e69de29