Skip to content

Commit

Permalink
Merge pull request #162 from AnalogJ/cron
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Apr 24, 2021
2 parents 27b923b + c55bdcb commit 93cf789
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 52 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/dist
/vendor
/.idea
/.github
/.git
/webapp/frontend/node_modules
12 changes: 5 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,25 @@ EXPOSE 8080
WORKDIR /scrutiny
ENV PATH="/scrutiny/bin:${PATH}"

ADD https://github.com/dshearer/jobber/releases/download/v1.4.4/jobber_1.4.4-1_amd64.deb /tmp/
RUN apt install /tmp/jobber_1.4.4-1_amd64.deb

RUN apt-get update && apt-get install -y smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates curl && update-ca-certificates
RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates curl && update-ca-certificates

ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/
RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C /
COPY /rootfs /

COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /scrutiny/bin/
COPY --from=frontendbuild /scrutiny/dist /scrutiny/web
RUN chmod +x /scrutiny/bin/scrutiny && \
chmod +x /scrutiny/bin/scrutiny-collector-selftest && \
chmod +x /scrutiny/bin/scrutiny-collector-metrics && \
chmod 0644 /etc/cron.d/scrutiny && \
rm -f /etc/cron.daily/* && \
mkdir -p /scrutiny/web && \
mkdir -p /scrutiny/config && \
mkdir -p /scrutiny/jobber && \
chmod -R ugo+rwx /scrutiny/config && \
chmod -R ugo+rwx /scrutiny/jobber
chmod -R ugo+rwx /scrutiny/config


CMD ["/init"]
16 changes: 7 additions & 9 deletions docker/Dockerfile.collector
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ RUN go mod vendor && \

########
FROM ubuntu:bionic as runtime
EXPOSE 8080
WORKDIR /scrutiny
ENV PATH="/scrutiny/bin:${PATH}"

ADD https://github.com/dshearer/jobber/releases/download/v1.4.4/jobber_1.4.4-1_amd64.deb /tmp/
RUN apt install /tmp/jobber_1.4.4-1_amd64.deb

RUN apt-get update && apt-get install -y smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates && update-ca-certificates

COPY /rootfs/scrutiny /scrutiny
RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates && update-ca-certificates

COPY /docker/entrypoint-collector.sh /entrypoint-collector.sh
COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /scrutiny/bin/
COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /scrutiny/bin/
RUN chmod +x /scrutiny/bin/scrutiny-collector-selftest && \
chmod +x /scrutiny/bin/scrutiny-collector-metrics
chmod +x /scrutiny/bin/scrutiny-collector-metrics && \
chmod 0644 /etc/cron.d/scrutiny && \
rm -f /etc/cron.daily/apt /etc/cron.daily/dpkg /etc/cron.daily/passwd

CMD ["/usr/lib/x86_64-linux-gnu/jobberrunner", "/scrutiny/jobber/jobber.yaml"]
CMD ["/entrypoint-collector.sh"]
9 changes: 9 additions & 0 deletions docker/entrypoint-collector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cron runs in its own isolated environment (usually using only /etc/environment )
# So when the container starts up, we will do a dump of the runtime environment into a .env file that we
# will then source into the crontab file (/etc/cron.d/scrutiny.sh)

printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh

# now that we have the env start cron in the foreground
echo "starting cron"
cron -f
7 changes: 7 additions & 0 deletions rootfs/etc/cont-init.d/01-timezone
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/with-contenv bash

if [ -n "${TZ}" ]
then
ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
fi
15 changes: 15 additions & 0 deletions rootfs/etc/cron.d/scrutiny
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MAILTO=""
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

# correctly route collector logs (STDOUT & STDERR) to Cron foreground (collectable by Docker STDOUT)
# cron schedule to run daily at midnight: '0 0 * * *'
# System environmental variables are stripped by cron, source our dump of the docker environmental variables before each command (/env.sh)
0 0 * * * root . /env.sh; /scrutiny/bin/scrutiny-collector-metrics run >/proc/1/fd/1 2>/proc/1/fd/2
# An empty line is required at the end of this file for a valid cron file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/execlineb -S0

echo "jobber/cron exiting"
echo "cron exiting"
s6-svscanctl -t /var/run/s6/services
10 changes: 10 additions & 0 deletions rootfs/etc/services.d/cron/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bash

# Cron runs in its own isolated environment (usually using only /etc/environment )
# So when the container starts up, we will do a dump of the runtime environment into a .env file that we
# will then source into the crontab file (/etc/cron.d/scrutiny.sh)

printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh

echo "starting cron"
cron -f
5 changes: 0 additions & 5 deletions rootfs/etc/services.d/jobber/run

This file was deleted.

Empty file added rootfs/scrutiny/.gitinclude
Empty file.
30 changes: 0 additions & 30 deletions rootfs/scrutiny/jobber/jobber.yaml

This file was deleted.

0 comments on commit 93cf789

Please sign in to comment.