From 1c79e1af6f4387e92c673438015e25bb7dc6c3ca Mon Sep 17 00:00:00 2001 From: Gleidson Nascimento Date: Sat, 13 Jun 2020 19:57:04 +1200 Subject: [PATCH] Adding docker support (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added docker support * Documenting docker usage * Add docker hub option to README Co-authored-by: Richard Szolár --- .gitignore | 3 ++- Dockerfile | 12 ++++++++++++ README.md | 18 ++++++++++++++++++ bot-config.template.json | 11 +++++++++++ conf/conf.go | 1 + init.sh | 25 +++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 bot-config.template.json create mode 100755 init.sh diff --git a/.gitignore b/.gitignore index 3ac079a..a0caebe 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out -bot-config.json \ No newline at end of file +bot-config.json +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1be20e2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.14-buster + +CMD /bin/init.sh /bin/rss-bot + +COPY . /code + +WORKDIR /code + +RUN go get ./... + +RUN make gh_linux_amd64 +RUN chmod -R g+rwx /code && cp build/telegram-rss-bot-linux-amd64 /bin/rss-bot && cp init.sh /bin \ No newline at end of file diff --git a/README.md b/README.md index 830ad9b..ea4a3c5 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,24 @@ You can put the config file in the current folder on where the binary resides or - feed_updates_interval: this represents the interval at which rate the feeds saved in the database should be updated in seconds (60 = 60 seconds and so on) - feed_posts_interval: this represents the interval at which rate the feeds should be posted to their respective channels in seconds (60 = 60 seconds and so on) +## Docker support +You can also run this application as a docker container. + +### Docker hub + +You can pull the official docker image +```bash +docker pull ruthless/telegram-rss-bot +``` + +### Build from source +Execute the following steps: +``` +git clone https://github.com/0x111/telegram-rss-bot +docker build -t telegram-rss-bot:latest . +docker run --name telegram-rss-bot -e TELEGRAM_AUTH_KEY="MY-TOKEN" -d telegram-rss-bot:latest +``` + ## Important Advisory: You should respect the rate limiting of the Telegram API (More info about this: https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this) diff --git a/bot-config.template.json b/bot-config.template.json new file mode 100644 index 0000000..f3cde85 --- /dev/null +++ b/bot-config.template.json @@ -0,0 +1,11 @@ +{ + "telegram_auth_key": "TELEGRAM_AUTH_KEY", + "migrations": "MIGRATIONS", + "telegram_api_debug": TELEGRAM_API_DEBUG, + "db_path": "DB_PATH", + "log_level": "LOG_LEVEL", + "feed_parse_amount": FEED_PARSE_AMOUNT, + "feed_post_amount": FEED_POST_AMOUNT, + "feed_updates_interval": FEED_UPDATES_INTERVAL, + "feed_posts_interval": FEED_POST_INTERVAL +} \ No newline at end of file diff --git a/conf/conf.go b/conf/conf.go index 92d4856..f57fe58 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -17,6 +17,7 @@ func LoadConfig() { viper.SetConfigName("bot-config") viper.AddConfigPath("$HOME/.telegram-rss-bot") viper.AddConfigPath(".") + viper.AddConfigPath("./.telegram-rss-bot") err := viper.ReadInConfig() if err != nil { diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..0544754 --- /dev/null +++ b/init.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -ue + +keys="TELEGRAM_AUTH_KEY MIGRATIONS TELEGRAM_API_DEBUG DB_PATH LOG_LEVEL FEED_PARSE_AMOUNT FEED_POST_AMOUNT FEED_UPDATES_INTERVAL FEED_POST_INTERVAL" + +TELEGRAM_AUTH_KEY=${TELEGRAM_AUTH_KEY:=token} +MIGRATIONS=${MIGRATIONS:=v1} +TELEGRAM_API_DEBUG=${TELEGRAM_API_DEBUG:=false} +DB_PATH=${DB_PATH:=./bot.db} +LOG_LEVEL=${LOG_LEVEL:=info} +FEED_PARSE_AMOUNT=${FEED_PARSE_AMOUNT:=5} +FEED_POST_AMOUNT=${FEED_POST_AMOUNT:=2} +FEED_UPDATES_INTERVAL=${FEED_UPDATES_INTERVAL:=600} +FEED_POST_INTERVAL=${FEED_POST_INTERVAL:=400} + +mkdir -p /code/.telegram-rss-bot +cp ./bot-config.template.json /code/.telegram-rss-bot/bot-config.json + +for key in $keys; do + sed -i "s|$key|$(eval echo "\$${key}")|g" /code/.telegram-rss-bot/bot-config.json +done + +echo Executing $* +$*