diff --git a/.gitignore b/.gitignore index 444de15..3833118 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ __pycache__/ venv/ .venv/ logs/ +data/ *.env *.db diff --git a/Dockerfile b/Dockerfile index daa2d29..68b15d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,20 +19,21 @@ RUN --mount=type=cache,target=/root/.cache/pip \ --mount=type=bind,source=requirements.txt,target=requirements.txt \ pip install -r requirements.txt -# copy i18n files -COPY --chown=bot i18n.yaml /i18n/i18n.yaml +# copy sources +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 -WORKDIR /app -COPY --chown=bot mybot mybot +# prepare environment +ENV I18N_PATH=/data/i18n.yaml +ENV DB_URL=sqlite:////data/bot.db -# preapre environment -ENV SS_TYPE=memory -ENV I18N_PATH=/i18n/i18n.yaml +RUN mkdir -p /data +RUN chown bot:bot /data +VOLUME /data -# set user USER bot +WORKDIR /app -CMD ["python3", "-m", "mybot"] - -VOLUME i18n/ +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..5f89639 --- /dev/null +++ b/docker-entrypoint.sh @@ -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 diff --git a/alembic.ini b/migrations/alembic.ini similarity index 100% rename from alembic.ini rename to migrations/alembic.ini