Skip to content

Conversation

@t33nsy
Copy link
Collaborator

@t33nsy t33nsy commented Oct 10, 2025

Реализован подсчет хэша всех static-файлов на запуске в Dockerfile, сохранение значения в классе VersionCache, а также функция versioned_url, заменяющая url_for('static',...) и приписывающая к запросу ?v=$hash

Dockerfile Outdated
RUN STATIC_HASH=$(find app/static -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1) && \
echo $STATIC_HASH >> /APP_STATIC_HASH

ENV APP_STATIC_HASH_FILE=/APP_STATIC_HASH No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, особого смысла держать файл с хэшем нет (т.к. это строка небольшой длины) - хэш можно записать в ENV переменную (возможно, даже не на сборке, а на запуске приложения?), и получить его в приложении

app/config.py Outdated
config_raw.read(config_path)
Config.c = DictToObject(config_raw._sections)

class VersionCache:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, данная логика и класс всё-таки лишние - достаточно добавить версию в app.config (конфигурация Flask- приложения) и брать её оттуда

from app.api.trainings import api_trainings
from app.api.version import api_version
from app.config import Config
from app.config import Config, VersionCache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VersionCache здесь нигде не используется

app/utils.py Outdated

def versioned_url(filename):
v = VersionCache().get_version()
return url_for('static', filename=filename) + f'?v={v}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейчас url с версией выглядит как ?v=[%27d41d8cd98f00b204e9800998ecf8427e%27] - результат self.version=f.read().split() - вероятно, вы хотели там strip (убрать пробелы)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants