dockerspec icon indicating copy to clipboard operation
dockerspec copied to clipboard

How does one specify build ARG to docker-build ?

Open tjbaker opened this issue 6 years ago • 9 comments

Dockerspec Version

0.5.0

Ruby Version

2.3

Platform Details

macOS

$ docker --version
Docker version 17.09.0-ce, build afdb6d4

Scenario

How does one specify build ARGs that are required in the Dockerfile via the describe docker_build() method? I can't find any examples of passing ARG. Builds requiring passed in ARG values can not be tested as the arg won't have an appropriate value.

tjbaker avatar Dec 05 '17 17:12 tjbaker

I essentially need to pass the docker build option is –build-arg to describe docker_build(). Ideas?

tjbaker avatar Dec 05 '17 17:12 tjbaker

It looks like this project has no support for ARG. https://github.com/zuazo/dockerspec/blob/master/lib/dockerspec/builder/matchers.rb#L34-L58

The parser code referenced in the comments does in-fact have ARG: https://github.com/moby/moby/blob/master/builder/dockerfile/parser/parser.go#L188

tjbaker avatar Dec 05 '17 17:12 tjbaker

What is your use case? Can you provide a complete example? Maybe passing ENV variables could be enough for you.

AFAIK, adding ARG to the Dockerfile, will require that you pass --build-arg with those vars, so I think you could use ENV for that, couldn't you?

zuazo avatar Dec 09 '17 07:12 zuazo

We have a generic Dockerfile that drives many images via docker-compose. ARG is used extensively to provide the values. When you have many services in the compose file and many args in the Dockerfile it is not feasible to use ENV and default everything since there is no common value.

ARG is a native feature to Docker and it should be supported via a testing framework such as this.

tjbaker avatar Dec 11 '17 15:12 tjbaker

We also need ARG support.

ENV vars are ARGS are very different. ENV vars are not used when building a docker image, only ARGS are.

tecnobrat avatar Jan 18 '18 17:01 tecnobrat

Thanks. I understand the difference.

Unfortunately recently I did not have a lot of time. My apologies for that. Anyway, if you do a PR, I will be happy to review it ASAP :smile: Maybe it will no be easy, IDK, but the code has a lot of comments to help you in the process. Any question you have, let me know on this issue.

zuazo avatar Feb 17 '18 16:02 zuazo

@tjbaker Have you tried using default values? I was failing to use the ARG option with the same error but then I specified a default value and it worked a treat

ARG VERSION_ELK=6.2.2
ARG FLAVOUR_ELK=""
FROM docker.elastic.co/elasticsearch/elasticsearch${FLAVOUR_ELK}:${VERSION_ELK}

deploymentking avatar Apr 09 '18 08:04 deploymentking

Hi, it's been two years... any chance dockerspec will support build ARGs in addition to run-time ENVs?

hardyoyo avatar Feb 01 '19 18:02 hardyoyo

If you're OK with not running any build-related tests on the build for which you need to use --build-arg, you can always make a system call to the docker build command... these tests are after all just Ruby files. Here's an example of what we're doing: https://github.com/UCLALibrary/docker-cantaloupe/blob/84cc2dd70454f821746123feed899580af1b0655/spec/cantaloupe_spec.rb#L21-L29 This works for us because we test the build completely in a previous step. Ideally, yes, DockerSpec would provide support for --build-arg but until it does, a system call might get you by.

hardyoyo avatar Feb 28 '19 16:02 hardyoyo