From 43bf0040cb88073e104ea52b10e4be2876f7f2f9 Mon Sep 17 00:00:00 2001 From: Henning Jacobs Date: Sat, 14 Jan 2017 17:54:27 +0100 Subject: [PATCH] add version --- Dockerfile | 3 +++ Makefile | 5 +++-- kube_ops_view/__init__.py | 2 ++ kube_ops_view/main.py | 12 +++++++++++- kube_ops_view/templates/index.html | 2 +- setup.py | 14 +++++++++++++- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 486cd84..ee816c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM alpine:3.5 MAINTAINER Henning Jacobs +ARG VERSION=latest + EXPOSE 8080 RUN apk add --no-cache python3 python3-dev gcc musl-dev zlib-dev libffi-dev openssl-dev ca-certificates && \ @@ -16,6 +18,7 @@ COPY requirements.txt / RUN pip3 install -r /requirements.txt COPY kube_ops_view /kube_ops_view +RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" /kube_ops_view/__init__.py WORKDIR / ENTRYPOINT ["/usr/bin/python3", "-m", "kube_ops_view"] diff --git a/Makefile b/Makefile index 8334705..e7b7d75 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ .PHONY: clean test appjs docker push mock IMAGE ?= hjacobs/kube-ops-view -TAG ?= latest +VERSION ?= 2017.0.dev1-$(shell git describe --tags --always --dirty) +TAG ?= $(VERSION) GITHEAD = $(shell git rev-parse --short HEAD) GITURL = $(shell git config --get remote.origin.url) GITSTATU = $(shell git status --porcelain || echo "no changes") @@ -19,7 +20,7 @@ appjs: docker run -it -u $$(id -u) -v $$(pwd):/workdir -w /workdir/app node:7.4-alpine npm run build docker: appjs scm-source.json - docker build -t "$(IMAGE):$(TAG)" . + docker build --build-arg "VERSION=$(VERSION)" -t "$(IMAGE):$(TAG)" . push: docker docker push "$(IMAGE):$(TAG)" diff --git a/kube_ops_view/__init__.py b/kube_ops_view/__init__.py index e69de29..d9f0a38 100644 --- a/kube_ops_view/__init__.py +++ b/kube_ops_view/__init__.py @@ -0,0 +1,2 @@ +# This version is replaced during release process. +__version__ = '2017.0.dev1' diff --git a/kube_ops_view/main.py b/kube_ops_view/main.py index c9ade14..8e5144f 100644 --- a/kube_ops_view/main.py +++ b/kube_ops_view/main.py @@ -15,6 +15,7 @@ import logging import os import signal import time +import kube_ops_view from pathlib import Path from flask import Flask, redirect @@ -80,7 +81,7 @@ def index(): else: logger.error('Could not find JavaScript application bundle app*.js in {}'.format(static_build_path)) flask.abort(503, 'JavaScript application bundle not found (missing build)') - return flask.render_template('index.html', app_js=app_js) + return flask.render_template('index.html', app_js=app_js, version=kube_ops_view.__version__) def event(cluster_ids: set): @@ -198,7 +199,16 @@ def exit_gracefully(signum, frame): gevent.spawn(shutdown) +def print_version(ctx, param, value): + if not value or ctx.resilient_parsing: + return + click.echo('Kubernetes Operational View {}'.format(kube_ops_view.__version__)) + ctx.exit() + + @click.command(context_settings={'help_option_names': ['-h', '--help']}) +@click.option('-V', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, + help='Print the current version number and exit.') @click.option('-p', '--port', type=int, help='HTTP port to listen on (default: 8080)', envvar='SERVER_PORT', default=8080) @click.option('-d', '--debug', is_flag=True, help='Run in debugging mode', envvar='DEBUG') @click.option('-m', '--mock', is_flag=True, help='Mock Kubernetes clusters', envvar='MOCK') diff --git a/kube_ops_view/templates/index.html b/kube_ops_view/templates/index.html index 452a579..fd24f68 100644 --- a/kube_ops_view/templates/index.html +++ b/kube_ops_view/templates/index.html @@ -3,7 +3,7 @@ - Kubernetes Operational View + Kubernetes Operational View {{ version }}