Created
July 18, 2020 23:10
-
-
Save ehabqadah/8fa295528eb8b9e57c0cfcf5bc8cde96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build layer | |
FROM maven:3.6.3-adoptopenjdk-11 as build | |
LABEL maintainer="ehabqadah@gmail.com" | |
ARG GIT_COMMIT | |
ARG ENVIRONMENT | |
LABEL service=demo \ | |
stage=build \ | |
tag=${GIT_COMMIT}\ | |
env=${ENVIRONMENT} | |
RUN mkdir /ms | |
WORKDIR /ms | |
# Copy the source code to build it | |
COPY ./pom.xml ./pom.xml | |
COPY ./src ./src | |
# Build the executable jar (Spring Boot fat jar) | |
RUN mvn clean package -DskipTests=true \ | |
&& mv ./target/demo.jar ./ms.jar | |
# Deployment layer | |
FROM adoptopenjdk:11-jre-hotspot | |
LABEL maintainer="ehabqadah@gmail.com" | |
ARG GIT_COMMIT | |
ARG ENVIRONMENT | |
LABEL service=demo \ | |
stage=deploy \ | |
tag=${GIT_COMMIT}\ | |
env=${ENVIRONMENT} | |
# Add a non-root user user an | |
RUN addgroup -gid 1009 udemo \ | |
&& adduser -uid 1009 -gid 1009 --gecos "udemo udemo,udemo,udemo,udemo" --disabled-password udemo \ | |
&& mkdir -p /ms && chown -R udemo:udemo /ms | |
WORKDIR /ms | |
COPY --chown=udemo:udemo --from=build /ms/ms.jar ./ms.jar | |
# Set udemo it as the current user (instead of root) | |
USER udemo | |
EXPOSE 9090 | |
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","./ms.jar"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment