From 4543684c4890f062d3f1b29a2d2b146ae137935c Mon Sep 17 00:00:00 2001 From: Patrick Valsecchi Date: Thu, 17 Aug 2017 12:08:02 +0200 Subject: [PATCH] Make the GIT tag optional for the versions.json service Since the commits are usually tagged after the images are built (and tested), the git_tag field was usually off. Better remove it in that case. --- Makefile | 3 +-- README.md | 2 +- acceptance_tests/app/Dockerfile | 3 +-- c2cwsgiutils/version.py | 5 ++++- c2cwsgiutils_genversion.py | 11 ++++++++--- setup.py | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index b56cd1cbb..363ccaca7 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,6 @@ else DOCKER_COMPOSE_VERSION := $(DOCKER_COMPOSE_VERSION_ACTUAL) endif -GIT_TAG := $(shell git describe --tags --first-parent 2>/dev/null || echo "none") GIT_HASH := $(shell git rev-parse HEAD) THIS_MAKEFILE_PATH := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) THIS_DIR := $(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) @@ -67,7 +66,7 @@ build_acceptance: build_docker .PHONY: build_test_app build_test_app: build_docker - docker build -t $(DOCKER_BASE)_test_app:$(DOCKER_TAG) --build-arg "GIT_TAG=$(GIT_TAG)" --build-arg "GIT_HASH=$(GIT_HASH)" acceptance_tests/app + docker build -t $(DOCKER_BASE)_test_app:$(DOCKER_TAG) --build-arg "GIT_HASH=$(GIT_HASH)" acceptance_tests/app .venv/timestamp: requirements.txt Makefile /usr/bin/virtualenv --python=/usr/bin/python3.5 .venv diff --git a/README.md b/README.md index 3ea31bcf2..5c7863e66 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ Version information ------------------- If the `/app/versions.json` exists, a view is added (`{C2C_BASE_PATH}/version.json`) to query the current -version of a app. This file is generated by calling the `c2cwsgiutils_genversion.py $GIT_TAG $GIT_HASH` +version of a app. This file is generated by calling the `c2cwsgiutils_genversion.py [$GIT_TAG] $GIT_HASH` command line. Usually done in the [Dockerfile](acceptance_tests/app/Dockerfile) of the WSGI application. diff --git a/acceptance_tests/app/Dockerfile b/acceptance_tests/app/Dockerfile index e8f05ef21..29388a7bc 100644 --- a/acceptance_tests/app/Dockerfile +++ b/acceptance_tests/app/Dockerfile @@ -15,11 +15,10 @@ ENV SQLALCHEMY_URL=postgresql://www-data:www-data@db:5432/test \ # Step #2 copy the rest of the files (watch for the .dockerignore) COPY . /app -ARG GIT_TAG ARG GIT_HASH RUN python ./setup.py install && \ ./models_graph.py > models.dot && \ ./models_graph.py Hello > models_hello.dot && \ - c2cwsgiutils_genversion.py $GIT_TAG $GIT_HASH && \ + c2cwsgiutils_genversion.py $GIT_HASH && \ flake8 c2cwsgiutils_app app_alembic diff --git a/c2cwsgiutils/version.py b/c2cwsgiutils/version.py index de2c9b35d..4887360bd 100644 --- a/c2cwsgiutils/version.py +++ b/c2cwsgiutils/version.py @@ -16,4 +16,7 @@ def init(config): request_method="GET") config.add_view(lambda request: versions, route_name="c2c_versions", renderer="json", http_cache=0) LOG.info("Installed the /versions.json service") - LOG.warning("Starting version %s (%s)", versions['main']['git_tag'], versions['main']['git_hash']) + if 'git_tag' in versions['main']: + LOG.warning("Starting version %s (%s)", versions['main']['git_tag'], versions['main']['git_hash']) + else: + LOG.warning("Starting version %s", versions['main']['git_hash']) diff --git a/c2cwsgiutils_genversion.py b/c2cwsgiutils_genversion.py index 126dd01e7..a2aa6c196 100755 --- a/c2cwsgiutils_genversion.py +++ b/c2cwsgiutils_genversion.py @@ -37,15 +37,20 @@ def _get_packages_version(): def main(): - git_tag = sys.argv[1] - git_hash = sys.argv[2] + if len(sys.argv) == 2: + git_tag = None + git_hash = sys.argv[1] + else: + git_tag = sys.argv[1] + git_hash = sys.argv[2] report = { 'main': { "git_hash": git_hash, - "git_tag": git_tag }, 'packages': _get_packages_version() } + if git_tag is not None: + report['main']['git_tag'] = git_tag with open('versions.json', 'w') as file: json.dump(report, file, indent=2) diff --git a/setup.py b/setup.py index 83969d823..36bc54a30 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION = '0.19.3' +VERSION = '0.20.0' HERE = os.path.abspath(os.path.dirname(__file__)) INSTALL_REQUIRES = open(os.path.join(HERE, 'requirements.txt')).read().splitlines()