Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce image size further #639

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
FROM quay.io/centos/centos:stream9-development

ARG USER_ID=${USER_ID:-1001}
ARG APP_DIR=${APP_DIR:-/app}

FROM quay.io/centos/centos:stream9 as build

ARG USER_ID
ARG APP_DIR
ARG DEVEL_COLLECTION_LIBRARY=0
ARG DEVEL_COLLECTION_REPO=git+https://github.com/ansible/event-driven-ansible.git

USER 0
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
RUN dnf install -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs \
java-17-openjdk-devel java-17-openjdk-jmods binutils python3-pip
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
ENV PATH="${PATH}:$APP_DIR/.local/bin"
RUN pip install -U pip \
&& pip install ansible-core \

RUN pip install -U pip virtualenv \
&& virtualenv --always-copy $APP_DIR/venv
ENV PATH="$APP_DIR/venv/bin:${PATH}"

RUN pip install ansible-core \
ansible-runner \
jmespath \
asyncio \
Expand All @@ -29,6 +29,43 @@ RUN pip install -U pip \
RUN bash -c "if [ $DEVEL_COLLECTION_LIBRARY -ne 0 ]; then \
ansible-galaxy collection install ${DEVEL_COLLECTION_REPO} --force; fi"

WORKDIR $APP_DIR
COPY . $APP_DIR

RUN pip install .

RUN chmod -R 0775 $APP_DIR
RUN $JAVA_HOME/bin/jdeps \
--ignore-missing-deps \
--print-module-deps \
--multi-release 17 \
--recursive \
$(find $APP_DIR -path '*/drools/jars/*' -name 'drools*.jar') > $APP_DIR/drools_jar_modules \
&& $JAVA_HOME/bin/jlink \
--add-modules $(cat $APP_DIR/drools_jar_modules) \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output $APP_DIR/custom_jre

FROM quay.io/centos/centos:stream9-minimal as dist

ARG USER_ID
ARG APP_DIR

ENV PATH="$APP_DIR/venv/bin:${PATH}"
ENV JAVA_HOME=/jre

COPY --from=build $APP_DIR/custom_jre $JAVA_HOME
COPY --from=build $APP_DIR/venv $APP_DIR/venv
COPY . $APP_DIR

RUN microdnf install -y --setopt=install_weak_deps=0 --setopt=tsflags=nodocs \
shadow-utils python3-libs \
&& useradd -u $USER_ID -d $APP_DIR appuser \
&& chown -R $USER_ID $APP_DIR \
&& chmod -R 0775 $APP_DIR \
&& microdnf clean all

WORKDIR $APP_DIR
USER $USER_ID
Loading