diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3893c93 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +# Python +.venv +__pycache__ + +# GIT +.gitignore + +#CI configuration +.drone.yml +pylama.ini + +# Bot documentation +README.md + +# Environment +.env +.env.dist diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..6f0acb7 --- /dev/null +++ b/.env.dist @@ -0,0 +1,8 @@ +RSSBOT_TG_TOKEN=1234567890:yourbotstoken + +# Optional variables +# RSSBOT_DSN=xxx +# POSTGRES_USER=xxx +# POSTGRES_PASSWORD=xxx +# POSTGRES_DB=xxx +# LOG_LEVEL=INFO \ No newline at end of file diff --git a/.gitignore b/.gitignore index 040e37d..a026304 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ /.venv /__pycache__ -# Database -/*.db \ No newline at end of file +# Environment +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8a77a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.10-alpine + +WORKDIR /bot + +COPY . . + +RUN pip install -r requirements.txt + +ENV PYTHONUNBUFFERED=1 + +# App settings +# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING +ENV RSSBOT_DSN=postgres://username:password@hostname/database_name +# https://core.telegram.org/bots#6-botfather +ENV RSSBOT_TG_TOKEN=1234567890:yourbotstoken +# https://docs.python.org/3/howto/logging.html#logging-levels +ENV LOG_LEVEL=INFO + +ENTRYPOINT [ "python" ] + +CMD [ "bot.py" ] \ No newline at end of file diff --git a/README.md b/README.md index 64300b7..8825a38 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,43 @@ python bot.py export RSSBOT_TG_TOKEN=xxx export RSSBOT_DSN=xxx python update.py -``` \ No newline at end of file +``` + +## Running prebuild Docker Image + +### Running the bot +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx miroslavskaya/tg_rss_bot bot.py +``` + +### Running update +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx miroslavskaya/tg_rss_bot update.py +``` +## Building and running Docker image from source + +```shell +docker build . -t tg_rss_bot +``` + +### Running the bot +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx tg_rss_bot bot.py +``` + +### Running update +```shell +docker run -e RSSBOT_DSN=yyy RSSBOT_TG_TOKEN=xxx tg_rss_bot update.py +``` + +## Using Docker Compose + +### Running the bot +```shell +docker-compose up +``` + +### Running the update +```shell +docker-compose run app update.py +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2f8241d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.7' + +services: + app: + build: . + image: miroslavsckaya/tg_rss_bot + environment: + # DSN schema: postgres://username:password@hostname/database_name + # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING + - "RSSBOT_DSN=postgres://${BOT_DB_USER:-bot}:${BOT_DB_PASSWORD:-dev}@${BOT_DB_HOST:-db}/${BOT_DB_NAME:-bot}" + # https://core.telegram.org/bots#6-botfather + - "RSSBOT_TG_TOKEN=${RSSBOT_TG_TOKEN}" + # https://docs.python.org/3/howto/logging.html#logging-levels + - "LOG_LEVEL=${LOG_LEVEL:-INFO}" + depends_on: + - postgres + restart: unless-stopped + + db: + image: postgres:14-alpine + environment: + # Postgres settings + # https://hub.docker.com/_/postgres + - "POSTGRES_USER=${BOT_DB_USER:-bot}" + - "POSTGRES_PASSWORD=${BOT_DB_PASSWORD:-dev}" + - "POSTGRES_DB=${BOT_DB_NAME:-bot}" + volumes: + - db-data:/var/lib/postgresql/data + restart: unless-stopped + +volumes: + db-data: