Send-report build
This commit is contained in:
parent
8d996db8e3
commit
e9214235c8
|
@ -0,0 +1,10 @@
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
RUN apk --no-cache add curl mutt
|
||||||
|
|
||||||
|
COPY send.sh /usr/local/bin/send.sh
|
||||||
|
COPY init.sh /usr/local/bin/init.sh
|
||||||
|
|
||||||
|
RUN chmod +x /usr/local/bin/send.sh /usr/local/bin/init.sh
|
||||||
|
|
||||||
|
CMD ["/usr/local/bin/init.sh"]
|
|
@ -0,0 +1,12 @@
|
||||||
|
Environments to set:
|
||||||
|
|
||||||
|
PDF_URL="https://example.tld/report.pdf"
|
||||||
|
TO_EMAIL="report@example.tld"
|
||||||
|
SMTP_SERVER="smtp.example.com"
|
||||||
|
SMTP_PORT="587"
|
||||||
|
SMTP_USER="your_username"
|
||||||
|
SMTP_PASSWORD="your_password"
|
||||||
|
FROM="Example <report@example.tld>"
|
||||||
|
|
||||||
|
TMP_PDF="/tmp/report.pdf"
|
||||||
|
CRON_SCHEDULE="0 2 * * 0"
|
|
@ -0,0 +1,3 @@
|
||||||
|
docker build . --tag registry.bhasher.com/send-report:latest
|
||||||
|
|
||||||
|
docker push registry.bhasher.com/send-report:latest
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
CRON_SCHEDULE=${CRON_SCHEDULE:-"0 2 * * 0"}
|
||||||
|
|
||||||
|
echo "$CRON_SCHEDULE /usr/local/bin/send.sh" > /etc/crontabs/root
|
||||||
|
|
||||||
|
echo "Service ready on schedule $CRON_SCHEDULE"
|
||||||
|
|
||||||
|
crond -f
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
TMP_PDF="/tmp/report.pdf"
|
||||||
|
|
||||||
|
curl -o "$TMP_PDF" "$PDF_URL"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Sending the report as an attachment" | mutt -s "Weekly Report" -e "set smtp_url=smtps://${SMTP_USER}:${SMTP_PASSWORD}@${SMTP_SERVER}:${SMTP_PORT}" -e 'set from="${FROM}"' -a "$TMP_PDF" -- "${TO_EMAIL}"
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Email sent successfully"
|
||||||
|
else
|
||||||
|
echo "Failed to send the email"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Failed to download the PDF"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$TMP_PDF"
|
Loading…
Reference in New Issue