community.docker
community.docker copied to clipboard
docker build from url of git repository
SUMMARY
I'd like to ask if community.docker.docker_image
can be extended to allow build
param to use a URL of a git
repository.
As noted in the docker build
documentation [1], users can build an image directly from the command line by passing the URL
ISSUE TYPE
- Feature Idea
COMPONENT NAME
-
community.docker.docker_image
->build
param
ADDITIONAL INFORMATION
I'd imagine the configuration could look something like this. Notice the path
and source
flags.
Note that source=git
doesn't exist currently in the existing ansible-docker, but I'd imagine something similar would be needed
- name: build docker image for hello-world
community.docker.docker_image:
build:
path: https://github.com/docker-library/hello-world.git#:amd64/hello-world
name: hello-world-custom
source: git
the above command would be equivalent to this
docker build --tag hello-world-custom https://github.com/docker-library/hello-world.git#:amd64/hello-world
Is this something supported by the Docker Daemon (i.e. by the API), or is this something handled by the Docker CLI program? If it's the former, we can offer it without much work, but if it's the later, we'd have to completely reimplement it.
I'm not familiar with the Docker Daemon API (normally I just use Ansible or docker compose), but this looks like it may be supported by the API?
- https://docs.docker.com/engine/api/v1.41/#operation/ImageBuild
query Parameters - remote:string A Git repository URI or HTTP/HTTPS context URI. If the URI points to a single text file, the file’s contents are placed into a file called Dockerfile and the image is built from that file. If the URI points to a tarball, the file is downloaded by the daemon and the contents therein used as the context for the build. If the URI points to a tarball and the dockerfile parameter is also specified, there must be a file with the corresponding path inside the tarball.
Looks like this has already been present since at least API version 1.18: https://docs.docker.com/engine/api/v1.18/#build-image-from-a-dockerfile Docker SDK or Python also supports it: https://docker-py.readthedocs.io/en/stable/api.html#docker.api.build.BuildApiMixin.build (since version 0.1.0 actually, according to the changelog)
So supporting it should definitely be possible.