kopia lustrzana https://github.com/J-Rios/TLG_JoinCaptchaBot
Add docker support & documentation.
rodzic
ccef7a9c7c
commit
f8bad849fa
|
@ -47,6 +47,12 @@ To ease usage, a run, status and kill scripts has been provided.
|
|||
./kill
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
You can also run the bot on [Docker](docker.io). This allows easy server
|
||||
migration and automates the download of all dependencies. Look at the
|
||||
[docker specific documentation](docker/README.md) for more details.
|
||||
|
||||
### Languages Contributors:
|
||||
|
||||
- Portuguese (Brazil): Anahuac de Paula Gil
|
||||
|
@ -54,5 +60,3 @@ To ease usage, a run, status and kill scripts has been provided.
|
|||
- Catalán: Adela Casals i Jorba
|
||||
|
||||
- Chinese (Mainland): [神林](https://github.com/jyxjjj)
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
FROM debian:buster
|
||||
|
||||
MAINTAINER Marco Paganini <paganini@paganini.net>
|
||||
|
||||
ARG BOT_PROJECT="captcha-bot"
|
||||
ARG BOT_USER="captcha-bot"
|
||||
ARG BOT_HOME_DIR="/home/${BOT_USER}"
|
||||
ARG GITHUB_URL="https://github.com/J-Rios/TLG_JoinCaptchaBot"
|
||||
|
||||
# Change this to an user_id that does not own anything on the host.
|
||||
ARG UID=62999
|
||||
|
||||
# This represents an invalid token and should always exist in
|
||||
# the "stock" constants.py file.
|
||||
ARG INVALID_TOKEN="XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
|
||||
# Use the BOT_TOKEN argument to override your token. We don't use environment
|
||||
# here, since there's no need to have the token available to the container as
|
||||
# an environment variable.
|
||||
ARG BOT_TOKEN
|
||||
|
||||
# Default language (override when building -- must be all CAPS.)
|
||||
ARG BOT_LANG="EN"
|
||||
|
||||
# OS and base environment layer.
|
||||
RUN groupadd --gid ${UID} ${BOT_USER} && \
|
||||
useradd --uid ${UID} --gid ${UID} --shell /bin/bash --home-dir ${BOT_HOME_DIR} ${BOT_USER} && \
|
||||
apt-get update && \
|
||||
apt-get install --yes bash coreutils git procps python3 python3-pip && \
|
||||
apt-get install --yes libtiff5-dev libjpeg62-turbo-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
|
||||
|
||||
# TLG captcha bot layer.
|
||||
RUN mkdir -p "${BOT_HOME_DIR}" && \
|
||||
cd "${BOT_HOME_DIR}" && \
|
||||
git clone --recurse-submodules "${GITHUB_URL}" && \
|
||||
# In Debian, installing the telegram library in the requirements.txt file
|
||||
# causes imports to fail.
|
||||
pip3 install python_telegram_bot==11.1.0 && \
|
||||
pip3 install Pillow==6.0.0 && \
|
||||
cd TLG_JoinCaptchaBot/sources && \
|
||||
sed -i -e "s/${INVALID_TOKEN}/${BOT_TOKEN}/g" constants.py && \
|
||||
sed -i -e "s/^\(\s\+'INIT_LANG'\)[^:]*:.*/\1 : '${BOT_LANG}',/g" constants.py && \
|
||||
chown -R "${BOT_USER}":"${BOT_USER}" "${BOT_HOME_DIR}" && \
|
||||
echo "rm -f ./data/captchas/*; python3 -u join_captcha_bot.py" >run_in_docker && \
|
||||
chmod 755 kill run run_in_docker status && \
|
||||
cd ..
|
||||
|
||||
|
||||
CMD ["/bin/su", "-", "captcha-bot", "-c", "bash -c 'cd /home/captcha-bot/TLG_JoinCaptchaBot/sources && ./run_in_docker'"]
|
|
@ -0,0 +1,14 @@
|
|||
NAME=captcha-bot
|
||||
BOT_LANG ?= "EN"
|
||||
|
||||
ifndef BOT_TOKEN
|
||||
$(error BOT_TOKEN is not set. Use make -e BOT_TOKEN=<your_bot_token>.)
|
||||
endif
|
||||
|
||||
build:
|
||||
docker build -t "${NAME}" --build-arg BOT_TOKEN="${BOT_TOKEN}" --build-arg BOT_LANG="${BOT_LANG}" .
|
||||
|
||||
force:
|
||||
docker build -t "${NAME}" --no-cache --build-arg BOT_TOKEN="${BOT_TOKEN}" --build-arg BOT_LANG="${BOT_LANG}" .
|
||||
|
||||
.PHONY: build force
|
|
@ -0,0 +1,73 @@
|
|||
# Docker configuration
|
||||
|
||||
This document lists the requirements and steps to run
|
||||
[TLG_JoinCaptchaBot](https://github.com/J-Rios/TLG_JoinCaptchaBot) in a docker
|
||||
container.
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
* [docker](https://www.docker.com/products/docker-engine). If possible, install
|
||||
it using your OS native packaging system (under Debian based systems, use
|
||||
`apt-get install docker-ce`).
|
||||
|
||||
* GNU Make, which should be installed on most Linux distributions by default.
|
||||
|
||||
## Building a new image
|
||||
|
||||
Create a new bot on Telegram using [The BotFather](http://t.me/BotFather). Make
|
||||
sure your bot can be invited to channels and has privacy set to _disabled_.
|
||||
Without this, the bot won't be able to read messages on the channel.
|
||||
|
||||
Save the bot token. The token _should not publicly visible_ as anyone with it
|
||||
could take control of your bot instance. We'll use the token to create the
|
||||
docker image containing the bot (below).
|
||||
|
||||
Create a docker image:
|
||||
|
||||
```
|
||||
make BOT_TOKEN="<your_bot_token_here>"
|
||||
```
|
||||
|
||||
It is also possible to specify a different default language for the bot to use
|
||||
by setting the `BOT_LANG` variable at build time, like:
|
||||
|
||||
```
|
||||
make BOT_TOKEN="<your_bot_token_here> BOT_LANG="PT_BR"
|
||||
```
|
||||
|
||||
The build process may take a while, depending on your computer and connection
|
||||
speeds. Docker will indicate a successful build at the end of the process with
|
||||
something like:
|
||||
|
||||
```
|
||||
Successfully built (number)
|
||||
Successfully tagged captcha-bot:latest
|
||||
```
|
||||
|
||||
**Note on token security**: A little bit of paranoia never hurts! Once your
|
||||
container has been built, remove the lines from your bash history containing
|
||||
your token. This can be accomplished with the `history -d` command on
|
||||
individual lines. An easier (but coarser) approach is to run `history -c`,
|
||||
followed by `history -r`. This will clear the history buffer and re-read the
|
||||
history from disk.
|
||||
|
||||
## Running
|
||||
|
||||
To run an instance, use:
|
||||
|
||||
```
|
||||
docker run -d --name captcha-bot captcha-bot
|
||||
```
|
||||
|
||||
This will start the container in the background. Use `docker ps` to check if
|
||||
the container is up and running, and `docker logs captcha-bot` to
|
||||
investigate the logs.
|
||||
|
||||
## Stopping the bot
|
||||
|
||||
To stop the bot, use
|
||||
|
||||
```
|
||||
docker stop captcha-bot
|
||||
docker rm captcha-bot
|
||||
```
|
Ładowanie…
Reference in New Issue