From 3199f15662373ca53fe1c7541259b31799e42315 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Mon, 19 Oct 2020 02:10:12 +0100 Subject: [PATCH] build/deploy: Fix --buildArg option with docker-compose.yml projects Resolves: #1053 Change-type: patch --- lib/utils/compose_ts.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/utils/compose_ts.ts b/lib/utils/compose_ts.ts index dba5c7a7..91289f51 100644 --- a/lib/utils/compose_ts.ts +++ b/lib/utils/compose_ts.ts @@ -313,14 +313,23 @@ function setTaskAttributes({ // multibuild (splitBuildStream) parses the composition internally so // any tags we've set before are lost; re-assign them here task.tag ??= [projectName, task.serviceName].join('_').toLowerCase(); - - task.dockerOpts ??= {}; if (isBuildConfig(d.image)) { d.image.tag = task.tag; - if (d.image.args) { - task.dockerOpts.buildargs ??= {}; - _.merge(task.dockerOpts.buildargs, d.image.args); - } + } + // reassign task.args so that the `--buildArg` flag takes precedence + // over assignments in the docker-compose.yml file (service.build.args) + task.args = { + ...task.args, + ...buildOpts.buildargs, + }; + + // Docker image build options + task.dockerOpts ??= {}; + if (task.args && Object.keys(task.args).length) { + task.dockerOpts.buildargs = { + ...task.dockerOpts.buildargs, + ...task.args, + }; } _.merge(task.dockerOpts, buildOpts, { t: task.tag }); }