Skip to content

Commit b071fc1

Browse files
authored
Include UI as static files during build package build. (#83)
* Include UI as static files during build package build. * Add git tag versioning to setup.py * Add release script to travis.
1 parent 58f16ed commit b071fc1

File tree

6 files changed

+73
-4
lines changed

6 files changed

+73
-4
lines changed

.dockerignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Git
2-
.git/
3-
41
# Python
52
venv/
63
.venv/

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ after_failure:
4343
- sudo kubectl logs -l app=pulp-worker --tail=10000
4444
jobs:
4545
include:
46+
- stage: Release to PyPI
47+
if: tag IS NOT blank
48+
deploy:
49+
provider: pypi
50+
user: "__token__"
51+
skip_cleanup: true
52+
password:
53+
secure: "mNDI7pqihv+NGCbjb5vKepCp4x+fPjRboQmx1+utaPBgKtofY3Cy7KRSnIcDb5t621+Yb2ufRXk9JGliihHFUUzxVMQjxtIrT8CgbsyXYGFqCQTLp0juCShcU3uCrmn0OB5FZfv1TPmbqrD2iOq1RKx6P6kGEa06ysTelADBi39gdk6l6qfC0o8XBu407KnpOOkx6dR6FjoTmwjN4XsM/UukvBEpAPvgv9eSOJDWR/sEDjpCE2ZMLPSqqM6b01RdkzLOWcDwH56/wXW5IQ3QK4GR63tXcGk6FHw2nfgi1izJhzQWmGD1fpReyxR8EucMOSYzCQSflLiyLCEF/uwnWnFqVDufnElTBCnqMko1qwcoAHwR8fp3xM0WQvGc4krIQjDvKdPpI7vqMrHxX2ZoUG5bDgZEUoYtxlNPBQ8R5GLuupgkLgfh/bORvIxQvmBm8MVGxwO1Ze++9TwTCsxTOTKKEBu3AOtqfdY+IyvYeDPP/Zw37IvGckNGOIyT3KwYgU+L+JGuEHpHkfCBx2oE3NyPN9YAm/6da1ZR1iSeGd980ux0yTGwF8sL4vhUp4lCTsWBqZseztYCsc+QFDUiKMHMQVbftXIwDbtA10SVZlaCrpNHoXNDtWLRo28kqoHFty4+Lzqughqxu27Wf2Eh9MUx9fUcAJA3a/REYyrZjz8="
54+
on:
55+
tags: true
4656
...

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN set -ex; \
2727
python3-devel \
2828
libpq \
2929
libpq-devel \
30+
git \
3031
&& dnf clean all \
3132
&& rm -rf /var/cache/dnf/ \
3233
&& rm -f /var/lib/rpm/__db.* \

MANIFEST.IN

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include galaxy_ng/app/static/galaxy_ng *

galaxy_ng/version.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import subprocess
2+
3+
TAG_PREFIX = 'v'
4+
5+
6+
def get_git_version():
7+
"""
8+
Returns package version in PEP440 format based on latest annotated
9+
version tag. Version tags should have prefix 'v'.
10+
:return str: A version string.
11+
:raises RuntimeError: If cannot determine git version string.
12+
"""
13+
try:
14+
# TODO(cutwater): Replace `.decode('utf-8')` call with subprocess
15+
# parameter `encoding` after dropping Python 2.7 support.
16+
tag_info = subprocess.check_output([
17+
'git', 'describe', '--tags', '--always', '--match', TAG_PREFIX + '*']
18+
).decode('utf-8').strip()
19+
except subprocess.CalledProcessError:
20+
raise RuntimeError('Cannot determine git version string.')
21+
22+
if '-' in tag_info:
23+
chunks = tag_info.lstrip(TAG_PREFIX).rsplit('-', 2)
24+
return '{0}.dev{1}+{2}'.format(*chunks)
25+
26+
if '.' in tag_info:
27+
return tag_info.lstrip(TAG_PREFIX)
28+
29+
return '0.0.0.dev0+{0}'.format(tag_info)

setup.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env python3
22

3+
import setuptools.command.build_py
4+
import tarfile
5+
import urllib.request
6+
7+
from galaxy_ng import version
38
from setuptools import find_packages, setup
49

510
# NOTE(cutwater): Because bindings are statically generated, requirements list
@@ -20,9 +25,32 @@
2025
]
2126

2227

28+
UI_DOWNLOAD_URL = 'https://github.com/ansible/ansible-hub-ui/' + \
29+
'releases/latest/download/automation-hub-ui-dist.tar.gz'
30+
31+
32+
class BuildPyCommand(setuptools.command.build_py.build_py):
33+
"""Custom build command."""
34+
35+
def run(self):
36+
print('Downloading UI static files')
37+
38+
filename, headers = urllib.request.urlretrieve(
39+
UI_DOWNLOAD_URL,
40+
'automation-hub-ui-dist.tar.gz'
41+
)
42+
43+
print('Extracting ' + filename)
44+
tarfile.open(filename).extractall(
45+
path='galaxy_ng/app/static/galaxy_ng'
46+
)
47+
48+
setuptools.command.build_py.build_py.run(self)
49+
50+
2351
setup(
2452
name="galaxy-ng",
25-
version="0.1.0a1",
53+
version=version.get_git_version(),
2654
description="galaxy-ng plugin for the Pulp Project",
2755
license="GPLv2+",
2856
author="AUTHOR",
@@ -42,4 +70,7 @@
4270
"Programming Language :: Python :: 3.7",
4371
),
4472
entry_points={"pulpcore.plugin": ["galaxy_ng = galaxy_ng:default_app_config"]},
73+
cmdclass={
74+
'build_py': BuildPyCommand,
75+
},
4576
)

0 commit comments

Comments
 (0)