You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
3 years ago
|
#+title: Справка
|
||
|
#+date: [2022-03-19 сб 17:11]
|
||
|
|
||
|
* Сборка Docker контейнера
|
||
|
#+name: Dockerfile
|
||
|
#+begin_src sh
|
||
|
FROM python:3.9-slim-buster
|
||
|
WORKDIR /project
|
||
|
|
||
|
ENV TELEGRAM_API_TOKEN=""
|
||
|
ENV GBOT_DELAY_TIME=1
|
||
|
ENV GBOT_DELAY_TIME_Q=180
|
||
|
ENV GBOT_CHAT_ID=""
|
||
|
ENV GBOT_DB_PATH="/project/data/support.db"
|
||
|
|
||
|
# без проброса времени бот счиатет что он в GMT+0
|
||
|
ENV TZ=Europe/Moscow
|
||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||
|
|
||
|
#RUN useradd -m -r user && \
|
||
|
# chown user /project
|
||
|
#USER user
|
||
|
COPY requirements.txt ./
|
||
|
RUN pip install -r requirements.txt
|
||
|
|
||
|
#USER user
|
||
|
|
||
|
COPY . .
|
||
|
ENTRYPOINT ["python", "main.py"]
|
||
|
#+end_src
|
||
|
|
||
|
После этого в папке с проектом:
|
||
|
- собираем бота src_sh{docker build -t gorgorod-bot .},
|
||
|
- пробуем запустить src_sh{docker run -it --rm --name gorgorod-tg --mount source=gorgorod_data,target=/project/data gorgorod-bot}
|
||
|
|
||
|
* Systemd сервис
|
||
|
Сам вайл `docker.gorgorod-bot.service`:
|
||
|
|
||
|
#+begin_src sh
|
||
|
#/etc/systemd/system/docker.gorgorod-bot.service
|
||
|
[Unit]
|
||
|
Description=Gorgorod bot
|
||
|
After=docker.service
|
||
|
Requires=docker.service
|
||
|
|
||
|
[Service]
|
||
|
TimeoutStartSec=0
|
||
|
Restart=always
|
||
|
WorkingDirectory=/home/redmaycry/gorgorod-bot
|
||
|
ExecStartPre=-/usr/bin/docker container stop gorgorod-tg
|
||
|
ExecStartPre=-/usr/bin/docker rm gorgorod-tg
|
||
|
ExecStart=/usr/bin/docker run --rm --name gorgorod-tg --mount source=gorgorod_data,target=/project/data gorgorod-bot
|
||
|
ExecStop=/usr/bin/docker container stop gorgorod-tg
|
||
|
|
||
|
[Install]
|
||
|
WantedBy=multi-user.target
|
||
|
#+end_src
|
||
|
|
||
|
После этого:
|
||
|
- перезагружаем список демонов src_sh{systemctl daemon-reload},
|
||
|
- включаем наш новый демон в автозагрузку src_sh{systemctl enable docker.gorgorod-bot.service},
|
||
|
- запускаем сервис src_sh{systemctl start docker.gorgorod-bot.service}
|