Browse Source

added cron for periodic sendout

Toastie 4 years ago
parent
commit
9ee8f02192

+ 12 - 0
Dockerfile

@@ -0,0 +1,12 @@
+FROM python:alpine
+
+WORKDIR  /opt/txt2mail
+ENV HOME /opt/txt2mail
+
+COPY ./data/opt/txt2mail/bin/requirements.txt ./bin/
+
+RUN chown -R 1000:1000 . \
+    && adduser -h /opt/txtmail -s /bin/sh -H -D -u 1000 txt2mail \
+    && pip install --no-cache-dir -r ./bin/requirements.txt
+
+VOLUME   /opt/txt2mail

+ 11 - 4
README.md

@@ -3,13 +3,20 @@
 Ships plain text files, e.g. logs or status reports via e-mail.
 Ships plain text files, e.g. logs or status reports via e-mail.
 
 
 ### Functionality
 ### Functionality
-This image sends the content of each text file moved from the folder `1-prep` to `2-ready` via e-mail.
-The first line of the text file is set as mail subject and all following lines as message body.
+- This image sends the content of each text file moved from the folder `1-prep` to `2-ready` via e-mail.
+- The first line of the text file is set as mail subject and all following lines as message body.
 When done, the mail is moved to `3-done`.
 When done, the mail is moved to `3-done`.
-
+- Files can be either moved manually or will be moved periodically
 ```
 ```
-mail/
+data/opt/txt2mail/var/
 ├── 1-prep
 ├── 1-prep
+│   ├── 15min
+│   │   └── testmail
+│   ├── daily
+│   ├── hourly
+│   ├── manually
+│   ├── monthly
+│   └── weekly
 ├── 2-ready
 ├── 2-ready
 └── 3-done
 └── 3-done
 ```
 ```

+ 0 - 12
data/Dockerfile

@@ -1,12 +0,0 @@
-FROM python:alpine
-
-WORKDIR  /opt/txt2mail
-ENV HOME /opt/txt2mail
-
-COPY . .
-RUN chown -R 1000:1000 . && pip install --no-cache-dir -r requirements.txt
-
-VOLUME   /opt/txt2mail
-
-USER 1000:1000
-CMD [ "python", "./txt2mail.py" ]

+ 1 - 0
data/etc/periodic/15min/txt2mail

@@ -0,0 +1 @@
+../txt2mail.sh

+ 1 - 0
data/etc/periodic/daily/txt2mail

@@ -0,0 +1 @@
+../txt2mail.sh

+ 1 - 0
data/etc/periodic/hourly/txt2mail

@@ -0,0 +1 @@
+../txt2mail.sh

+ 1 - 0
data/etc/periodic/monthly/txt2mail

@@ -0,0 +1 @@
+../txt2mail.sh

+ 6 - 0
data/etc/periodic/txt2mail.sh

@@ -0,0 +1,6 @@
+#!/bin/sh -xe
+period=`basename \`dirname $0\``
+prep="/opt/txt2mail/var/1-prep/"
+ready="/opt/txt2mail/var/2-ready/"
+for file in `ls $prep$period`; do mv  $prep$period"/"$file $ready;done
+

+ 1 - 0
data/etc/periodic/weekly/txt2mail

@@ -0,0 +1 @@
+../txt2mail.sh

+ 5 - 0
data/opt/txt2mail/bin/entry.sh

@@ -0,0 +1,5 @@
+#!/bin/sh -x
+
+# Start crond
+/usr/sbin/crond -f -L /dev/stdout &
+su txt2mail -c "python /opt/txt2mail/bin/txt2mail.py"

data/requirements.txt → data/opt/txt2mail/bin/requirements.txt


+ 4 - 3
data/txt2mail.py

@@ -4,9 +4,10 @@ from inotify_simple import INotify, flags
 from email.mime.text import MIMEText
 from email.mime.text import MIMEText
 
 
 # Define and create folders if they don't exist
 # Define and create folders if they don't exist
-prep  = 'mail/1-prep/'
-ready = 'mail/2-ready/'
-done  = 'mail/3-done/'
+base  = '/opt/txt2mail/var/'
+prep  = base + '1-prep/'
+ready = base + '2-ready/'
+done  = base + '3-done/'
 os.makedirs(prep,  exist_ok=True)
 os.makedirs(prep,  exist_ok=True)
 os.makedirs(ready, exist_ok=True)
 os.makedirs(ready, exist_ok=True)
 os.makedirs(done,  exist_ok=True)
 os.makedirs(done,  exist_ok=True)

+ 5 - 2
docker-compose.yml

@@ -2,13 +2,16 @@ version: '2'
 services:
 services:
   txt2mail:
   txt2mail:
     build: 
     build: 
-      context: ./data/
+      context: ./
       dockerfile: Dockerfile
       dockerfile: Dockerfile
     image: toastie89/txt2mail
     image: toastie89/txt2mail
     container_name: txt2mail 
     container_name: txt2mail 
     hostname: txt2mail
     hostname: txt2mail
     restart: on-failure:3
     restart: on-failure:3
     volumes:
     volumes:
-      - './data/:/opt/txt2mail'
+      - './data/opt/txt2mail/bin:/opt/txt2mail/bin:ro'
+      - './data/opt/txt2mail/var:/opt/txt2mail/var:rw'
+      - './data/etc/periodic:/etc/periodic:ro'
     env_file:
     env_file:
       - .env
       - .env
+    entrypoint: '/opt/txt2mail/bin/entry.sh'