Skip to content

Instantly share code, notes, and snippets.

@jeffersonbezerra
Last active June 19, 2019 22:23
Show Gist options
  • Save jeffersonbezerra/6abe44d57b886c2b19f9a50d8a9ce04d to your computer and use it in GitHub Desktop.
Save jeffersonbezerra/6abe44d57b886c2b19f9a50d8a9ce04d to your computer and use it in GitHub Desktop.
Dockerfile with mvn spotify plugin
#AZUL/ZULU(Alpine) is compiled in muslm, so it can run directly in alpine
FROM azul/zulu-openjdk-alpine:12.0.1 as generateJreMinimal
#This command creates a partial JRE with a selected set of modules.
RUN jlink \
--add-modules java.sql,java.naming,java.management,java.instrument,java.security.jgss,java.desktop,jdk.unsupported \
--verbose \
--strip-debug \
--compress 2 \
--no-header-files \
--no-man-pages \
--output /opt/jre-minimal \
--module-path /opt/java/openjdk/jmods
FROM alpine:3.8
MAINTAINER Jefferson Bezerra <[email protected]>
#Creates a new user and disables the root
RUN addgroup -g 1000 -S appuser && \
adduser -u 1000 -S appuser -G appuser && \
mkdir -p /var/log/fserv && \
chown appuser:appuser -R /var/log/fserv && chmod 666 /var/log/fserv && \
sed -i -e 's/^root::/root:!:/' /etc/shadow
USER appuser
COPY --from=generateJreMinimal /opt/jre-minimal /opt/jre-minimal
ENV LANG=C.UTF-8 \
PATH="$PATH:/opt/jre-minimal/bin:/var/lib/app-configs"
#I used maven-dependency-plugin to unpack the fatjar
COPY --chown=appuser:appuser target/dependency/BOOT-INF/lib /home/appuser/app/lib
COPY --chown=appuser:appuser target/dependency/META-INF /home/appuser/app/META-INF
COPY --chown=appuser:appuser target/dependency/BOOT-INF/classes /home/appuser/app/
COPY --chown=appuser:appuser target/dependency/BOOT-INF/classes/u63d/ /var/lib/app-configs/u63d/
WORKDIR /home/appuser/app
VOLUME ["/var/log/appLogFolder"]
EXPOSE 8080
ENTRYPOINT ["java","-cp",".:./lib/*","com.example.demo.DemoApplication"]
@jeffersonbezerra
Copy link
Author

jeffersonbezerra commented Apr 1, 2019

<properties>
    <java.version>12</java.version>
    <docker.image.prefix>jeffersonbezerra</docker.image.prefix>
</properties>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>package</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.4.9</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>${docker.image.prefix}/${project.artifactId}</repository>
        <tag>${project.version}</tag>
    </configuration>
</plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment