version_app

This commit is contained in:
Mateusz Gruszczyński
2025-09-23 12:41:10 +02:00
parent c34aad68f1
commit 939f55d9aa
2 changed files with 36 additions and 20 deletions

45
app.py
View File

@@ -148,23 +148,36 @@ WEBP_SAVE_PARAMS = {
}
def build_fingerprint(paths):
h = hashlib.sha256()
for base in paths:
if not os.path.exists(base):
continue
for root, _, files in os.walk(base):
for f in sorted(files):
p = os.path.join(root, f)
try:
with open(p, "rb") as fh:
h.update(fh.read())
except Exception:
pass
return h.hexdigest()[:8]
def read_commit_and_date(filename="version.txt", root_path=None):
base = root_path or os.path.dirname(os.path.abspath(__file__))
path = os.path.join(base, filename)
if not os.path.exists(path):
return None, None
APP_VERSION = f"{datetime.now():%Y.%m.%d}+{build_fingerprint(['templates','static','app.py'])}"
app.config['APP_VERSION'] = APP_VERSION
try:
commit = open(path, "r", encoding="utf-8").read().strip()
if commit:
commit = commit[:12]
except Exception:
commit = None
try:
ts = os.path.getmtime(path)
date_str = datetime.fromtimestamp(ts).strftime("%Y.%m.%d")
except Exception:
date_str = None
return date_str, commit
deploy_date, commit = read_commit_and_date("version.txt", root_path=os.path.dirname(__file__))
if not deploy_date:
deploy_date = datetime.now().strftime("%Y.%m.%d")
if not commit:
commit = "dev"
APP_VERSION = f"{deploy_date}+{commit}"
app.config["APP_VERSION"] = APP_VERSION
db = SQLAlchemy(app)
socketio = SocketIO(app, async_mode="eventlet")

View File

@@ -4,11 +4,11 @@ set -e
PROFILE=$1
if [[ -z "$PROFILE" ]]; then
echo "Uzycie: $0 {pgsql|mysql|sqlite}"
echo "Użycie: $0 {pgsql|mysql|sqlite}"
exit 1
fi
echo "Zatrzymuje kontenery aplikacji i bazy..."
echo "Zatrzymuję kontenery aplikacji i bazy..."
if [[ "$PROFILE" == "sqlite" ]]; then
docker compose stop
else
@@ -18,11 +18,14 @@ fi
echo "Pobieram najnowszy kod z repozytorium..."
git pull
echo "Buduje i uruchamiam kontenery..."
echo "Zapisuję hash commita do version.txt..."
git rev-parse --short HEAD > version.txt
echo "Buduję i uruchamiam kontenery..."
if [[ "$PROFILE" == "sqlite" ]]; then
docker compose up -d --build
else
DB_ENGINE="$PROFILE" docker compose --profile "$PROFILE" up -d --build
fi
echo "Gotowe!"
echo "Gotowe! Wersja aplikacji: $(cat version.txt)"