Explorar o código

Add the git sha to version output

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin %!s(int64=10) %!d(string=hai) anos
pai
achega
d4b9845201

+ 1 - 0
.gitignore

@@ -8,3 +8,4 @@
 /docs/_site
 /venv
 README.rst
+compose/GITSHA

+ 1 - 1
Dockerfile.run

@@ -8,6 +8,6 @@ COPY    requirements.txt /code/requirements.txt
 RUN     pip install -r /code/requirements.txt
 
 ADD     dist/docker-compose-release.tar.gz /code/docker-compose
-RUN     pip install /code/docker-compose/docker-compose-*
+RUN     pip install --no-deps /code/docker-compose/docker-compose-*
 
 ENTRYPOINT ["/usr/bin/docker-compose"]

+ 1 - 0
MANIFEST.in

@@ -7,6 +7,7 @@ include *.md
 exclude README.md
 include README.rst
 include compose/config/*.json
+include compose/GITSHA
 recursive-include contrib/completion *
 recursive-include tests *
 global-exclude *.pyc

+ 2 - 2
compose/cli/command.py

@@ -12,12 +12,12 @@ from requests.exceptions import SSLError
 
 from . import errors
 from . import verbose_proxy
-from .. import __version__
 from .. import config
 from ..project import Project
 from ..service import ConfigError
 from .docker_client import docker_client
 from .utils import call_silently
+from .utils import get_version_info
 from .utils import is_mac
 from .utils import is_ubuntu
 
@@ -71,7 +71,7 @@ def get_client(verbose=False, version=None):
     client = docker_client(version=version)
     if verbose:
         version_info = six.iteritems(client.version())
-        log.info("Compose version %s", __version__)
+        log.info(get_version_info('full'))
         log.info("Docker base_url: %s", client.base_url)
         log.info("Docker version: %s",
                  ", ".join("%s=%s" % item for item in version_info))

+ 29 - 10
compose/cli/utils.py

@@ -7,10 +7,10 @@ import platform
 import ssl
 import subprocess
 
-from docker import version as docker_py_version
+import docker
 from six.moves import input
 
-from .. import __version__
+import compose
 
 
 def yesno(prompt, default=None):
@@ -57,13 +57,32 @@ def is_ubuntu():
 
 
 def get_version_info(scope):
-    versioninfo = 'docker-compose version: %s' % __version__
+    versioninfo = 'docker-compose version {}, build {}'.format(
+        compose.__version__,
+        get_build_version())
+
     if scope == 'compose':
         return versioninfo
-    elif scope == 'full':
-        return versioninfo + '\n' \
-            + "docker-py version: %s\n" % docker_py_version \
-            + "%s version: %s\n" % (platform.python_implementation(), platform.python_version()) \
-            + "OpenSSL version: %s" % ssl.OPENSSL_VERSION
-    else:
-        raise RuntimeError('passed unallowed value to `cli.utils.get_version_info`')
+    if scope == 'full':
+        return (
+            "{}\n"
+            "docker-py version: {}\n"
+            "{} version: {}\n"
+            "OpenSSL version: {}"
+        ).format(
+            versioninfo,
+            docker.version,
+            platform.python_implementation(),
+            platform.python_version(),
+            ssl.OPENSSL_VERSION)
+
+    raise ValueError("{} is not a valid version scope".format(scope))
+
+
+def get_build_version():
+    filename = os.path.join(os.path.dirname(compose.__file__), 'GITSHA')
+    if not os.path.exists(filename):
+        return 'unknown'
+
+    with open(filename) as fh:
+        return fh.read().strip()

+ 19 - 5
docker-compose.spec

@@ -9,18 +9,32 @@ a = Analysis(['bin/docker-compose'],
              runtime_hooks=None,
              cipher=block_cipher)
 
-pyz = PYZ(a.pure,
-             cipher=block_cipher)
+pyz = PYZ(a.pure, cipher=block_cipher)
 
 exe = EXE(pyz,
           a.scripts,
           a.binaries,
           a.zipfiles,
           a.datas,
-          [('compose/config/fields_schema.json', 'compose/config/fields_schema.json', 'DATA')],
-          [('compose/config/service_schema.json', 'compose/config/service_schema.json', 'DATA')],
+          [
+            (
+                'compose/config/fields_schema.json',
+                'compose/config/fields_schema.json',
+                'DATA'
+            ),
+            (
+                'compose/config/service_schema.json',
+                'compose/config/service_schema.json',
+                'DATA'
+            ),
+            (
+                'compose/GITSHA',
+                'compose/GITSHA',
+                'DATA'
+            )
+          ],
           name='docker-compose',
           debug=False,
           strip=None,
           upx=True,
-          console=True )
+          console=True)

+ 1 - 0
script/build-image

@@ -10,6 +10,7 @@ fi
 TAG=$1
 VERSION="$(python setup.py --version)"
 
+./script/write-git-sha
 python setup.py sdist
 cp dist/docker-compose-$VERSION.tar.gz dist/docker-compose-release.tar.gz
 docker build -t docker/compose:$TAG -f Dockerfile.run .

+ 1 - 0
script/build-linux

@@ -9,4 +9,5 @@ docker build -t "$TAG" . | tail -n 200
 docker run \
     --rm --entrypoint="script/build-linux-inner" \
     -v $(pwd)/dist:/code/dist \
+    -v $(pwd)/.git:/code/.git \
     "$TAG"

+ 1 - 0
script/build-linux-inner

@@ -9,6 +9,7 @@ mkdir -p `pwd`/dist
 chmod 777 `pwd`/dist
 
 $VENV/bin/pip install -q -r requirements-build.txt
+./script/write-git-sha
 su -c "$VENV/bin/pyinstaller docker-compose.spec" user
 mv dist/docker-compose $TARGET
 $TARGET version

+ 1 - 0
script/build-osx

@@ -9,6 +9,7 @@ virtualenv -p /usr/local/bin/python venv
 venv/bin/pip install -r requirements.txt
 venv/bin/pip install -r requirements-build.txt
 venv/bin/pip install --no-deps .
+./script/write-git-sha
 venv/bin/pyinstaller docker-compose.spec
 mv dist/docker-compose dist/docker-compose-Darwin-x86_64
 dist/docker-compose-Darwin-x86_64 version

+ 2 - 0
script/build-windows.ps1

@@ -47,6 +47,8 @@ virtualenv .\venv
 .\venv\Scripts\pip install --no-deps .
 .\venv\Scripts\pip install --allow-external pyinstaller -r requirements-build.txt
 
+git rev-parse --short HEAD | out-file -encoding ASCII compose\GITSHA
+
 # Build binary
 # pyinstaller has lots of warnings, so we need to run with ErrorAction = Continue
 $ErrorActionPreference = "Continue"

+ 1 - 0
script/release/push-release

@@ -57,6 +57,7 @@ docker push docker/compose:$VERSION
 echo "Uploading sdist to pypi"
 pandoc -f markdown -t rst README.md -o README.rst
 sed -i -e 's/logo.png?raw=true/https:\/\/github.com\/docker\/compose\/raw\/master\/logo.png?raw=true/' README.rst
+./script/write-git-sha
 python setup.py sdist
 if [ "$(command -v twine 2> /dev/null)" ]; then
     twine upload ./dist/docker-compose-${VERSION}.tar.gz

+ 7 - 0
script/write-git-sha

@@ -0,0 +1,7 @@
+#!/bin/bash
+#
+# Write the current commit sha to the file GITSHA. This file is included in
+# packaging so that `docker-compose version` can include the git sha.
+#
+set -e
+git rev-parse --short HEAD > compose/GITSHA