dockerspec
dockerspec copied to clipboard
How does one specify build ARG to docker-build ?
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.
I essentially need to pass the docker build
option is –build-arg
to describe docker_build()
. Ideas?
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
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?
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.
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.
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.
@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}
Hi, it's been two years... any chance dockerspec will support build ARGs in addition to run-time ENVs?
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.