diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 21849b0..c92d728 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -25,15 +25,15 @@ jobs: - tox_env: lint # - tox_env: docs - tox_env: py36 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=3 - tox_env: py36-devel - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=3 - tox_env: py37 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=3 - tox_env: py38 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=3 - tox_env: py39 - PREFIX: PYTEST_REQPASS=2 + PREFIX: PYTEST_REQPASS=3 - tox_env: packaging steps: diff --git a/molecule_podman/playbooks/Dockerfile.j2 b/molecule_podman/playbooks/Dockerfile.j2 new file mode 100644 index 0000000..8617591 --- /dev/null +++ b/molecule_podman/playbooks/Dockerfile.j2 @@ -0,0 +1,22 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean && rm -rf /var/lib/apt/lists/*; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python3 sudo bash iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python3 sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python3 sudo bash ca-certificates iproute2 && xbps-remove -O; fi diff --git a/molecule_podman/playbooks/validate-dockerfile.yml b/molecule_podman/playbooks/validate-dockerfile.yml new file mode 100644 index 0000000..5c2e63f --- /dev/null +++ b/molecule_podman/playbooks/validate-dockerfile.yml @@ -0,0 +1,55 @@ +#!/usr/bin/env ansible-playbook +--- +- hosts: localhost + connection: local + gather_facts: false + collections: + - containers.podman + vars: + platforms: + # platforms supported as being managed by molecule/ansible, this does + # not mean molecule itself can run on them. + - image: alpine:edge + - image: centos:7 + - image: centos:8 + - image: ubuntu:latest + - image: debian:latest + tasks: + + - name: Create isolated build directories for each image + tempfile: + prefix: "molecule-dockerfile-{{ item.image }}" + state: directory + register: temp_image_dirs + with_items: "{{ platforms }}" + loop_control: + label: "{{ item.image }}" + + - name: Expand Dockerfile templates + template: + src: Dockerfile.j2 + dest: "{{ temp_image_dirs.results[index].path }}/Dockerfile" + register: result + with_items: "{{ platforms }}" + loop_control: + index_var: index + label: "{{ item.image }}" + + - name: Build Dockerfile(s) + podman_image: + name: "{{ item.item.image }}" + path: "{{ temp_image_dirs.results[index].path }}" + state: build + with_items: "{{ result.results }}" + loop_control: + index_var: index + label: "{{ item.item.image }}" + register: result + + - name: Clean up temporary Dockerfile's + file: + path: "{{ item }}" + state: absent + loop: "{{ temp_dockerfiles.results | map(attribute='path') | list }}" + + - debug: var=result diff --git a/molecule_podman/test/test_func.py b/molecule_podman/test/test_func.py index 90c0c26..dcf1a82 100644 --- a/molecule_podman/test/test_func.py +++ b/molecule_podman/test/test_func.py @@ -1,14 +1,26 @@ """Functional tests.""" import os +import subprocess import pytest import sh from molecule import logger from molecule.test.conftest import change_dir_to, run_command +import molecule_podman + LOG = logger.get_logger(__name__) +def format_result(result: subprocess.CompletedProcess): + """Return friendly representation of completed process run.""" + return ( + f"RC: {result.returncode}\n" + + f"STDOUT: {result.stdout}\n" + + f"STDERR: {result.stderr}" + ) + + # @pytest.mark.xfail(reason="need to fix template path") def test_command_init_scenario(temp_dir, DRIVER): """Verify that init scenario works.""" @@ -28,3 +40,36 @@ def test_command_init_scenario(temp_dir, DRIVER): cmd = sh.molecule.bake("--debug", "test", "-s", "test-scenario") run_command(cmd) + + +def test_dockerfile(): + """Verify that our embedded dockerfile can be build.""" + result = subprocess.run( + ["ansible-playbook", "--version"], + check=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + stdin=subprocess.DEVNULL, + shell=False, + universal_newlines=True, + ) + assert result.returncode == 0, result + assert "ansible-playbook" in result.stdout + + module_path = os.path.dirname(molecule_podman.__file__) + assert os.path.isdir(module_path) + env = os.environ.copy() + env["ANSIBLE_FORCE_COLOR"] = "0" + result = subprocess.run( + ["ansible-playbook", "-i", "localhost,", "playbooks/validate-dockerfile.yml"], + check=False, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + stdin=subprocess.DEVNULL, + shell=False, + cwd=module_path, + universal_newlines=True, + env=env, + ) + assert result.returncode == 0, format_result(result) + # , result diff --git a/setup.cfg b/setup.cfg index 7f18cdb..2180ae4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,7 +64,7 @@ setup_requires = # These are required in actual runtime: install_requires = - molecule >= 3.0.2 + molecule >= 3.1.2 # selinux python module is needed as least by ansible-podman modules # and allows us of isolated (default) virtualenvs. It does not avoid need # to install the system selinux libraries but it will provide a clear