Spaces:
Sleeping
Sleeping
KevanSoon
commited on
Commit
·
86def8e
1
Parent(s):
581891c
made some local files
Browse files- DemoApplication.java +18 -0
- Dockerfile +8 -28
- User.java +15 -0
- pom.xml +34 -0
- target/maven-archiver/pom.properties +3 -0
- target/springboot-hf-0.0.1-SNAPSHOT.jar +0 -0
- target/springboot-hf-0.0.1-SNAPSHOT.jar.original +0 -0
DemoApplication.java
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import org.springframework.boot.SpringApplication;
|
| 2 |
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 3 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
| 4 |
+
import org.springframework.web.bind.annotation.RestController;
|
| 5 |
+
|
| 6 |
+
@SpringBootApplication
|
| 7 |
+
@RestController
|
| 8 |
+
public class DemoApplication {
|
| 9 |
+
|
| 10 |
+
public static void main(String[] args) {
|
| 11 |
+
SpringApplication.run(DemoApplication.class, args);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
@GetMapping("/user")
|
| 15 |
+
public User getUser() {
|
| 16 |
+
return new User("Kevan", 21);
|
| 17 |
+
}
|
| 18 |
+
}
|
Dockerfile
CHANGED
|
@@ -1,41 +1,21 @@
|
|
| 1 |
-
# Stage 1:
|
| 2 |
FROM maven:3.9.6-eclipse-temurin-17 AS build
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 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 |
-
#
|
| 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
|
| 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"]
|
|
|
|
| 1 |
+
# Stage 1: Build Spring Boot app
|
| 2 |
FROM maven:3.9.6-eclipse-temurin-17 AS build
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Copy pom.xml and Java files
|
| 6 |
+
COPY pom.xml .
|
| 7 |
+
COPY *.java ./
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Build the JAR
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
RUN mvn clean package -DskipTests
|
| 11 |
|
| 12 |
+
# Stage 2: Run Spring Boot
|
| 13 |
FROM openjdk:17-jdk-slim
|
| 14 |
WORKDIR /app
|
| 15 |
+
|
| 16 |
+
# Copy the JAR from build stage
|
| 17 |
COPY --from=build /app/target/*.jar app.jar
|
| 18 |
|
|
|
|
| 19 |
EXPOSE 7860
|
| 20 |
|
| 21 |
ENTRYPOINT ["java","-jar","app.jar","--server.port=7860"]
|
User.java
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
public class User {
|
| 2 |
+
private String name;
|
| 3 |
+
private int age;
|
| 4 |
+
|
| 5 |
+
public User(String name, int age) {
|
| 6 |
+
this.name = name;
|
| 7 |
+
this.age = age;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
public String getName() { return name; }
|
| 11 |
+
public int getAge() { return age; }
|
| 12 |
+
|
| 13 |
+
public void setName(String name) { this.name = name; }
|
| 14 |
+
public void setAge(int age) { this.age = age; }
|
| 15 |
+
}
|
pom.xml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
| 2 |
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
| 3 |
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
| 4 |
+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
| 5 |
+
|
| 6 |
+
<modelVersion>4.0.0</modelVersion>
|
| 7 |
+
|
| 8 |
+
<groupId>com.example</groupId>
|
| 9 |
+
<artifactId>springboot-hf</artifactId>
|
| 10 |
+
<version>0.0.1-SNAPSHOT</version>
|
| 11 |
+
|
| 12 |
+
<parent>
|
| 13 |
+
<groupId>org.springframework.boot</groupId>
|
| 14 |
+
<artifactId>spring-boot-starter-parent</artifactId>
|
| 15 |
+
<version>3.2.5</version>
|
| 16 |
+
</parent>
|
| 17 |
+
|
| 18 |
+
<dependencies>
|
| 19 |
+
<dependency>
|
| 20 |
+
<groupId>org.springframework.boot</groupId>
|
| 21 |
+
<artifactId>spring-boot-starter-web</artifactId>
|
| 22 |
+
</dependency>
|
| 23 |
+
</dependencies>
|
| 24 |
+
|
| 25 |
+
<build>
|
| 26 |
+
<plugins>
|
| 27 |
+
<plugin>
|
| 28 |
+
<groupId>org.springframework.boot</groupId>
|
| 29 |
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
| 30 |
+
</plugin>
|
| 31 |
+
</plugins>
|
| 32 |
+
</build>
|
| 33 |
+
|
| 34 |
+
</project>
|
target/maven-archiver/pom.properties
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
artifactId=springboot-hf
|
| 2 |
+
groupId=com.example
|
| 3 |
+
version=0.0.1-SNAPSHOT
|
target/springboot-hf-0.0.1-SNAPSHOT.jar
ADDED
|
Binary file (22 Bytes). View file
|
|
|
target/springboot-hf-0.0.1-SNAPSHOT.jar.original
ADDED
|
Binary file (1.6 kB). View file
|
|
|