-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
840b95e
commit 29bec82
Showing
3 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM python:3.9.12-buster | ||
|
||
RUN adduser user | ||
|
||
WORKDIR /home/flask_app | ||
|
||
############################ | ||
# poetry | ||
ENV POETRY_VERSION=1.1.13 | ||
|
||
RUN pip install "poetry==$POETRY_VERSION" | ||
|
||
COPY poetry.lock pyproject.toml /home/flask_app/ | ||
|
||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --no-interaction --no-ansi | ||
############################ | ||
# project files | ||
|
||
COPY app app | ||
COPY migrations migrations | ||
COPY flask_app.py config.py boot.sh ./ | ||
RUN chmod +x boot.sh | ||
|
||
ENV FLASK_APP flask_app.py | ||
|
||
RUN chown -R user:user ./ | ||
|
||
############################ | ||
|
||
USER user | ||
|
||
EXPOSE 5000 | ||
|
||
CMD [ "./boot.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# О проекте | ||
### Заметки | ||
- Используется самореферентные отношения (self-referential relationship) «многие ко многим» для отслеживания подписчиков. | ||
- `flask-moment` (Moment.js) - для решения задачи отображения даты и времени в нужной time zone для пользователя на клиенте | ||
|
@@ -8,5 +9,48 @@ | |
Весь код, который взаимодействует с индексом Elasticsearch в модуле app/search.py. | ||
Идея состоит в том, чтобы сохранить весь код Elasticsearch в этом модуле. Остальная часть приложения будет использовать функции в этом новом модуле для доступа к индексу и не будет иметь прямого доступа к Elasticsearch. Это важно, потому что если однажды я решу, что мне больше не нравится Elasticsearch и соберусь переключиться на другой движок, все, что мне нужно сделать, это перезаписать функции в этом одном модуле, и приложение будет продолжать работать по-прежнему. | ||
|
||
### deployment | ||
- добавить индекс в elasticsearch. Выполнить `Posts.reindex()`. Возможно перед этим потребуется вручную создать индекс `post`. | ||
# Настройка приложения (переменные окружения) | ||
Общие настройки: | ||
``` | ||
SECRET_KEY="" | ||
FLASK_ENV="development" / "production" | ||
APP_SETTINGS="config.DevelopmentConfig" / "config.ProductionConfig" | ||
FLASK_DEBUG= "1" / "0" | ||
``` | ||
|
||
БД: | ||
``` | ||
DATABASE_URL="postgresql://localhost/flask_app" | ||
``` | ||
|
||
Для получения сообщений о сбоях на email: | ||
``` | ||
MAIL_SERVER="smtp.googlemail.com" | ||
MAIL_PORT="587" | ||
MAIL_USE_TLS="1" | ||
MAIL_USERNAME="[email protected]" | ||
MAIL_PASSWORD="pass" | ||
``` | ||
|
||
Elasticsearch | ||
``` | ||
ELASTICSEARCH_URL=http://localhost:9200 | ||
``` | ||
|
||
# deployment | ||
- добавить индекс в elasticsearch. Выполнить `Posts.reindex()`. Возможно перед этим потребуется вручную создать индекс `post`. | ||
|
||
## Docker | ||
Развертывание контейнера: | ||
``` | ||
# Создание образа | ||
docker build -t flask_app:latest . | ||
# Создание и запук контейнера | ||
# --name <name> создать контейнер с именем | ||
# -d фоновый режим | ||
# -p проброс порта | ||
# -e <VAR_NAME>=<VAR_VALUE> задать переменную окружения | ||
# название образа | ||
docker run --name flask_app_container -d -p 8000:5000 -e SECRET_KEY="1234" -e APP_SETTINGS="config.DevelopmentConfig" -e FLASK_DEBUG="1" -e flask_app:latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
# this script is used to boot a Docker container | ||
|
||
while true; do | ||
flask db upgrade | ||
if [[ "$?" == "0" ]]; then | ||
break | ||
fi | ||
echo Deploy command failed, retrying in 5 secs... | ||
sleep 5 | ||
done | ||
exec gunicorn -b :5000 --access-logfile - --error-logfile - flask_app:app |