From 73522d3b53363b834caeb07a7b44706c48162a33 Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Tue, 18 Aug 2020 12:33:15 -0400 Subject: [PATCH] Dockerfile now is properly set up to run tests in a rootless container (#11) * Dockerfile now is properly set up to run tests in a rootless container * Keep docker as default --- Makefile | 9 ++++++--- ci/Dockerfile | 27 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 7c5e0b7..9cc0050 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,21 @@ # Also needs to be updated in galaxy.yml VERSION = 0.1.0 +# To run sanity tests in a venv, set SANITY_TEST_ARGS to '--venv' +SANITY_TEST_ARGS ?= '--docker' + clean: - rm -f community-okd-${VERSION}.tar.gz + rm -f community-okd-$(VERSION).tar.gz rm -rf ansible_collections build: clean ansible-galaxy collection build install: build - ansible-galaxy collection install -p ansible_collections community-okd-${VERSION}.tar.gz + ansible-galaxy collection install -p ansible_collections community-okd-$(VERSION).tar.gz test-sanity: install - cd ansible_collections/community/okd && ansible-test sanity -v --docker --color $(TEST_ARGS) + cd ansible_collections/community/okd && ansible-test sanity -v --color $(SANITY_TEST_ARGS) test-integration: install molecule test diff --git a/ci/Dockerfile b/ci/Dockerfile index 18f88db..e20e8bd 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,14 +1,33 @@ FROM registry.access.redhat.com/ubi8/ubi -RUN yum install -y make python3 python3-devel python3-pip python3-setuptools \ +ENV OPERATOR=/usr/local/bin/ansible-operator \ + USER_UID=1001 \ + USER_NAME=ansible-operator\ + HOME=/opt/ansible \ + ANSIBLE_LOCAL_TMP=/opt/ansible/tmp + +RUN yum install -y \ + glibc-langpack-en \ + git \ + make \ + python3 \ + python3-devel \ + python3-pip \ + python3-setuptools \ && pip3 install --upgrade setuptools pip \ && pip3 install \ openshift \ ansible \ molecule -WORKDIR /src +COPY . /opt/ansible -COPY . /src +WORKDIR /opt/ansible -USER 1001 +RUN echo "${USER_NAME}:x:${USER_UID}:0:${USER_NAME} user:${HOME}:/sbin/nologin" >> /etc/passwd \ + && mkdir -p "${HOME}/.ansible/tmp" \ + && chown -R "${USER_UID}:0" "${HOME}" \ + && chmod -R ug+rw "${HOME}" + + +USER ${USER_UID}