Spaces:
Sleeping
Sleeping
KevanSoon
commited on
Commit
·
581891c
1
Parent(s):
b10c8c6
initialize a java dockerfile
Browse files- Dockerfile +27 -9
Dockerfile
CHANGED
|
@@ -1,23 +1,41 @@
|
|
| 1 |
-
# Stage 1:
|
| 2 |
FROM maven:3.9.6-eclipse-temurin-17 AS build
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
RUN mvn clean package -DskipTests
|
| 11 |
|
| 12 |
# Stage 2: Run the app
|
| 13 |
FROM openjdk:17-jdk-slim
|
| 14 |
WORKDIR /app
|
| 15 |
-
|
| 16 |
-
# Copy the JAR from the build stage
|
| 17 |
COPY --from=build /app/target/*.jar app.jar
|
| 18 |
|
| 19 |
-
# Hugging Face
|
| 20 |
EXPOSE 7860
|
| 21 |
|
| 22 |
-
# Run Spring Boot on port 7860
|
| 23 |
ENTRYPOINT ["java","-jar","app.jar","--server.port=7860"]
|
|
|
|
| 1 |
+
# Stage 1: Generate and build Spring Boot app
|
| 2 |
FROM maven:3.9.6-eclipse-temurin-17 AS build
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Create a minimal pom.xml
|
| 6 |
+
RUN printf '<project xmlns="http://maven.apache.org/POM/4.0.0" \
|
| 7 |
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
|
| 8 |
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 \
|
| 9 |
+
http://maven.apache.org/xsd/maven-4.0.0.xsd"> \
|
| 10 |
+
<modelVersion>4.0.0</modelVersion> \
|
| 11 |
+
<groupId>com.example</groupId> \
|
| 12 |
+
<artifactId>springboot-hf</artifactId> \
|
| 13 |
+
<version>0.0.1-SNAPSHOT</version> \
|
| 14 |
+
<parent><groupId>org.springframework.boot</groupId> \
|
| 15 |
+
<artifactId>spring-boot-starter-parent</artifactId> \
|
| 16 |
+
<version>3.2.5</version></parent> \
|
| 17 |
+
<dependencies><dependency> \
|
| 18 |
+
<groupId>org.springframework.boot</groupId> \
|
| 19 |
+
<artifactId>spring-boot-starter-web</artifactId> \
|
| 20 |
+
</dependency></dependencies> \
|
| 21 |
+
<build><plugins><plugin> \
|
| 22 |
+
<groupId>org.springframework.boot</groupId> \
|
| 23 |
+
<artifactId>spring-boot-maven-plugin</artifactId> \
|
| 24 |
+
</plugin></plugins></build></project>' > pom.xml
|
| 25 |
|
| 26 |
+
# Create minimal Hello World application
|
| 27 |
+
RUN mkdir -p src/main/java/com/example/demo && \
|
| 28 |
+
printf 'package com.example.demo;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@SpringBootApplication\n@RestController\npublic class DemoApplication {\n public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);} \n\n @GetMapping("/")\n public String hello(){return "Hello from Spring Boot on Hugging Face Spaces 🚀";}\n}' > src/main/java/com/example/demo/DemoApplication.java
|
| 29 |
+
|
| 30 |
+
# Build the jar
|
| 31 |
RUN mvn clean package -DskipTests
|
| 32 |
|
| 33 |
# Stage 2: Run the app
|
| 34 |
FROM openjdk:17-jdk-slim
|
| 35 |
WORKDIR /app
|
|
|
|
|
|
|
| 36 |
COPY --from=build /app/target/*.jar app.jar
|
| 37 |
|
| 38 |
+
# Hugging Face requires port 7860
|
| 39 |
EXPOSE 7860
|
| 40 |
|
|
|
|
| 41 |
ENTRYPOINT ["java","-jar","app.jar","--server.port=7860"]
|