Skip to content

Commit

Permalink
Make the GIT tag optional for the versions.json service
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Patrick Valsecchi committed Aug 17, 2017
1 parent 1fd29b5 commit 4543684
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
3 changes: 1 addition & 2 deletions acceptance_tests/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion c2cwsgiutils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
11 changes: 8 additions & 3 deletions c2cwsgiutils_genversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 4543684

Please sign in to comment.