-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version information to the applications
- Loading branch information
Patrick Valsecchi
committed
Mar 30, 2017
1 parent
d174b30
commit c371262
Showing
9 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def test_ok(app_connection): | ||
response = app_connection.get_json('versions.json') | ||
assert 'main' in response | ||
assert 'git_hash' in response['main'] | ||
assert 'packages' in response | ||
assert 'pyramid' in response['packages'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import logging | ||
import json | ||
import os | ||
|
||
VERSIONS_PATH = '/app/versions.json' | ||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def init(config): | ||
if os.path.isfile(VERSIONS_PATH): | ||
with open(VERSIONS_PATH) as file: | ||
versions = json.load(file) | ||
config.add_route("c2c_versions", r"/versions.json", 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
import json | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
VERSION_RE = re.compile(r'^(.*)==(.*)$') | ||
|
||
|
||
def _get_git_versions(root): | ||
git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root).strip() | ||
try: | ||
with open(os.devnull, "w") as devnull: | ||
git_tag = subprocess.check_output(["git", "describe", "--tags", "--first-parent"], | ||
stderr=devnull, cwd=root).strip() | ||
git_tag = re.sub(r"-g[a-f0-9]+$", "", git_tag) | ||
except: | ||
git_tag = None | ||
return { | ||
"git_hash": git_hash, | ||
"git_tag": git_tag | ||
} | ||
|
||
|
||
def _get_packages_version(): | ||
result = {} | ||
with open(os.devnull, "w") as devnull: | ||
for comp in subprocess.check_output(["pip3", "freeze"], stderr=devnull).decode().strip().split('\n'): | ||
matcher = VERSION_RE.match(comp) | ||
if matcher: | ||
name, version = matcher.groups() | ||
result[name] = version | ||
else: | ||
print("Cannot parse pacakge version: " + comp) | ||
return result | ||
|
||
|
||
def main(): | ||
git_tag = sys.argv[1] | ||
git_hash = sys.argv[2] | ||
report = { | ||
'main': { | ||
"git_hash": git_hash, | ||
"git_tag": git_tag | ||
}, | ||
'packages': _get_packages_version() | ||
} | ||
with open('versions.json', 'w') as file: | ||
json.dump(report, file, indent=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters