diff --git a/galaxy.yml b/galaxy.yml index 4590aad..0c48788 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: syndr name: molecule # The version of the collection. Must be compatible with semantic versioning -version: 1.6.0 +version: 2.0.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 423f79a..72c4999 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -20,7 +20,11 @@ platforms: image: rockylinux/rockylinux:9-ubi systemd: True exec_systemd: True + exec_systemd_build_commands: + - dnf install -y sudo privileged: False + hostvars: + test_hostvar: test - name: ansible-collection-molecule-docker-fedora41 type: docker image: geerlingguy/docker-fedora41-ansible:latest diff --git a/roles/docker_platform/defaults/main.yml b/roles/docker_platform/defaults/main.yml index 5a2cd1a..756a0a3 100644 --- a/roles/docker_platform/defaults/main.yml +++ b/roles/docker_platform/defaults/main.yml @@ -25,7 +25,7 @@ docker_platform_container_defaults: command: "" # Container hostname - hostname: molecule-ci-{{ __docker_platform_instance.name }} + hostname: molecule-ci-{{ __docker_platform_instance.name | default('instance') }} # Number of CPUs to allocate to the container cpus: 2 @@ -101,12 +101,20 @@ docker_platform_container_defaults: # WARNING: # - This can cause issues with some containers # - Not required if the container is already built with systemd running as PID 1 - # - Expects the container to have systemd installed + # - Expects the container to have systemd packages present + # - Rebuilds the container with a custom entrypoint, provided by 'exec_systemd_path' exec_systemd: false # Path to the systemd binary in the container + # - This is only used if 'exec_systemd' is true exec_systemd_path: /usr/lib/systemd/systemd + # List of commands to run as part of the docker build process to enable systemd + # - This is only used if 'exec_systemd' is true + # - Each command should be a string + # - Commands are run in the order they are defined, using the docker RUN directive + exec_systemd_build_commands: [] + # Tmpfs mounts to add to the container tmpfs: [] diff --git a/roles/docker_platform/tasks/custom_image/buildfiles.yml b/roles/docker_platform/tasks/custom_image/buildfiles.yml index 8ca043e..3882dad 100644 --- a/roles/docker_platform/tasks/custom_image/buildfiles.yml +++ b/roles/docker_platform/tasks/custom_image/buildfiles.yml @@ -12,9 +12,8 @@ mode: "0755" - name: Exec Systemd | Build file exists + # Add additional build files to this list as needed loop: - - bash.service.j2 - - entrypoint.sh.j2 - Dockerfile.j2 loop_control: loop_var: __docker_platform_item diff --git a/roles/docker_platform/templates/Dockerfile.j2 b/roles/docker_platform/templates/Dockerfile.j2 index 1ce8727..e54d6d7 100644 --- a/roles/docker_platform/templates/Dockerfile.j2 +++ b/roles/docker_platform/templates/Dockerfile.j2 @@ -1,11 +1,9 @@ FROM {{ __docker_platform_definition.image }} -COPY bash.service /etc/systemd/system/bash.service -COPY entrypoint.sh /entrypoint.sh -RUN chown root:root /entrypoint.sh \ - && chmod 755 /entrypoint.sh \ - && chown root:root /etc/systemd/system/bash.service \ - && chmod 644 /etc/systemd/system/bash.service \ - && systemctl enable bash.service -ENTRYPOINT ["/entrypoint.sh"] + +{% for __run_command in __docker_platform_definition.exec_systemd_build_commands %} +RUN {{ __run_command }} +{% endfor %} + +ENTRYPOINT ["{{ __docker_platform_definition.exec_systemd_path | default(docker_platform_container_defaults.exec_systemd_path) }}"] diff --git a/roles/docker_platform/templates/bash.service.j2 b/roles/docker_platform/templates/bash.service.j2 deleted file mode 100644 index b2f8133..0000000 --- a/roles/docker_platform/templates/bash.service.j2 +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Start bash shell attached to container STDIN/STDOUT - -[Service] -Type=simple -PassEnvironment=PATH LD_LIBRARY_PATH -ExecStart=/bin/bash -c "echo Attaching to pipes of PID `cat container-pipes-pid` && exec /bin/bash < /proc/`cat container-pipes-pid`/fd/0 > /proc/`cat container-pipes-pid`/fd/1 2>/proc/`cat container-pipes-pid`/fd/2" -ExecStopPost=/usr/bin/systemctl exit $EXIT_STATUS - -[Install] -WantedBy=multi-user.target rescue.target - diff --git a/roles/docker_platform/templates/entrypoint.sh.j2 b/roles/docker_platform/templates/entrypoint.sh.j2 deleted file mode 100644 index a38822e..0000000 --- a/roles/docker_platform/templates/entrypoint.sh.j2 +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -echo Start a long-running process to keep the container pipes open -sleep infinity < /proc/1/fd/0 > /proc/1/fd/1 2>&1 & - -echo Wait a bit before retrieving the PID -sleep 1 - -echo Save the long-running PID on file -echo $! > /container-pipes-pid - -echo Start systemd as PID 1 -exec /usr/lib/systemd/systemd - -echo Attaching to pipes of PID `cat container-pipes-pid` -exec /bin/bash < /proc/`cat container-pipes-pid`/fd/0 > /proc/`cat container-pipes-pid`/fd/1 2>/proc/`cat container-pipes-pid`/fd/2 -