Bug 1419638 - Allow to pass arguments to docker when building docker-images. r=dustin
Ideally, we'd simply use the --build-arg docker argument along with ARG in the Dockerfile, but that's only supported from Docker API 1.21, and we're stuck on 1.18 for the moment. So we add another hack to how we handle the Dockerfile, by adding a commented syntax that allows to declare arguments to the Dockerfile. The arguments can be defined in the docker images kind.yml file through the `args` keyword. Under the hood, they are passed down to the docker image task through the environment. The mach taskcluster-build-image command then uses the corresponding values from the environment to generate a "preprocessed" Dockerfile for its context.
This commit is contained in:
@@ -34,6 +34,9 @@ docker_image_schema = Schema({
|
||||
# relative path (from config.path) to the file the docker image was defined
|
||||
# in.
|
||||
Optional('job-from'): basestring,
|
||||
|
||||
# Arguments to use for the Dockerfile.
|
||||
Optional('args'): {basestring: basestring},
|
||||
})
|
||||
|
||||
|
||||
@@ -50,9 +53,11 @@ def fill_template(config, tasks):
|
||||
for task in tasks:
|
||||
image_name = task.pop('name')
|
||||
job_symbol = task.pop('symbol')
|
||||
args = task.pop('args', {})
|
||||
|
||||
context_path = os.path.join('taskcluster', 'docker', image_name)
|
||||
context_hash = generate_context_hash(GECKO, context_path, image_name)
|
||||
context_hash = generate_context_hash(
|
||||
GECKO, context_path, image_name, args)
|
||||
|
||||
description = 'Build the docker image {} for use by dependent tasks'.format(
|
||||
image_name)
|
||||
@@ -120,6 +125,9 @@ def fill_template(config, tasks):
|
||||
},
|
||||
}
|
||||
|
||||
for k, v in args.items():
|
||||
taskdesc['worker']['env'][k] = v
|
||||
|
||||
add_optimization(
|
||||
config, taskdesc,
|
||||
cache_type="docker-images.v1",
|
||||
|
||||
Reference in New Issue
Block a user