Skip to content

Commit

Permalink
Add META_SOURCE, rename version.py to meta.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TheReverend403 committed Feb 28, 2024
1 parent 2a58519 commit 24d2a1f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ jobs:
build-args: |
META_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
META_VERSION_HASH=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
META_SOURCE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.source'] }}
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} as python-base

ARG META_VERSION
ARG META_VERSION_HASH
ARG META_SOURCE

ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
Expand All @@ -22,7 +23,8 @@ ENV PYTHONUNBUFFERED=1 \
POETRY_VERSION="" \
VIRTUAL_ENV="/venv" \
META_VERSION="${META_VERSION}" \
META_VERSION_HASH="${META_VERSION_HASH}"
META_VERSION_HASH="${META_VERSION_HASH}" \
META_SOURCE="${META_SOURCE}"

ENV PATH="${POETRY_HOME}/bin:${VIRTUAL_ENV}/bin:${PATH}" \
PYTHONPATH="/app:${PYTHONPATH}"
Expand Down
17 changes: 11 additions & 6 deletions pste/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# along with pste. If not, see <https://www.gnu.org/licenses/>.

import shutil
from datetime import timedelta

import sentry_sdk
from flask import Flask
Expand All @@ -23,7 +22,7 @@
from webassets import Bundle
from werkzeug.middleware.proxy_fix import ProxyFix

from pste import paths, version
from pste import meta, paths
from pste.extensions import assets, csrf, db, dynaconf, login, session


Expand All @@ -34,7 +33,7 @@ def create_app():
template_folder=str(paths.TEMPLATES),
)

app.logger.info(f"Starting {app.name} {version.VERSION}")
app.logger.info(f"Starting {app.name} {meta.VERSION}")

for path in [paths.STATIC, paths.DATA]:
path.mkdir(exist_ok=True, parents=True)
Expand All @@ -43,6 +42,7 @@ def create_app():
register_extensions(app)
register_commands(app)
register_blueprints(app)
inject_template_context(app)

with app.app_context():
register_assets(app)
Expand Down Expand Up @@ -72,7 +72,7 @@ def init_sentry(app):
app.logger.info("Sentry enabled.")
sentry_sdk.init(
dsn=dsn,
release=version.VERSION,
release=meta.VERSION,
integrations=[FlaskIntegration(), SqlalchemyIntegration()],
)
else:
Expand All @@ -82,12 +82,11 @@ def init_sentry(app):
def load_configuration(app):
dynaconf.init_app(app)
app.config.update(
PSTE_VERSION=version.VERSION,
PSTE_VERSION=meta.VERSION,
DEBUG_TB_INTERCEPT_REDIRECTS=False,
SESSION_TYPE="sqlalchemy",
SESSION_SQLALCHEMY=db,
SESSION_USE_SIGNER=True,
PERMANENT_SESSION_LIFETIME=timedelta(days=7).total_seconds(),
SESSION_COOKIE_SECURE=not (app.debug or app.testing),
SQLALCHEMY_RECORD_QUERIES=app.debug, # for debugbar
)
Expand Down Expand Up @@ -169,3 +168,9 @@ def register_assets(app):
)

app.logger.debug("Assets registered.")


def inject_template_context(app):
@app.context_processor
def inject_meta():
return {"meta": meta}
2 changes: 2 additions & 0 deletions pste/version.py → pste/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@

if _META_VERSION and _META_HASH:
VERSION = f"{_META_VERSION} ({_META_HASH[:8]})"

SOURCE: str = os.getenv("META_SOURCE") or "https://github.com/TheReverend403/pste"
4 changes: 2 additions & 2 deletions pste/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<div class="text-muted">
<div class="d-flex justify-content-between mb-3">
<div class="p-2">
<a href="https://github.com/TheReverend403/pste" class="text-muted"
target="_blank">pste {{ config.PSTE_VERSION }}</a>
<a href="{{ meta.SOURCE }}" class="text-muted"
target="_blank">pste {{ meta.VERSION }}</a>
</div>
{% if current_user.is_authenticated %}
<div class="p-2">
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pste"
version = "0.7.12"
version = "0.7.13"
description = "Just a simple file hosting application inspired by the likes of pomf.se and teknik.io."
authors = ["Lee Watson <[email protected]>"]
license = "GPL-3.0+"
Expand Down

0 comments on commit 24d2a1f

Please sign in to comment.