Skip to content
This repository has been archived by the owner on Jan 8, 2023. It is now read-only.

Commit

Permalink
Added missing embedded dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Oct 17, 2020
1 parent d1aa482 commit 82b93ea
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tox.yml
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions 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
55 changes: 55 additions & 0 deletions 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
45 changes: 45 additions & 0 deletions 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."""
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
Expand Down

0 comments on commit 82b93ea

Please sign in to comment.