Skip to content

Commit 1c79e1a

Browse files
slaterx0x111
andauthored
Adding docker support (#4)
* Added docker support * Documenting docker usage * Add docker hub option to README Co-authored-by: Richard Szolár <r@richardszolar.me>
1 parent a394911 commit 1c79e1a

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313

14-
bot-config.json
14+
bot-config.json
15+
.idea

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.14-buster
2+
3+
CMD /bin/init.sh /bin/rss-bot
4+
5+
COPY . /code
6+
7+
WORKDIR /code
8+
9+
RUN go get ./...
10+
11+
RUN make gh_linux_amd64
12+
RUN chmod -R g+rwx /code && cp build/telegram-rss-bot-linux-amd64 /bin/rss-bot && cp init.sh /bin

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ You can put the config file in the current folder on where the binary resides or
4343
- 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)
4444
- 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)
4545

46+
## Docker support
47+
You can also run this application as a docker container.
48+
49+
### Docker hub
50+
51+
You can pull the official docker image
52+
```bash
53+
docker pull ruthless/telegram-rss-bot
54+
```
55+
56+
### Build from source
57+
Execute the following steps:
58+
```
59+
git clone https://github.com/0x111/telegram-rss-bot
60+
docker build -t telegram-rss-bot:latest .
61+
docker run --name telegram-rss-bot -e TELEGRAM_AUTH_KEY="MY-TOKEN" -d telegram-rss-bot:latest
62+
```
63+
4664
## Important
4765
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)
4866

bot-config.template.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"telegram_auth_key": "TELEGRAM_AUTH_KEY",
3+
"migrations": "MIGRATIONS",
4+
"telegram_api_debug": TELEGRAM_API_DEBUG,
5+
"db_path": "DB_PATH",
6+
"log_level": "LOG_LEVEL",
7+
"feed_parse_amount": FEED_PARSE_AMOUNT,
8+
"feed_post_amount": FEED_POST_AMOUNT,
9+
"feed_updates_interval": FEED_UPDATES_INTERVAL,
10+
"feed_posts_interval": FEED_POST_INTERVAL
11+
}

conf/conf.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func LoadConfig() {
1717
viper.SetConfigName("bot-config")
1818
viper.AddConfigPath("$HOME/.telegram-rss-bot")
1919
viper.AddConfigPath(".")
20+
viper.AddConfigPath("./.telegram-rss-bot")
2021
err := viper.ReadInConfig()
2122

2223
if err != nil {

init.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -ue
4+
5+
keys="TELEGRAM_AUTH_KEY MIGRATIONS TELEGRAM_API_DEBUG DB_PATH LOG_LEVEL FEED_PARSE_AMOUNT FEED_POST_AMOUNT FEED_UPDATES_INTERVAL FEED_POST_INTERVAL"
6+
7+
TELEGRAM_AUTH_KEY=${TELEGRAM_AUTH_KEY:=token}
8+
MIGRATIONS=${MIGRATIONS:=v1}
9+
TELEGRAM_API_DEBUG=${TELEGRAM_API_DEBUG:=false}
10+
DB_PATH=${DB_PATH:=./bot.db}
11+
LOG_LEVEL=${LOG_LEVEL:=info}
12+
FEED_PARSE_AMOUNT=${FEED_PARSE_AMOUNT:=5}
13+
FEED_POST_AMOUNT=${FEED_POST_AMOUNT:=2}
14+
FEED_UPDATES_INTERVAL=${FEED_UPDATES_INTERVAL:=600}
15+
FEED_POST_INTERVAL=${FEED_POST_INTERVAL:=400}
16+
17+
mkdir -p /code/.telegram-rss-bot
18+
cp ./bot-config.template.json /code/.telegram-rss-bot/bot-config.json
19+
20+
for key in $keys; do
21+
sed -i "s|$key|$(eval echo "\$${key}")|g" /code/.telegram-rss-bot/bot-config.json
22+
done
23+
24+
echo Executing $*
25+
$*

0 commit comments

Comments
 (0)