From 4410c570bfcbe9ba28f5f0b7d5540ab191a7ba24 Mon Sep 17 00:00:00 2001
From: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Date: Wed, 9 Sep 2020 18:14:41 +0200
Subject: [PATCH] ready for docker!

---
 .gitlab-ci.yml                         | 14 +++++++++++++
 Dockerfile                             | 19 +++++++++++++++++
 crontab                                |  1 +
 run.sh                                 | 29 ++++++++++++++++++++++++++
 program_info.py => src/program_info.py |  0
 telegram_bot.py => src/telegram_bot.py |  0
 twitter_bot.py => src/twitter_bot.py   |  0
 7 files changed, 63 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 Dockerfile
 create mode 100644 crontab
 create mode 100755 run.sh
 rename program_info.py => src/program_info.py (100%)
 rename telegram_bot.py => src/telegram_bot.py (100%)
 rename twitter_bot.py => src/twitter_bot.py (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..96ff835b
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,14 @@
+
+
+stages:
+  - build
+
+docker:
+  stage: build
+  before_script: []
+  image: 
+    name: gcr.io/kaniko-project/executor:debug
+    entrypoint: [""]
+  script:
+    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
+    - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:latest
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 00000000..89fc3888
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,19 @@
+FROM python:3-alpine
+
+RUN apk upgrade --available --update
+
+WORKDIR /usr/src/app
+COPY requirements.txt ./
+
+RUN apk add --no-cache build-base && \
+    pip install --no-cache-dir -r requirements.txt && \
+    apk del build-base
+
+COPY src .
+COPY run.sh /usr/local/bin/run.sh
+COPY crontab /var/spool/cron/crontabs/programbot
+RUN chmod +x /usr/local/bin/run.sh
+
+RUN apk add --no-cache msmtp
+
+CMD ["crond", "-f"]
diff --git a/crontab b/crontab
new file mode 100644
index 00000000..85af2c8e
--- /dev/null
+++ b/crontab
@@ -0,0 +1 @@
+* 9 * * * /usr/local/bin/run.sh >/dev/null 2>&1
diff --git a/run.sh b/run.sh
new file mode 100755
index 00000000..0c5c4369
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+cd /usr/src/app
+
+function preview {
+
+        (>&2 echo "run twitter")
+    python3 twitter_bot.py --nofailmessage --daydiff 2
+    echo ""
+        (>&2 echo "run telegram")
+    python3 telegram_bot.py --nofailmessage --daydiff 2
+    echo ""
+
+        (>&2 echo "run twitter as doit")
+    python3 twitter_bot.py --nofailmessage --daydiff 1 --doit
+    echo ""
+        (>&2 echo "run telegram as doit")
+    python3 telegram_bot.py --nofailmessage --daydiff 1 --doit
+    echo ""
+    }
+
+OUTPUT="$(preview)"
+
+if [ ! -z "$OUTPUT" ]
+then
+
+echo "$OUTPUT" | msmtp -a "Content-Type: text/plain; charset=UTF-8" ${MSMTP_ARGUMENTS}
+
+fi
diff --git a/program_info.py b/src/program_info.py
similarity index 100%
rename from program_info.py
rename to src/program_info.py
diff --git a/telegram_bot.py b/src/telegram_bot.py
similarity index 100%
rename from telegram_bot.py
rename to src/telegram_bot.py
diff --git a/twitter_bot.py b/src/twitter_bot.py
similarity index 100%
rename from twitter_bot.py
rename to src/twitter_bot.py
-- 
GitLab