Skip to content

Instantly share code, notes, and snippets.

@pgilad pgilad/Dockerfile
Last active Aug 18, 2019

Embed
What would you like to do?
Minimal Spring Boot 2 on Docker Alpine with Java 11 (Using Jigsaw modules)
plugins {
id 'java'
id 'idea'
id 'jacoco'
id 'org.springframework.boot' version '2.0.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'io.franzbecker.gradle-lombok' version '1.14'
id 'com.github.ben-manes.versions' version '0.20.0'
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
springBoot {
mainClassName = 'com.blazemeter.dagger.DaggerApplication'
buildInfo()
}
lombok {
version = '1.18.2'
sha256 = ''
}
jacoco {
toolVersion = '0.8.2'
}
jacocoTestReport {
reports {
xml.enabled = true
html.enabled = true
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
compile 'org.springframework.boot:spring-boot-starter-webflux'
compile 'org.springframework.boot:spring-boot-starter-jetty'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.hdrhistogram:HdrHistogram:2.1.10'
compile 'org.springframework.boot:spring-boot-devtools'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'io.projectreactor:reactor-test'
// required for mockito to mock private/final methods
testCompile 'net.bytebuddy:byte-buddy:1.8.22'
}
FROM alpine:3.8 AS builder
WORKDIR /opt
ARG JDK_TAR=openjdk-11+28_linux-x64-musl_bin.tar.gz
ARG JDK_DOWNLOAD_PREFIX=https://download.java.net/java/early_access/alpine/28/binaries
RUN wget -q "$JDK_DOWNLOAD_PREFIX/$JDK_TAR" && \
wget -q "$JDK_DOWNLOAD_PREFIX/$JDK_TAR.sha256"
RUN cat $JDK_TAR.sha256 | xargs -I{} echo "{} $JDK_TAR" | sha256sum -c - && \
tar zxf "$JDK_TAR" && \
ln -s jdk-11 java && \
rm -f "$JDK_TAR" "$JDK_TAR.sha256"
ENV JAVA_HOME=/opt/java
ENV PATH="$PATH:$JAVA_HOME/bin"
WORKDIR /root/dev
ENV GRADLE_USER_HOME=/root/dev/.cache
RUN mkdir -p /root/dev/.cache
COPY build.gradle gradlew gradlew.bat settings.gradle gradle.properties /root/dev/
COPY gradle /root/dev/gradle
RUN ./gradlew --no-daemon --refresh-dependencies --version
COPY src ./src
RUN ./gradlew --no-daemon build
# Make sure only 1 jar file is assembled
RUN test $(find ./build/libs -type f -name '*.jar' | wc -l) -eq 1
RUN jlink \
--verbose \
--module-path "$JAVA_HOME/jmods" \
--add-modules java.base,java.logging,java.xml,jdk.unsupported,java.sql,java.naming,java.desktop,java.management,java.security.jgss,java.instrument,jdk.management \
--compress 2 \
--no-header-files \
--no-man-pages \
--strip-debug \
--output /opt/jre
FROM alpine:3.8
WORKDIR /usr/src/app
ENV JAVA_HOME=/opt/jre
ENV LANG=C.UTF-8
ENV PATH="$PATH:$JAVA_HOME/bin"
ENV APP_TIMEZONE=UTC
COPY --from=builder /opt/jre /opt/jre
COPY --from=builder /root/dev/build/libs/*.jar dagger.jar
COPY newrelic/newrelic.jar newrelic/newrelic.yml ./
EXPOSE 80
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "dagger.jar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.