version_app
This commit is contained in:
44
app.py
44
app.py
@@ -25,25 +25,35 @@ except ImportError:
|
|||||||
from backports.zoneinfo import ZoneInfo
|
from backports.zoneinfo import ZoneInfo
|
||||||
|
|
||||||
|
|
||||||
def build_fingerprint(paths):
|
def read_commit_and_date(filename="version.txt", root_path=None):
|
||||||
h = hashlib.sha256()
|
base = root_path or os.path.dirname(os.path.abspath(__file__))
|
||||||
for base in paths:
|
path = os.path.join(base, filename)
|
||||||
if not os.path.exists(base):
|
if not os.path.exists(path):
|
||||||
continue
|
return None, None
|
||||||
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:
|
|
||||||
continue
|
|
||||||
return h.hexdigest()[:8]
|
|
||||||
|
|
||||||
APP_VERSION = f"{datetime.now():%Y.%m.%d}+{build_fingerprint(['templates','static','app.py'])}"
|
try:
|
||||||
|
commit = open(path, "r", encoding="utf-8").read().strip()
|
||||||
|
if commit:
|
||||||
|
commit = commit[:12]
|
||||||
|
except Exception:
|
||||||
|
commit = None
|
||||||
|
|
||||||
app = Flask(__name__)
|
try:
|
||||||
app.config['APP_VERSION'] = APP_VERSION
|
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
|
||||||
|
|
||||||
# Ładujemy konfigurację z pliku config.py
|
# Ładujemy konfigurację z pliku config.py
|
||||||
app.config.from_object("config.Config")
|
app.config.from_object("config.Config")
|
||||||
|
@@ -23,7 +23,6 @@ if ! docker compose version >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$REPO_DIR/$COMPOSE_FILE" ]]; then
|
if [[ ! -f "$REPO_DIR/$COMPOSE_FILE" ]]; then
|
||||||
# Spróbuj alternatywnej nazwy
|
|
||||||
if [[ -f "$REPO_DIR/compose.yaml" ]]; then
|
if [[ -f "$REPO_DIR/compose.yaml" ]]; then
|
||||||
COMPOSE_FILE="compose.yaml"
|
COMPOSE_FILE="compose.yaml"
|
||||||
else
|
else
|
||||||
@@ -41,6 +40,10 @@ git fetch --prune "$GIT_REMOTE"
|
|||||||
git checkout "$GIT_BRANCH" >/dev/null 2>&1 || true
|
git checkout "$GIT_BRANCH" >/dev/null 2>&1 || true
|
||||||
git pull --ff-only "$GIT_REMOTE" "$GIT_BRANCH"
|
git pull --ff-only "$GIT_REMOTE" "$GIT_BRANCH"
|
||||||
|
|
||||||
|
# --- Zapisanie wersji do pliku ---
|
||||||
|
log "Zapisywanie hasha commita do version.txt"
|
||||||
|
git rev-parse --short HEAD > version.txt
|
||||||
|
|
||||||
# --- Zatrzymanie i usunięcie bieżącego stacka ---
|
# --- Zatrzymanie i usunięcie bieżącego stacka ---
|
||||||
log "Docker Compose DOWN (usuwanie kontenerów i osieroconych usług)"
|
log "Docker Compose DOWN (usuwanie kontenerów i osieroconych usług)"
|
||||||
docker compose -f "$COMPOSE_FILE" down --remove-orphans
|
docker compose -f "$COMPOSE_FILE" down --remove-orphans
|
||||||
@@ -53,4 +56,4 @@ else
|
|||||||
docker compose -f "$COMPOSE_FILE" up -d --no-deps --build
|
docker compose -f "$COMPOSE_FILE" up -d --no-deps --build
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Gotowe ✅"
|
log "Gotowe ✅ (wersja: $(cat version.txt))"
|
||||||
|
Reference in New Issue
Block a user