From 4c24a5c3c2f462bbdd4778adbea03316e399a15a Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:26:28 -0400 Subject: [PATCH] move to Dockerfile.centos7 --- .github/workflows/maven-ci.yml | 2 +- DEVELOPING.md | 12 ++++- contrib/docker/Dockerfile | 75 +++++++------------------------ contrib/docker/Dockerfile.centos7 | 72 +++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 61 deletions(-) create mode 100644 contrib/docker/Dockerfile.centos7 diff --git a/.github/workflows/maven-ci.yml b/.github/workflows/maven-ci.yml index 0b76017ab2..cbd14cd67f 100644 --- a/.github/workflows/maven-ci.yml +++ b/.github/workflows/maven-ci.yml @@ -63,7 +63,7 @@ jobs: with: context: . push: false - file: contrib/docker/Dockerfile + file: contrib/docker/Dockerfile.centos7 cache-from: type=gha cache-to: type=gha,mode=max diff --git a/DEVELOPING.md b/DEVELOPING.md index 58f485a785..c87ef565c8 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -601,8 +601,18 @@ a non-root user. ### Build Emissary Docker Image -We can use Docker directly to build Emissary: +Maven can be used to create the docker image. There is a profile that was created to run the docker image build that, by default, +has been turned off. We'll need to add the docker profile, along with the dist profile, to trigger an assembly. From the +project root, run the following maven command: + +``` +mvn clean install -Pdist,docker +``` + +Alternatively, we can use Docker directly. First run a full maven build and then run the ```docker build``` command: + ``` +mvn clean install -Pdist docker build -f contrib/docker/Dockerfile . -t emissary ``` diff --git a/contrib/docker/Dockerfile b/contrib/docker/Dockerfile index f8e925d9b5..194941bb72 100644 --- a/contrib/docker/Dockerfile +++ b/contrib/docker/Dockerfile @@ -1,71 +1,28 @@ -ARG IMG_NAME=centos -ARG IMG_TAG=7 -FROM ${IMG_NAME}:${IMG_TAG} AS base +FROM centos:7 -ARG java_version=11 -ARG user=emissary -ARG group=emissary -ARG uid=1000 -ARG gid=1000 +RUN yum update -y \ + && rpm --import https://yum.corretto.aws/corretto.key \ + && curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo \ + && yum install -y java-11-amazon-corretto-devel \ + && yum clean all -y \ + && rm -rf /var/cache/yum -ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8 -ENV PROJECT_BASE=/opt/emissary - -RUN rpm --import https://yum.corretto.aws/corretto.key \ - && curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo \ - && yum install -y java-${java_version}-amazon-corretto-devel \ - && yum install -y which \ - && groupadd -g ${gid} ${group} \ - && useradd -u ${uid} -g ${group} -m -s /bin/bash ${user} \ - && yum clean all -y \ - && rm -rf /var/cache/yum - - - -FROM base AS build - -ARG maven_version=3.9.6 -ENV MAVEN_OPTS -Xms512M -Xmx1024M -Xss1M -Djava.awt.headless=true -ENV MAVEN_HOME /opt/maven - -RUN curl -L -o /tmp/maven.tar.gz https://dlcdn.apache.org/maven/maven-3/${maven_version}/binaries/apache-maven-${maven_version}-bin.tar.gz \ - && tar xvf /tmp/maven.tar.gz -C /opt \ - && ln -s /opt/apache-maven-${maven_version} ${MAVEN_HOME} \ - && ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn +ADD target/emissary-*-dist.tar.gz /opt -COPY . /opt/emissary -RUN chown -R ${user}:${group} /opt/emissary \ - && chmod -R 744 /opt/emissary \ - && (rm -f .mvn-classpath || true) +RUN ls -al /opt && \ + version=`ls /opt | grep emissary- | awk '{ print $1 }'` && \ + echo "Linking /opt/${version} to /opt/emissary" && \ + ln -s /opt/${version} /opt/emissary && \ + mkdir -p /opt/emissary/localoutput && \ + chmod -R a+rw /opt/emissary -USER ${user} -WORKDIR /opt/emissary -RUN --mount=type=cache,uid=${uid},gid=${gid},target=/home/${user}/.m2 \ - mvn -V -B -e -ntp "-Dstyle.color=always" clean verify -Pdist - - -FROM base - -COPY --from=build /opt/emissary/target/emissary-*-dist.tar.gz /tmp - -RUN tar -xf /tmp/emissary-*-dist.tar.gz -C /opt/ \ - && version=`ls /opt | grep emissary- | awk '{ print $1 }'` \ - && echo "Linking /opt/${version} to /opt/emissary" \ - && ln -s /opt/${version} /opt/emissary \ - && mkdir -p /opt/emissary/localoutput \ - && mkdir -p /opt/emissary/target/data \ - && chmod -R a+rw /opt/emissary \ - && chown -R ${user}:${group} /opt/emissary* \ - && rm -f /tmp/* - -USER ${user} +ENV PROJECT_BASE=/opt/emissary WORKDIR /opt/emissary -VOLUME /opt/emissary/target/data VOLUME /opt/emissary/localoutput -EXPOSE 8001 +EXPOSE 8000 8001 ENTRYPOINT ["./emissary"] diff --git a/contrib/docker/Dockerfile.centos7 b/contrib/docker/Dockerfile.centos7 new file mode 100644 index 0000000000..f8e925d9b5 --- /dev/null +++ b/contrib/docker/Dockerfile.centos7 @@ -0,0 +1,72 @@ +ARG IMG_NAME=centos +ARG IMG_TAG=7 +FROM ${IMG_NAME}:${IMG_TAG} AS base + +ARG java_version=11 +ARG user=emissary +ARG group=emissary +ARG uid=1000 +ARG gid=1000 + +ENV JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8 +ENV PROJECT_BASE=/opt/emissary + +RUN rpm --import https://yum.corretto.aws/corretto.key \ + && curl -L -o /etc/yum.repos.d/corretto.repo https://yum.corretto.aws/corretto.repo \ + && yum install -y java-${java_version}-amazon-corretto-devel \ + && yum install -y which \ + && groupadd -g ${gid} ${group} \ + && useradd -u ${uid} -g ${group} -m -s /bin/bash ${user} \ + && yum clean all -y \ + && rm -rf /var/cache/yum + + + +FROM base AS build + +ARG maven_version=3.9.6 +ENV MAVEN_OPTS -Xms512M -Xmx1024M -Xss1M -Djava.awt.headless=true +ENV MAVEN_HOME /opt/maven + +RUN curl -L -o /tmp/maven.tar.gz https://dlcdn.apache.org/maven/maven-3/${maven_version}/binaries/apache-maven-${maven_version}-bin.tar.gz \ + && tar xvf /tmp/maven.tar.gz -C /opt \ + && ln -s /opt/apache-maven-${maven_version} ${MAVEN_HOME} \ + && ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn + +COPY . /opt/emissary +RUN chown -R ${user}:${group} /opt/emissary \ + && chmod -R 744 /opt/emissary \ + && (rm -f .mvn-classpath || true) + +USER ${user} +WORKDIR /opt/emissary +RUN --mount=type=cache,uid=${uid},gid=${gid},target=/home/${user}/.m2 \ + mvn -V -B -e -ntp "-Dstyle.color=always" clean verify -Pdist + + +FROM base + +COPY --from=build /opt/emissary/target/emissary-*-dist.tar.gz /tmp + +RUN tar -xf /tmp/emissary-*-dist.tar.gz -C /opt/ \ + && version=`ls /opt | grep emissary- | awk '{ print $1 }'` \ + && echo "Linking /opt/${version} to /opt/emissary" \ + && ln -s /opt/${version} /opt/emissary \ + && mkdir -p /opt/emissary/localoutput \ + && mkdir -p /opt/emissary/target/data \ + && chmod -R a+rw /opt/emissary \ + && chown -R ${user}:${group} /opt/emissary* \ + && rm -f /tmp/* + +USER ${user} + +WORKDIR /opt/emissary + +VOLUME /opt/emissary/target/data +VOLUME /opt/emissary/localoutput + +EXPOSE 8001 + +ENTRYPOINT ["./emissary"] + +CMD ["server", "-a", "2", "-p", "8001"]