From 73ad500686de2c455f52aa156ebd6e067a21dd93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?PICHOU=20Ky=C3=A2ne?= <kyane@kyane.fr>
Date: Mon, 17 Sep 2018 21:51:20 +0200
Subject: [PATCH] Add docker image

---
 .dockerignore | 27 +++++++++++++++++++++++++++
 Dockerfile    | 14 ++++++++++++++
 README.md     |  4 ++++
 entrypoint.sh |  9 +++++++++
 4 files changed, 54 insertions(+)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100755 entrypoint.sh

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..b03b075
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,27 @@
+##### Project related files #####
+config/config.json
+Dockerfile
+README.md
+.git/
+
+##### Python related files #####
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# pyenv
+.python-version
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..207f4f6
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,14 @@
+FROM python:3.7-alpine
+
+MAINTAINER kyane@kyane.fr
+
+# Copy all code
+COPY . /code
+WORKDIR /code
+
+# Install dependencies
+RUN pip3 install -r requirements.txt
+
+VOLUME /code/config/config.json
+
+ENTRYPOINT ["/code/entrypoint.sh"]
diff --git a/README.md b/README.md
index 169d9ac..7c96717 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,10 @@ Configuration for InfluxDB is under the `influxdb` key. It is a simple object wi
 
 ### Docker
 
+A simple Docker image is provided in order to run this bot on a regular basis. It is a simple Python 3 (Alpine based) Docker image with all the requirements. The entrypoint is quite simple : a while loop that call the `main.py` script and sleep for some times. The interval to sleep between each calls can be configured with the environment variable `INTERVAL_SECONDS` (default to `60`).
+
+Also, don't forget to mount your configuration file on `/code/config/config.json`
+
 ## Modules
 
 This bot is modular : each module provide an interface allow to collect metrics for a service. The main function use those modules and push all data to InfluxDB.
diff --git a/entrypoint.sh b/entrypoint.sh
new file mode 100755
index 0000000..55700c1
--- /dev/null
+++ b/entrypoint.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+INTERVAL_SECONDS=${INTERVAL_SECONDS:-60}
+
+while :
+do
+  python3 main.py
+  sleep $INTERVAL_SECONDS
+done
-- 
GitLab