Skip to content

Commit

Permalink
Adding docker support (#4)
Browse files Browse the repository at this point in the history
* Added docker support
* Documenting docker usage
* Add docker hub option to README

Co-authored-by: Richard Szolár <[email protected]>
  • Loading branch information
slaterx and 0x111 committed Jun 13, 2020
1 parent a394911 commit 1c79e1a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

bot-config.json
bot-config.json
.idea
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions bot-config.template.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -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 $*
$*

0 comments on commit 1c79e1a

Please sign in to comment.