molecule-podman
molecule-podman copied to clipboard
Ansible rebuilds images after molecule destroy when pre_build_image: false
When I run molecule create
with pre_build_image: false
ansible recreates image everytime.
I'm not sure if this is a bug or expected behavior?
After molecule create
ls ~/.cache/molecule/gentoo-portage/default/
ansible.cfg Dockerfile_gentoo_portage molecule.yml
inventory state.yml
After molecule destroy
Dockerfile is gone
ls ~/.cache/molecule/gentoo-portage/default/
ansible.cfg inventory state.yml
Next time I run molecule create
Dockerfiles would be created again triggering Build an Ansible compatible image with platforms.changed
My molecule.yml
file
driver:
name: podman
platforms:
- name: gentoo-portage
image: gentoo-portage
dockerfile: Containerfile
pre_build_image: false
cmd: /sbin/init
provisioner:
name: ansible
verifier:
name: ansible
This is the expected behavior. While Build an Ansible compatible image
is rebuilding each time, molecule does not prune the image, only the instance. This means on successive builds where no changes are made, we're taking advantage of the image layers already existing on the host, so the build is almost instantaneous:
$ podman system prune -af
$ time molecule create
real 1m2.137s
user 0m42.328s
sys 0m7.961s
$ molecule destroy
$ time molecule create
real 0m3.748s
user 0m3.192s
sys 0m0.636s
In theory the Ansible task could better describe this, but I personally believe this to be expected behavior of minimal note and is specific to molecule itself, not molecule-podman. I've experienced the exact behavior when using Docker, so it is not isolated to Podman as a driver. Improving the explanation around pre_build_image
in the documentation might help to clarify this for future users, though I think this behavior is hinted at in some capacity, if not expressly stated somewhere I tend skim over.
Hope this is (mostly) correct and helps to clarify! Happy hacking :smile:
Ah, looks like there's an open issue to track a way of determining if containers should be rebuilt by checking whether the configuration was changed: https://github.com/ansible-community/molecule/issues/2175
I think this ticket might be a more suitable location for describing desired behavior, as it looks like this has been an open idea for some time.