From efde2b3047ba19a4631a7214fea76951e8bd32bf Mon Sep 17 00:00:00 2001 From: Tom Tuffin <71447672+ttuffin@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:41:25 +0100 Subject: [PATCH] AAP-15000: Changes to container image to reduce overall size (#575) Closes [AAP-15000](https://issues.redhat.com/browse/AAP-15000). The main changes are switching to Centos stream image and installing ansible-core instead of the full ansible package. Image size is reduced from ~2gb to ~500mb. Tests in the eda-qa test suite are passing with this image. --- .github/actions/image-test/action.yml | 2 +- Dockerfile | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/actions/image-test/action.yml b/.github/actions/image-test/action.yml index a01ede5d..361e0ee6 100644 --- a/.github/actions/image-test/action.yml +++ b/.github/actions/image-test/action.yml @@ -18,6 +18,6 @@ runs: - name: Run tests shell: bash run: > - docker run --rm -u 0 localhost/ansible-rulebook:test bash -c ' + docker run --rm localhost/ansible-rulebook:test bash -c ' pip install -r requirements_test.txt && pytest -m "e2e" -n auto' diff --git a/Dockerfile b/Dockerfile index 0c0af1e0..e5fcd653 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,22 @@ -FROM registry.access.redhat.com/ubi8/python-39 +FROM quay.io/centos/centos:stream9-development ARG USER_ID=${USER_ID:-1001} +ARG APP_DIR=${APP_DIR:-/app} ARG DEVEL_COLLECTION_LIBRARY=0 ARG DEVEL_COLLECTION_REPO=git+https://github.com/ansible/event-driven-ansible.git -WORKDIR $HOME USER 0 -RUN dnf install -y java-17-openjdk-devel +RUN useradd -u $USER_ID -d $APP_DIR appuser +WORKDIR $APP_DIR +COPY . $WORKDIR +RUN chown -R $USER_ID $APP_DIR +RUN dnf install -y java-17-openjdk-devel python3-pip + +USER $USER_ID ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk +ENV PATH="${PATH}:$APP_DIR/.local/bin" RUN pip install -U pip \ - && pip install ansible \ + && pip install ansible-core \ ansible-runner \ jmespath \ asyncio \ @@ -22,8 +29,4 @@ RUN pip install -U pip \ RUN bash -c "if [ $DEVEL_COLLECTION_LIBRARY -ne 0 ]; then \ ansible-galaxy collection install ${DEVEL_COLLECTION_REPO} --force; fi" -COPY . $WORKDIR -RUN chown -R $USER_ID ./ - -USER $USER_ID RUN pip install .