diff --git a/.drone.yml b/.drone.yml index 5ebcfde..10a177c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,12 +5,11 @@ kind: pipeline name: default - -platform: - os: linux - arch: amd64 +type: docker steps: + - name: reuse + image: fsfe/reuse:latest - name: deploy pull: if-not-exists image: docker/compose:1.29.2 @@ -18,7 +17,7 @@ steps: XDG_RUNTIME_DIR: "/run/user/1001" DOCKER_HOST: "unix:///run/user/1001/docker.sock" commands: - - docker-compose --project-name reminder-mails up --build -d + - docker-compose -p reminder-mails up --build -d volumes: - name: dockersock path: /run/user/1001/docker.sock diff --git a/msmtprc b/.msmtprc similarity index 87% rename from msmtprc rename to .msmtprc index f98d5ae..d14040e 100644 --- a/msmtprc +++ b/.msmtprc @@ -8,7 +8,7 @@ auth off tls on tls_starttls on tls_certcheck off -logfile /home/reminder/reminder-mails/msmtp.log +logfile ~/.msmtp.log # FSFE account fsfe diff --git a/Dockerfile b/Dockerfile index df9be75..a0bccc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,42 +3,31 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Base image selection -FROM debian:buster-slim +FROM bitnami/minideb:bullseye # Installing the services and dependencies -ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C.UTF-8 LANGUAGE=en_US.UTF-8 -RUN [ "apt-get", "-q", "update" ] -RUN [ "apt-get", "-qy", "--force-yes", "upgrade" ] -RUN [ "apt-get", "install", "--no-install-recommends", "-qy", "--force-yes", \ - "ca-certificates", \ - "git", \ - "cron", \ - "msmtp" ] -RUN [ "apt-get", "clean" ] -RUN [ "rm", "-rf", "/var/lib/apt/lists/*", "/tmp/*", "/var/tmp/*" ] +RUN install_packages msmtp ca-certificates curl -RUN adduser --quiet --disabled-password --shell /bin/bash --home /home/reminder --gecos "User" reminder +# Manually install supercronic +ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64 \ + SUPERCRONIC=supercronic-linux-amd64 \ + SUPERCRONIC_SHA1SUM=048b95b48b708983effb2e5c935a1ef8483d9e3e + +RUN curl -fsSLO "$SUPERCRONIC_URL" \ + && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \ + && chmod +x "$SUPERCRONIC" \ + && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \ + && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic + +RUN adduser --shell "/sbin/nologin" --gecos "Reminder" --disabled-password reminder USER reminder WORKDIR /home/reminder -# Add latest master branch version to skip loading from cache if newer commit available -ADD https://git.fsfe.org/api/v1/repos/fsfe-system-hackers/reminder-mails/branches/master version.json +RUN mkdir mails +COPY reminder-mails.sh cron.txt .msmtprc /home/reminder/ +COPY mails/* /home/reminder/mails/ -RUN git clone https://git.fsfe.org/fsfe-system-hackers/reminder-mails.git - -WORKDIR /home/reminder/reminder-mails - -# First run to create files -RUN /home/reminder/reminder-mails/reminder-mails.sh - -# Add crontab file in the cron directory -ADD cron.txt /etc/cron.d/reminder-mails - -# Give execution rights on the cron job -USER root -RUN chmod 0644 /etc/cron.d/reminder-mails - -# CMD to run the service on container start -CMD cron && : >> /home/reminder/reminder-mails/app.log && tail -f /home/reminder/reminder-mails/app.log +# CMD to run the cron on container start +CMD supercronic /home/reminder/cron.txt diff --git a/cron.txt b/cron.txt index b14650d..b347157 100644 --- a/cron.txt +++ b/cron.txt @@ -2,6 +2,6 @@ # # SPDX-License-Identifier: CC0-1.0 -0 22 15 2,5,8,11 * reminder /home/reminder/reminder-mails/reminder-mails.sh access-review -0 22 15 1,4,7,10 * reminder /home/reminder/reminder-mails/reminder-mails.sh services-review -0 22 15 3,6,9,12 * reminder /home/reminder/reminder-mails/reminder-mails.sh mailinglist-review +0 22 15 2,5,8,11 * /home/reminder/reminder-mails.sh access-review +0 22 15 1,4,7,10 * /home/reminder/reminder-mails.sh services-review +0 22 15 3,6,9,12 * /home/reminder/reminder-mails.sh mailinglist-review diff --git a/reminder-mails.sh b/reminder-mails.sh index af7a639..5ebca68 100755 --- a/reminder-mails.sh +++ b/reminder-mails.sh @@ -2,19 +2,11 @@ # This file takes care of identifying the requested mail, adding necessary # information to the template, and piping it to msmtp to send it out. -# +# # Copyright (c) 2018 Free Software Foundation Europe # Author 2018 Max Mehl # SPDX-License-Identifier: GPL-3.0-or-later -basedir="${0%/*}" -LOG="${basedir}/app.log" -touch "${LOG}" -touch "${basedir}/msmtp.log" - -exec > >(tee -ia "${LOG}") -exec 2>&1 - function decho { DATE=$(date +%y-%m-%d_%H:%M:%S%z) echo "[$DATE] $*" @@ -24,12 +16,13 @@ EMAIL=$1 # If argument is given, check for mail template and send it out if [[ ! -z "$EMAIL" ]]; then - if [[ -e "${basedir}/mails/$EMAIL" ]]; then - cat "${basedir}/mails/$EMAIL" | sed "1s|^|Date: $(date -R)\n|" | sed "1s|^|Message-ID: \n|" | msmtp -C "${basedir}"/msmtprc -t --read-envelope-from -a fsfe + if [[ -e "${HOME}/mails/$EMAIL" ]]; then + cat "${HOME}/mails/$EMAIL" | sed "1s|^|Date: $(date -R)\n|" | sed "1s|^|Message-ID: \n|" | msmtp -t --read-envelope-from -a fsfe if [[ "$?" == 0 ]]; then decho "[INFO] Mail \"$EMAIL\" has been sent successfully" else decho "[ERROR] There has been an error with sending \"$EMAIL\"". + exit 1 fi else decho "[ERROR] Mail template \"$EMAIL\" does not exist." diff --git a/renovate.json.license b/renovate.json.license new file mode 100644 index 0000000..c6e72a6 --- /dev/null +++ b/renovate.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2022 Free Software Foundation Europe + +SPDX-License-Identifier: CC0-1.0