Refactored and fix docker deploy

This commit is contained in:
Ilya Bezrukov 2024-07-30 18:02:46 +03:00
parent c309d4975e
commit b3a1ea1309
4 changed files with 31 additions and 12 deletions

1
.gitignore vendored
View File

@ -3,5 +3,6 @@ __pycache__/
venv/ venv/
.venv/ .venv/
logs/ logs/
data/
*.env *.env
*.db *.db

View File

@ -19,20 +19,21 @@ RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=requirements.txt,target=requirements.txt \ --mount=type=bind,source=requirements.txt,target=requirements.txt \
pip install -r requirements.txt pip install -r requirements.txt
# copy i18n files # copy sources
COPY --chown=bot i18n.yaml /i18n/i18n.yaml COPY --chown=bot --chmod=774 docker-entrypoint.sh /app/
COPY --chown=bot migrations /app/migrations
COPY --chown=bot mybot /app/mybot
COPY --chown=bot i18n.yaml /app/
# copy default configs # prepare environment
WORKDIR /app ENV I18N_PATH=/data/i18n.yaml
COPY --chown=bot mybot mybot ENV DB_URL=sqlite:////data/bot.db
# preapre environment RUN mkdir -p /data
ENV SS_TYPE=memory RUN chown bot:bot /data
ENV I18N_PATH=/i18n/i18n.yaml VOLUME /data
# set user
USER bot USER bot
WORKDIR /app
CMD ["python3", "-m", "mybot"] ENTRYPOINT ["./docker-entrypoint.sh"]
VOLUME i18n/

17
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/sh
if [ ! -f /i18n/i18n.yaml ]; then
cp i18n.yaml ${I18N_PATH}
fi
alembic -c migrations/alembic.ini upgrade head
if [ $# -eq 0 ]; then
if [ -z "${USE_WEBHOOK}" ]; then
exec python3 -m mybot
else
exec gunicorn -b 0.0.0.0:8080 "mybot:main()"
fi
else
exec $1
fi