Added version metadata into container

This commit is contained in:
simonmicro 2022-12-11 22:48:04 +01:00
parent d795f5265b
commit 818520730c
No known key found for this signature in database
GPG key ID: 033A4D4CE4E063D6
4 changed files with 23 additions and 5 deletions

View file

@ -1,6 +1,9 @@
# Switch to the target image # Switch to the target image
FROM alpine:3.15 FROM alpine:3.15
ARG BUILD_COMMIT=unknown
ARG BUILD_BRANCH=unknown
ENV IP :: ENV IP ::
ENV PORT 1688 ENV PORT 1688
ENV EPID "" ENV EPID ""
@ -35,7 +38,10 @@ RUN apk add --no-cache --update \
COPY py-kms /home/py-kms/ COPY py-kms /home/py-kms/
COPY docker/entrypoint.py /usr/bin/entrypoint.py COPY docker/entrypoint.py /usr/bin/entrypoint.py
COPY docker/start.py /usr/bin/start.py COPY docker/start.py /usr/bin/start.py
# Web-interface specifics
COPY LICENSE /LICENSE COPY LICENSE /LICENSE
RUN echo "$BUILD_COMMIT" > /VERSION && echo "$BUILD_BRANCH" >> /VERSION
RUN chmod 755 /usr/bin/entrypoint.py RUN chmod 755 /usr/bin/entrypoint.py

View file

@ -60,6 +60,7 @@ def start_kms():
pykms_webui_env['PYKMS_SQLITE_DB_PATH'] = db_path pykms_webui_env['PYKMS_SQLITE_DB_PATH'] = db_path
pykms_webui_env['PORT'] = '8080' pykms_webui_env['PORT'] = '8080'
pykms_webui_env['PYKMS_LICENSE_PATH'] = '/LICENSE' pykms_webui_env['PYKMS_LICENSE_PATH'] = '/LICENSE'
pykms_webui_env['PYKMS_VERSION_PATH'] = '/VERSION'
pykms_webui_process = subprocess.Popen(['gunicorn', '--log-level', os.environ.get('LOGLEVEL'), 'pykms_WebUI:app'], env=pykms_webui_env) pykms_webui_process = subprocess.Popen(['gunicorn', '--log-level', os.environ.get('LOGLEVEL'), 'pykms_WebUI:app'], env=pykms_webui_env)
except Exception as e: except Exception as e:
loggersrv.error("Failed to start webui: %s" % e) loggersrv.error("Failed to start webui: %s" % e)

View file

@ -3,17 +3,16 @@ from flask import Flask, render_template
from pykms_Sql import sql_get_all from pykms_Sql import sql_get_all
from pykms_DB2Dict import kmsDB2Dict from pykms_DB2Dict import kmsDB2Dict
serve_count = 0
def _random_uuid(): def _random_uuid():
return str(uuid.uuid4()).replace('-', '_') return str(uuid.uuid4()).replace('-', '_')
_serve_count = 0
def _increase_serve_count(): def _increase_serve_count():
global serve_count global _serve_count
serve_count += 1 _serve_count += 1
def _get_serve_count(): def _get_serve_count():
return serve_count return _serve_count
_kms_items = None _kms_items = None
_kms_items_ignored = None _kms_items_ignored = None
@ -48,6 +47,15 @@ app = Flask('pykms_webui')
app.jinja_env.globals['start_time'] = datetime.datetime.now() app.jinja_env.globals['start_time'] = datetime.datetime.now()
app.jinja_env.globals['get_serve_count'] = _get_serve_count app.jinja_env.globals['get_serve_count'] = _get_serve_count
app.jinja_env.globals['random_uuid'] = _random_uuid app.jinja_env.globals['random_uuid'] = _random_uuid
app.jinja_env.globals['version_info'] = None
_version_info_path = os.environ.get('PYKMS_VERSION_PATH', '../VERSION')
if os.path.exists(_version_info_path):
with open(_version_info_path, 'r') as f:
app.jinja_env.globals['version_info'] = {
'hash': f.readline(),
'branch': f.readline()
}
@app.route('/') @app.route('/')
def root(): def root():

View file

@ -40,6 +40,9 @@
<p> <p>
<strong>py-kms</strong> is online since <span class="convert_timestamp">{{ start_time }}</span>. <strong>py-kms</strong> is online since <span class="convert_timestamp">{{ start_time }}</span>.
This instance was accessed {{ get_serve_count() }} times. View this softwares license <a href="/license">here</a>. This instance was accessed {{ get_serve_count() }} times. View this softwares license <a href="/license">here</a>.
{% if version_info %}
<br>This instance is running version "{{ version_info['hash'] }}" from branch "{{ version_info['branch'] }}" of py-kms.
{% endif %}
</p> </p>
</div> </div>
</footer> </footer>