mirror of
https://github.com/docker/compose.git
synced 2025-09-25 18:48:47 +02:00
Add version guard for multi-service buildarg
Add buildarg tests Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
ac209a2485
commit
8e268afc93
@ -236,8 +236,14 @@ class TopLevelCommand(object):
|
|||||||
-m, --memory MEM Sets memory limit for the build container.
|
-m, --memory MEM Sets memory limit for the build container.
|
||||||
--build-arg key=val Set build-time variables for services.
|
--build-arg key=val Set build-time variables for services.
|
||||||
"""
|
"""
|
||||||
|
service_names = options['SERVICE']
|
||||||
build_args = options.get('--build-arg', None)
|
build_args = options.get('--build-arg', None)
|
||||||
if build_args:
|
if build_args:
|
||||||
|
if not service_names and docker.utils.version_lt(self.project.client.api_version, '1.25'):
|
||||||
|
raise UserError(
|
||||||
|
'--build-arg is only supported when services are specified for API version < 1.25.'
|
||||||
|
' Please use a Compose file version > 2.2 or specify which services to build.'
|
||||||
|
)
|
||||||
environment = Environment.from_env_file(self.project_dir)
|
environment = Environment.from_env_file(self.project_dir)
|
||||||
build_args = resolve_build_args(build_args, environment)
|
build_args = resolve_build_args(build_args, environment)
|
||||||
|
|
||||||
@ -1026,8 +1032,7 @@ class TopLevelCommand(object):
|
|||||||
|
|
||||||
if cascade_stop:
|
if cascade_stop:
|
||||||
print("Aborting on container exit...")
|
print("Aborting on container exit...")
|
||||||
all_containers = self.project.containers(
|
all_containers = self.project.containers(service_names=options['SERVICE'], stopped=True)
|
||||||
service_names=options['SERVICE'], stopped=True)
|
|
||||||
exit_code = compute_exit_code(
|
exit_code = compute_exit_code(
|
||||||
exit_value_from, attached_containers, cascade_starter, all_containers
|
exit_value_from, attached_containers, cascade_starter, all_containers
|
||||||
)
|
)
|
||||||
|
@ -658,6 +658,33 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
result = self.dispatch(['build', '--no-cache', '--memory', '96m', 'service'], None)
|
result = self.dispatch(['build', '--no-cache', '--memory', '96m', 'service'], None)
|
||||||
assert 'memory: 100663296' in result.stdout # 96 * 1024 * 1024
|
assert 'memory: 100663296' in result.stdout # 96 * 1024 * 1024
|
||||||
|
|
||||||
|
def test_build_with_buildarg_from_compose_file(self):
|
||||||
|
pull_busybox(self.client)
|
||||||
|
self.base_dir = 'tests/fixtures/build-args'
|
||||||
|
result = self.dispatch(['build'], None)
|
||||||
|
assert 'Favorite Touhou Character: mariya.kirisame' in result.stdout
|
||||||
|
|
||||||
|
def test_build_with_buildarg_cli_override(self):
|
||||||
|
pull_busybox(self.client)
|
||||||
|
self.base_dir = 'tests/fixtures/build-args'
|
||||||
|
result = self.dispatch(['build', '--build-arg', 'favorite_th_character=sakuya.izayoi'], None)
|
||||||
|
assert 'Favorite Touhou Character: sakuya.izayoi' in result.stdout
|
||||||
|
|
||||||
|
@mock.patch.dict(os.environ)
|
||||||
|
def test_build_with_buildarg_old_api_version(self):
|
||||||
|
pull_busybox(self.client)
|
||||||
|
self.base_dir = 'tests/fixtures/build-args'
|
||||||
|
os.environ['COMPOSE_API_VERSION'] = '1.24'
|
||||||
|
result = self.dispatch(
|
||||||
|
['build', '--build-arg', 'favorite_th_character=reimu.hakurei'], None, returncode=1
|
||||||
|
)
|
||||||
|
assert '--build-arg is only supported when services are specified' in result.stderr
|
||||||
|
|
||||||
|
result = self.dispatch(
|
||||||
|
['build', '--build-arg', 'favorite_th_character=hong.meiling', 'web'], None
|
||||||
|
)
|
||||||
|
assert 'Favorite Touhou Character: hong.meiling' in result.stdout
|
||||||
|
|
||||||
def test_bundle_with_digests(self):
|
def test_bundle_with_digests(self):
|
||||||
self.base_dir = 'tests/fixtures/bundle-with-digests/'
|
self.base_dir = 'tests/fixtures/bundle-with-digests/'
|
||||||
tmpdir = pytest.ensuretemp('cli_test_bundle')
|
tmpdir = pytest.ensuretemp('cli_test_bundle')
|
||||||
|
4
tests/fixtures/build-args/Dockerfile
vendored
Normal file
4
tests/fixtures/build-args/Dockerfile
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
FROM busybox:latest
|
||||||
|
LABEL com.docker.compose.test_image=true
|
||||||
|
ARG favorite_th_character
|
||||||
|
RUN echo "Favorite Touhou Character: ${favorite_th_character}"
|
7
tests/fixtures/build-args/docker-compose.yml
vendored
Normal file
7
tests/fixtures/build-args/docker-compose.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
version: '2.2'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
- favorite_th_character=mariya.kirisame
|
Loading…
x
Reference in New Issue
Block a user