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 1 commit
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
60 changes: 47 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
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-development as build

Alex-Izquierdo marked this conversation as resolved.
Show resolved Hide resolved
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 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 \

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

RUN python3 -m venv $APP_DIR/venv \
&& pip install -U pip \
&& pip install ansible-core \
ansible-runner \
jmespath \
Expand All @@ -29,6 +28,41 @@ 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 . $WORKDIR

Alex-Izquierdo marked this conversation as resolved.
Show resolved Hide resolved
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

RUN microdnf install -y shadow-utils \
&& 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