From e42e11c7140523bdc8c36e2601413f242b8d453e Mon Sep 17 00:00:00 2001 From: Sergey <6213510+sshnaidm@users.noreply.github.com> Date: Wed, 23 Aug 2023 00:03:50 +0300 Subject: [PATCH] Add CI for runlabel testing (#630) Signed-off-by: Sagi Shnaidman --- .github/workflows/podman_runlabel.yml | 99 +++++++++++++++++++ ci/playbooks/containers/podman_runlabel.yml | 9 ++ .../targets/podman_runlabel/files/Dockerfile | 34 +++++++ .../targets/podman_runlabel/files/start.sh | 5 + .../targets/podman_runlabel/tasks/main.yml | 49 +++++++++ 5 files changed, 196 insertions(+) create mode 100644 .github/workflows/podman_runlabel.yml create mode 100644 ci/playbooks/containers/podman_runlabel.yml create mode 100644 tests/integration/targets/podman_runlabel/files/Dockerfile create mode 100755 tests/integration/targets/podman_runlabel/files/start.sh create mode 100644 tests/integration/targets/podman_runlabel/tasks/main.yml diff --git a/.github/workflows/podman_runlabel.yml b/.github/workflows/podman_runlabel.yml new file mode 100644 index 0000000..99a80d6 --- /dev/null +++ b/.github/workflows/podman_runlabel.yml @@ -0,0 +1,99 @@ +name: Podman runlabel module + +on: + push: + paths: + - '.github/workflows/podman_runlabel.yml' + - 'ci/*.yml' + - 'ci/run_containers_tests.sh' + - 'ci/playbooks/containers/podman_runlabel.yml' + - 'plugins/modules/podman_runlabel.py' + - 'tests/integration/targets/podman_runlabel/**' + branches: + - master + pull_request: + paths: + - '.github/workflows/podman_runlabel.yml' + - 'ci/*.yml' + - 'ci/run_containers_tests.sh' + - 'ci/playbooks/containers/podman_runlabel.yml' + - 'plugins/modules/podman_runlabel.py' + - 'tests/integration/targets/podman_runlabel/**' + schedule: + - cron: 4 0 * * * # Run daily at 0:03 UTC + +jobs: + + test_podman_runlabel: + name: Podman runlabel module ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }} + runs-on: ${{ matrix.os || 'ubuntu-22.04' }} + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + ansible-version: + - ansible<2.10 + # - git+https://github.com/ansible/ansible.git@stable-2.11 + - git+https://github.com/ansible/ansible.git@devel + os: + - ubuntu-22.04 + python-version: + - "3.10" + + steps: + + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Upgrade pip and display Python and PIP versions + run: | + sudo apt-get update + sudo apt-get install -y python*-wheel python*-yaml + python -m pip install --upgrade pip + python -V + pip --version + - name: Set up pip cache + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ github.ref }}-units-VMs + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install Ansible ${{ matrix.ansible-version }} + run: python3 -m pip install --user --force-reinstall --upgrade '${{ matrix.ansible-version }}' + + - name: Build and install the collection tarball + run: | + rm -rf /tmp/just_new_collection + ~/.local/bin/ansible-galaxy collection build --output-path /tmp/just_new_collection --force + ~/.local/bin/ansible-galaxy collection install -vvv --force /tmp/just_new_collection/*.tar.gz + - name: Run collection tests for Podman runlabel module + run: | + export PATH=~/.local/bin:$PATH + echo "Run ansible version" + command -v ansible + ansible --version + export ANSIBLE_CONFIG=$(pwd)/ci/ansible-dev.cfg + if [[ '${{ matrix.ansible-version }}' == 'ansible<2.10' ]]; then + export ANSIBLE_CONFIG=$(pwd)/ci/ansible-2.9.cfg + fi + echo $ANSIBLE_CONFIG + command -v ansible-playbook + pip --version + python --version + ansible-playbook --version + ansible-playbook -vv ci/playbooks/pre.yml \ + -e host=localhost \ + -i localhost, \ + -e ansible_connection=local \ + -e setup_python=false + TEST2RUN=podman_runlabel ./ci/run_containers_tests.sh + shell: bash diff --git a/ci/playbooks/containers/podman_runlabel.yml b/ci/playbooks/containers/podman_runlabel.yml new file mode 100644 index 0000000..e28d31b --- /dev/null +++ b/ci/playbooks/containers/podman_runlabel.yml @@ -0,0 +1,9 @@ +--- +- hosts: all + gather_facts: true + tasks: + - include_role: + name: podman_runlabel + vars: + runlabel_image: runlabel_test + ansible_python_interpreter: "{{ _ansible_python_interpreter }}" diff --git a/tests/integration/targets/podman_runlabel/files/Dockerfile b/tests/integration/targets/podman_runlabel/files/Dockerfile new file mode 100644 index 0000000..36c24d0 --- /dev/null +++ b/tests/integration/targets/podman_runlabel/files/Dockerfile @@ -0,0 +1,34 @@ +FROM alpine + +LABEL "key"="amazing value" +LABEL nobody=cares +LABEL install="touch /tmp/testedinstallfortests" +LABEL run="touch /tmp/testedrunfortests" + +ARG build_arg + +ENV password root +ENV username root + +WORKDIR /work + +RUN adduser -D user && \ + adduser -D user2 + +COPY start.sh /start + +RUN chmod a+rwx /start + +EXPOSE 80 +EXPOSE 8080/tcp +VOLUME ["/data", "/data2"] +USER user +STOPSIGNAL KILL + +# problem with OS w/o systemd +# HEALTHCHECK --interval=5m --timeout=3s \ +# CMD date + +CMD ["1d"] +ENTRYPOINT ["/start"] + diff --git a/tests/integration/targets/podman_runlabel/files/start.sh b/tests/integration/targets/podman_runlabel/files/start.sh new file mode 100755 index 0000000..1217239 --- /dev/null +++ b/tests/integration/targets/podman_runlabel/files/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +s=${1:-"3h"} +sleep "$s" + diff --git a/tests/integration/targets/podman_runlabel/tasks/main.yml b/tests/integration/targets/podman_runlabel/tasks/main.yml new file mode 100644 index 0000000..e4c4fcc --- /dev/null +++ b/tests/integration/targets/podman_runlabel/tasks/main.yml @@ -0,0 +1,49 @@ +--- +- name: Create directory for user build images + file: + path: /tmp/usr_img + state: directory + +- name: Copy files to container build directory + copy: + src: "{{ item }}" + dest: "/tmp/usr_img/{{ item }}" + mode: 777 + loop: + - Dockerfile + - start.sh + +- name: Build test docker image for regular user + containers.podman.podman_image: + executable: "{{ test_executable | default('podman') }}" + name: "{{ runlabel_image }}" + path: /tmp/usr_img + build: + format: docker + extra_args: --cgroup-manager=cgroupfs + +- name: Run container runlabel install + containers.podman.podman_runlabel: + image: "{{ runlabel_image }}" + label: install + +- name: Run container runlabel run + containers.podman.podman_runlabel: + image: "{{ runlabel_image }}" + label: run + +- name: Check file for install exists + stat: + path: /tmp/testedinstallfortests + register: testedinstallfortests + +- name: Check file for run exists + stat: + path: /tmp/testedrunfortests + register: testedrunfortests + +- name: Make sure files exist + assert: + that: + - testedinstallfortests.stat.exists + - testedrunfortests.stat.exists