Podman and docker: dynamically skip registry login step
dometto opened this issue · 0 comments
Request
Make it possible to use an environment variable to determine whether the registry login step should be skipped or not. Presently this is impossible, because the conditional for that step look as follows:
# docker and podman create.yml
when:
- item.registry is defined
- item.registry.credentials is defined
- item.registry.credentials.username is defined
This means that if the registry
key is defined, regardless of what the values to any of its keys are, the login step is nevertheless performed. So this:
---
platforms:
- name: name
image: ghcr.io/foo/bar:latest
pre_build_image: true
registry:
url: $DOCKER_REGISTRY
credentials:
username: $DOCKER_USER
password: $DOCKER_PW
...means the login step is performed, even if all the $DOCKER_
variables are unset.
Use case
I would like for molecule to exhibit the following behaviour:
- If we're on CI, login and pull the image
- If we're running molecule locally, don't login and use local images
This is because on CI, I can use a token to login to the container registry, but I don't want my teammembers to have to login to the registry when running tests locally.
So something like the platforms
definition provided above should perform the login step if and only if the $DOCKER_
environment variables are set, and skip it otherwise.
Proposal
The login step should be skipped if the url
subkey of registry
is empty/None
. If the user has set the registry to an empty string (or in my example case, has not set the $DOCKER_REGISTRY
env variable), that seems a clear signal that they do not want to engage with the registry in any way.
Alternatively, the login step could also be skipped if the pull
key is explicitly set to false
by the user.