Hello,
today I was struggling while trying to pass build args to the Dockterfile. Tried three different ways to pass the args and got three different results.
This ist a.drone.yml file to reproduce:
---
kind: pipeline
name: debug build args
steps:
- name: build-args passed twice with build_args_from_env
image: plugins/docker
environment:
ARG1: arg1
ARG2: arg2
BRANCH: ${DRONE_BRANCH}
settings:
repo: smainz/plugin-drone-docker-debug
build_args_from_env:
- ARG1
- ARG2
- BRANCH
dry_run: true
- name: Passed wrong when given as mapping with build_args
image: plugins/docker
settings:
repo: smainz/plugin-drone-docker-debug
build_args:
ARG1: arg1
ARG2: arg2
BRANCH: ${DRONE_BRANCH}
dry_run: true
- name: Passed correctly when given as sequence with build_args
image: plugins/docker
settings:
repo: smainz/plugin-drone-docker-debug
build_args:
- ARG1=arg1
- ARG2=arg2
- BRANCH=${DRONE_BRANCH}
dry_run: true
The three ways of passing build args all have a different result (copied from the console):`
First step:
[build-args passed twice with build_args_from_env:79] + /usr/local/bin/docker build --rm=true -f Dockerfile -t 00000000 . --pull=true --build-arg ARG1=arg1 --build-arg ARG1=arg1 --build-arg ARG2=arg2 --build-arg ARG2=arg2 --build-arg BRANCH=master --build-arg BRANCH=master --label org.opencontainers.image.created=2021-04-08T10:01:30Z --label org.opencontainers.image.revision=00000000 --label org.opencontainers.image.source= --label org.opencontainers.image.url=
The build args are passed twice to the docker command line. Works but seems to be wrong.
Second step
[Passed wrong when given as mapping with build_args:79] + /usr/local/bin/docker build --rm=true -f Dockerfile -t 00000000 . --pull=true --build-arg {"ARG1":"arg1" --build-arg "ARG2":"arg2" --build-arg "BRANCH":"master"} --label org.opencontainers.image.created=2021-04-08T10:01:47Z --label org.opencontainers.image.revision=00000000 --label org.opencontainers.image.source= --label org.opencontainers.image.url=
Looks compleetly weird, although i do not know if I am supposed to define build args as a YAML mapping. Might be an enhancement well worth it.
Third step
[Passed wrong when given as mapping with build_args:79] + /usr/local/bin/docker build --rm=true -f Dockerfile -t 00000000 . --pull=true --build-arg {"ARG1":"arg1" --build-arg "ARG2":"arg2" --build-arg "BRANCH":"master"} --label org.opencontainers.image.created=2021-04-08T10:02:52Z --label org.opencontainers.image.revision=00000000 --label org.opencontainers.image.source= --label org.opencontainers.image.url=
Looks fine to me.
Question
I would have expected that all three steps give the same result.
Do you consider this as a bug?
For reference, this is the Dockerfile I have been using:
FROM alpine:3.12
ARG ARG1="not set"
ARG ARG2="not set"
ARG BRANCH="not set"
RUN echo ARG1 is $ARG1
RUN echo ARG2 is $ARG2
RUN echo BRANCH is ${BRANCH}
``