Spaces:
Sleeping
Sleeping
KevanSoon
commited on
Commit
·
437b610
1
Parent(s):
a1f4435
changed dockerfile
Browse files- Dockerfile +27 -13
Dockerfile
CHANGED
|
@@ -2,27 +2,41 @@ FROM eclipse-temurin:17-jdk AS build
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
RUN
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
COPY DemoApplication.java User.java ./
|
| 11 |
|
| 12 |
-
# Compile
|
| 13 |
-
RUN javac -cp "
|
| 14 |
jar cfe app.jar DemoApplication *.class
|
| 15 |
|
| 16 |
-
# Runtime image
|
| 17 |
FROM eclipse-temurin:17-jre
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
-
# Copy
|
| 21 |
COPY --from=build /app/app.jar .
|
| 22 |
-
COPY --from=build /app/
|
| 23 |
-
COPY --from=build /app/gson.jar .
|
| 24 |
|
| 25 |
EXPOSE 8080
|
| 26 |
|
| 27 |
-
|
| 28 |
-
CMD ["java", "-cp", "app.jar:javalin.jar:gson.jar", "DemoApplication"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install Maven just for dependency fetching
|
| 6 |
+
RUN apt-get update && apt-get install -y maven curl && rm -rf /var/lib/apt/lists/*
|
| 7 |
+
|
| 8 |
+
# Create a minimal pom.xml to fetch Javalin + Gson
|
| 9 |
+
RUN echo '<project xmlns="http://maven.apache.org/POM/4.0.0" \
|
| 10 |
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
|
| 11 |
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 \
|
| 12 |
+
http://maven.apache.org/xsd/maven-4.0.0.xsd"> \
|
| 13 |
+
<modelVersion>4.0.0</modelVersion> \
|
| 14 |
+
<groupId>com.example</groupId> \
|
| 15 |
+
<artifactId>javalin-demo</artifactId> \
|
| 16 |
+
<version>1.0</version> \
|
| 17 |
+
<dependencies> \
|
| 18 |
+
<dependency><groupId>io.javalin</groupId><artifactId>javalin</artifactId><version>5.6.1</version></dependency> \
|
| 19 |
+
<dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.10.1</version></dependency> \
|
| 20 |
+
</dependencies> \
|
| 21 |
+
</project>' > pom.xml
|
| 22 |
+
|
| 23 |
+
# Download dependencies into /root/.m2/repository
|
| 24 |
+
RUN mvn dependency:copy-dependencies -DoutputDirectory=libs
|
| 25 |
+
|
| 26 |
+
# Copy source
|
| 27 |
COPY DemoApplication.java User.java ./
|
| 28 |
|
| 29 |
+
# Compile with all dependencies
|
| 30 |
+
RUN javac -cp "libs/*" DemoApplication.java User.java && \
|
| 31 |
jar cfe app.jar DemoApplication *.class
|
| 32 |
|
|
|
|
| 33 |
FROM eclipse-temurin:17-jre
|
| 34 |
WORKDIR /app
|
| 35 |
|
| 36 |
+
# Copy compiled JAR + libraries
|
| 37 |
COPY --from=build /app/app.jar .
|
| 38 |
+
COPY --from=build /app/libs ./libs
|
|
|
|
| 39 |
|
| 40 |
EXPOSE 8080
|
| 41 |
|
| 42 |
+
CMD ["java", "-cp", "app.jar:libs/*", "DemoApplication"]
|
|
|