kopia lustrzana https://github.com/jupyterhub/repo2docker
commit
7bcfa06d8f
|
@ -5,6 +5,8 @@ Release date: the-future
|
|||
|
||||
New features
|
||||
------------
|
||||
- Add additional metadata to docker images about how they were built `#500`_ by
|
||||
`@jrbourbeau`_.
|
||||
|
||||
API changes
|
||||
-----------
|
||||
|
@ -99,6 +101,7 @@ Released 2017-04-14
|
|||
.. _#475: https://github.com/jupyter/repo2docker/pull/475
|
||||
.. _#478: https://github.com/jupyter/repo2docker/pull/478
|
||||
.. _#482: https://github.com/jupyter/repo2docker/pull/482
|
||||
.. _#500: https://github.com/jupyter/repo2docker/pull/500
|
||||
|
||||
.. _@agahkarakuzu: https://github.com/agahkarakuzu
|
||||
.. _@betatim: https://github.com/betatim
|
||||
|
@ -107,6 +110,7 @@ Released 2017-04-14
|
|||
.. _@costrouc: https://github.com/costrouc
|
||||
.. _@dsludwig: https://github.com/dsludwig
|
||||
.. _@evertrol: https://github.com/evertrol
|
||||
.. _@jrbourbeau: https://github.com/jrbourbeau
|
||||
.. _@minrk: https://github.com/minrk
|
||||
.. _@nuest: https://github.com/nuest
|
||||
.. _@yuvipanda: https://github.com/yuvipanda
|
||||
|
|
|
@ -745,6 +745,11 @@ class Repo2Docker(Application):
|
|||
picked_buildpack = self.default_buildpack()
|
||||
|
||||
picked_buildpack.appendix = self.appendix
|
||||
# Add metadata labels
|
||||
picked_buildpack.labels['repo2docker.version'] = self.version
|
||||
repo_label = 'local' if os.path.isdir(self.repo) else self.repo
|
||||
picked_buildpack.labels['repo2docker.repo'] = repo_label
|
||||
picked_buildpack.labels['repo2docker.ref'] = self.ref
|
||||
|
||||
self.log.debug(picked_buildpack.render(),
|
||||
extra=dict(phase='building'))
|
||||
|
|
|
@ -120,8 +120,8 @@ ENV {{item[0]}} {{item[1]}}
|
|||
# Container image Labels!
|
||||
# Put these at the end, since we don't want to rebuild everything
|
||||
# when these change! Did I mention I hate Dockerfile cache semantics?
|
||||
{% for k, v in labels.items() -%}
|
||||
LABEL {{k}}={{v}}
|
||||
{% for k, v in labels.items() %}
|
||||
LABEL {{k}}="{{v}}"
|
||||
{%- endfor %}
|
||||
|
||||
# We always want containers to run as non-root
|
||||
|
@ -171,6 +171,7 @@ class BuildPack:
|
|||
def __init__(self):
|
||||
self.log = logging.getLogger('repo2docker')
|
||||
self.appendix = ''
|
||||
self.labels = {}
|
||||
if sys.platform.startswith('win'):
|
||||
self.log.warning("Windows environment detected. Note that Windows "
|
||||
"support is experimental in repo2docker.")
|
||||
|
@ -246,7 +247,7 @@ class BuildPack:
|
|||
"""
|
||||
Docker labels to set on the built image.
|
||||
"""
|
||||
return {}
|
||||
return self.labels
|
||||
|
||||
def get_build_script_files(self):
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
"""
|
||||
Test if labels are supplied correctly to the container
|
||||
"""
|
||||
from repo2docker.app import Repo2Docker
|
||||
from repo2docker.buildpacks import BuildPack
|
||||
from repo2docker import __version__
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
URL = "https://github.com/binderhub-ci-repos/repo2docker-ci-clone-depth"
|
||||
|
||||
|
||||
def test_buildpack_labels_rendered():
|
||||
bp = BuildPack()
|
||||
assert 'LABEL' not in bp.render()
|
||||
bp.labels['first_label'] = 'firstlabel'
|
||||
assert 'LABEL first_label="firstlabel"\n' in bp.render()
|
||||
bp.labels['second_label'] = 'anotherlabel'
|
||||
assert 'LABEL second_label="anotherlabel"\n' in bp.render()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ref, repo, expected_repo_label', [
|
||||
(None, URL, URL),
|
||||
('some-ref', None, 'local'),
|
||||
(None, None, 'local'),
|
||||
])
|
||||
def test_Repo2Docker_labels(ref, repo, expected_repo_label, tmpdir):
|
||||
if repo is None:
|
||||
repo = str(tmpdir)
|
||||
if ref is not None:
|
||||
argv = ['--ref', ref, repo]
|
||||
else:
|
||||
argv = [repo]
|
||||
|
||||
app = Repo2Docker()
|
||||
# Add mock BuildPack to app
|
||||
mock_buildpack = Mock()
|
||||
mock_buildpack.return_value.labels = {}
|
||||
app.buildpacks = [mock_buildpack]
|
||||
|
||||
app.initialize(argv)
|
||||
app.build = False
|
||||
app.run = False
|
||||
app.start()
|
||||
expected_labels = {
|
||||
'repo2docker.ref': ref,
|
||||
'repo2docker.repo': expected_repo_label,
|
||||
'repo2docker.version': __version__,
|
||||
}
|
||||
|
||||
assert mock_buildpack().labels == expected_labels
|
Ładowanie…
Reference in New Issue