-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
In issue #3281 compose < 1.8.0-rc1 incorrectly sent undefined default build args as 'None' string to docker build, it was fixed by PR #3449 (included in compose 1.8.0-rc1) by sending an empty string instead to docker build.
I think it would be better to just not send the undefined build args to docker build, so that the default value for the build arg defined in Dockerfile would apply.
Scenario:
Files
Dockerfile:
FROM ubuntu:14.04
ARG FOO=1
RUN echo "-${FOO}-"
CMD /bin/bash
docker-compose.yml:
version: '2'
services:
test:
build:
context: .
args:
- FOO
Execution:
$ ./docker-compose-1.8.0-rc1 --verbose config
networks: {}
services:
test:
build:
args:
FOO: ''
context: /home/riccardi/git/ses-docker/test-default-build-arg
version: '2.0'
volumes: {}
$ ./docker-compose-1.8.0-rc1 --verbose build
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.auth.load_config: Found 'auths' section
docker.auth.auth.parse_auth: Found entry (registry=u'docker-registry-stag.systran.net:5000', username=u'systran')
compose.cli.command.get_client: docker-compose version 1.8.0-rc1, build 9bf6bc6
docker-py version: 1.8.1
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: KernelVersion=4.4.0-21-generic, Os=linux, BuildTime=2016-04-26T23:30:23.291099901+00:00, ApiVersion=1.23, Version=1.11.1, GitCommit=5604cbe, Arch=amd64, GoVersion=go1.5.4
compose.service.build: Building test
compose.cli.verbose_proxy.proxy_callable: docker build <- (pull=False, stream=True, nocache=False, tag=u'testdefaultbuildarg_test', buildargs={u'FOO': ''}, rm=True, forcerm=False, path='/home/riccardi/git/ses-docker/test-default-build-arg', dockerfile=None)
docker.api.build._set_auth_headers: Looking for auth config
docker.api.build._set_auth_headers: Sending auth config (u'docker-registry-stag.systran.net:5000')
compose.cli.verbose_proxy.proxy_callable: docker build -> <generator object _stream_helper at 0x7f8a18739b40>
Step 1 : FROM ubuntu:14.04
---> 8f1bd21bd25c
Step 2 : ARG FOO=1
---> Using cache
---> a8c68a88ef6d
Step 3 : RUN echo "-${FOO}-"
---> Running in c03d7e477353
--
---> 17f6ac07ea06
Removing intermediate container c03d7e477353
Step 4 : CMD /bin/bash
---> Running in 47164716758d
---> 5ef78af6532b
Removing intermediate container 47164716758d
Successfully built 5ef78af6532b
compose.cli.verbose_proxy.proxy_callable: docker close <- ()
compose.cli.verbose_proxy.proxy_callable: docker close -> None
Issue
Expected result:
prints -1-.
Actual result:
prints --.
<1.8.0-rc1 result:
prints -None-.
Details
compose 1.8.0-rc1 behavior is better than previous compose versions: it could be accepted as a correct behavior.
However, I believe the behavior could be improved further by expecting -1- as result, not --: if docker compose has no value for the build arg, then it should let docker build apply its own default value that comes from the Dockerfile.
Changing from -- to -1- is a breaking change, so I suggest to release it in 1.8.0 if this behavior is accepted.
Without this feature, I have to duplicate the default value both in Dockerfile and in .env read by docker-compose (or just in .env, but in this case the Dockerfile cannot be used alone, without docker-compose), and I think the best place for the default value is in the Dockerfile only.