Skip to content

Commit

Permalink
Use official alpine image with JDK11
Browse files Browse the repository at this point in the history
This image is available in multiple architectures, i.e. arm64 and x86_64
Also create minimal JRE to use in final image.

Fixs #313
  • Loading branch information
afranken committed Nov 25, 2021
1 parent 791678e commit a31c955
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
45 changes: 19 additions & 26 deletions docker/src/main/docker/Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,36 @@
# limitations under the License.
#

FROM adoptopenjdk/openjdk11:${adoptopenjdk11.image.version} as staging_area
FROM alpine:3.15.0 as staging_area

# create a minimal jdk assembly with those modules that we need
RUN jlink \
--module-path $JAVA_HOME/jmods \
RUN apk --no-cache add openjdk11-jdk openjdk11-jmods

ENV JAVA_MINIMAL="/opt/java-minimal"

# build minimal JRE
RUN /usr/lib/jvm/java-11-openjdk/bin/jlink \
--verbose \
--add-modules java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument \
--compress 2 \
--no-header-files \
--no-man-pages \
--strip-debug \
--output /target/opt/jdk-minimal

# add libz* files, so that we don't have to re-install that (not included in alpine-glibc)
RUN mkdir -p /target/usr/glibc-compat/lib; \
cp /usr/glibc-compat/lib/libz* /target/usr/glibc-compat/lib
--output "$JAVA_MINIMAL"

#
# build the actual image
#
FROM frolvlad/alpine-glibc:${alpine-glibc.image.version}
FROM alpine:3.15.0

# copy files prepared in the other container
COPY --from=staging_area /target /
ENV JAVA_HOME=/opt/java-minimal
ENV PATH="$PATH:$JAVA_HOME/bin"

# rebuild ld.so.cache to add libz
RUN /usr/glibc-compat/sbin/ldconfig
COPY --from=staging_area "$JAVA_HOME" "$JAVA_HOME"
COPY ./target/s3mock-exec.jar s3mock.jar

ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8 \
JAVA_HOME=/opt/jdk-minimal \
PATH="$PATH:/opt/jdk-minimal/bin" \
root=/s3mockroot
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV root=/s3mockroot

EXPOSE 9090 9191

COPY maven /opt/

ENTRYPOINT java -XX:+UseContainerSupport -Xmx128m --illegal-access=warn -Djava.security.egd=file:/dev/./urandom -jar /opt/service/*.jar
# run the app on startup
ENTRYPOINT java -XX:+UseContainerSupport -Xmx128m --illegal-access=warn -Djava.security.egd=file:/dev/./urandom -jar s3mock.jar
45 changes: 29 additions & 16 deletions docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,7 @@
<alias>s3mock</alias>
<name>${docker.image.name}</name>
<build>
<dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
<assembly>
<basedir>/opt</basedir>
<inline>
<dependencySets>
<dependencySet>
<includes>
<include>com.adobe.testing:s3mock</include>
</includes>
<outputDirectory>service</outputDirectory>
<fileMode>755</fileMode>
</dependencySet>
</dependencySets>
</inline>
<mode>dir</mode>
</assembly>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
<tags>
<tag>${project.version}</tag>
<tag>latest</tag>
Expand All @@ -82,6 +67,34 @@
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.adobe.testing</groupId>
<artifactId>s3mock</artifactId>
<classifier>exec</classifier>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
<destFileName>s3mock-exec.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>

<adoptopenjdk11.image.version>jdk-11.0.11_9-alpine</adoptopenjdk11.image.version>
<alpine-glibc.image.version>alpine-3.13_glibc-2.33</alpine-glibc.image.version>
<docker.image.name>adobe/s3mock</docker.image.name>
<!-- Run Docker build by default -->
<skipDocker>false</skipDocker>
Expand Down

0 comments on commit a31c955

Please sign in to comment.