Spaces:
Sleeping
Sleeping
KevanSoon
commited on
Commit
·
f3bb92a
1
Parent(s):
8b38cc3
made some local files
Browse files
Dockerfile
CHANGED
|
@@ -1,25 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
FROM maven:3.9.3-eclipse-temurin-17 AS build
|
| 3 |
-
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
-
# Copy pom and
|
| 7 |
COPY pom.xml .
|
| 8 |
COPY src ./src
|
| 9 |
|
| 10 |
# Build the jar
|
| 11 |
RUN mvn clean package -DskipTests
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
FROM eclipse-temurin:17-
|
| 15 |
-
|
| 16 |
WORKDIR /app
|
| 17 |
-
|
| 18 |
-
# Copy jar from build stage
|
| 19 |
COPY --from=build /app/target/demo-0.0.1-SNAPSHOT.jar app.jar
|
| 20 |
-
|
| 21 |
-
# Expose default Spring Boot port
|
| 22 |
EXPOSE 8080
|
| 23 |
-
|
| 24 |
-
# Run the jar
|
| 25 |
-
ENTRYPOINT ["java","-jar","app.jar"]
|
|
|
|
| 1 |
+
FROM maven:3.9.4-eclipse-temurin-17 AS build
|
|
|
|
|
|
|
| 2 |
WORKDIR /app
|
| 3 |
|
| 4 |
+
# Copy pom and source code
|
| 5 |
COPY pom.xml .
|
| 6 |
COPY src ./src
|
| 7 |
|
| 8 |
# Build the jar
|
| 9 |
RUN mvn clean package -DskipTests
|
| 10 |
|
| 11 |
+
# Run stage
|
| 12 |
+
FROM eclipse-temurin:17-jre
|
|
|
|
| 13 |
WORKDIR /app
|
|
|
|
|
|
|
| 14 |
COPY --from=build /app/target/demo-0.0.1-SNAPSHOT.jar app.jar
|
|
|
|
|
|
|
| 15 |
EXPOSE 8080
|
| 16 |
+
ENTRYPOINT ["java", "-jar", "app.jar"]
|
|
|
|
|
|
pom.xml
CHANGED
|
@@ -1,16 +1,15 @@
|
|
| 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 |
-
|
| 5 |
<modelVersion>4.0.0</modelVersion>
|
| 6 |
-
|
| 7 |
<groupId>com.example</groupId>
|
| 8 |
<artifactId>demo</artifactId>
|
| 9 |
<version>0.0.1-SNAPSHOT</version>
|
| 10 |
<packaging>jar</packaging>
|
| 11 |
|
| 12 |
-
<name>
|
| 13 |
-
<description>Spring Boot
|
| 14 |
|
| 15 |
<parent>
|
| 16 |
<groupId>org.springframework.boot</groupId>
|
|
@@ -29,31 +28,11 @@
|
|
| 29 |
<groupId>org.springframework.boot</groupId>
|
| 30 |
<artifactId>spring-boot-starter-web</artifactId>
|
| 31 |
</dependency>
|
| 32 |
-
|
| 33 |
-
<!--
|
| 34 |
-
<dependency>
|
| 35 |
-
<groupId>org.springframework.boot</groupId>
|
| 36 |
-
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
| 37 |
-
</dependency>
|
| 38 |
-
|
| 39 |
-
<!-- PostgreSQL driver (for Supabase) -->
|
| 40 |
-
<dependency>
|
| 41 |
-
<groupId>org.postgresql</groupId>
|
| 42 |
-
<artifactId>postgresql</artifactId>
|
| 43 |
-
<scope>runtime</scope>
|
| 44 |
-
</dependency>
|
| 45 |
-
|
| 46 |
-
<!-- Optional: Lombok -->
|
| 47 |
<dependency>
|
| 48 |
-
<groupId>
|
| 49 |
-
<artifactId>
|
| 50 |
-
<optional>true</optional>
|
| 51 |
-
</dependency>
|
| 52 |
-
|
| 53 |
-
<dependency>
|
| 54 |
-
<groupId>org.springframework.boot</groupId>
|
| 55 |
-
<artifactId>spring-boot-starter-test</artifactId>
|
| 56 |
-
<scope>test</scope>
|
| 57 |
</dependency>
|
| 58 |
</dependencies>
|
| 59 |
|
|
@@ -65,5 +44,4 @@
|
|
| 65 |
</plugin>
|
| 66 |
</plugins>
|
| 67 |
</build>
|
| 68 |
-
|
| 69 |
</project>
|
|
|
|
| 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 |
<modelVersion>4.0.0</modelVersion>
|
|
|
|
| 6 |
<groupId>com.example</groupId>
|
| 7 |
<artifactId>demo</artifactId>
|
| 8 |
<version>0.0.1-SNAPSHOT</version>
|
| 9 |
<packaging>jar</packaging>
|
| 10 |
|
| 11 |
+
<name>springboot-hf</name>
|
| 12 |
+
<description>Spring Boot HF Space Example</description>
|
| 13 |
|
| 14 |
<parent>
|
| 15 |
<groupId>org.springframework.boot</groupId>
|
|
|
|
| 28 |
<groupId>org.springframework.boot</groupId>
|
| 29 |
<artifactId>spring-boot-starter-web</artifactId>
|
| 30 |
</dependency>
|
| 31 |
+
|
| 32 |
+
<!-- Optional: for JSON serialization -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
<dependency>
|
| 34 |
+
<groupId>com.fasterxml.jackson.core</groupId>
|
| 35 |
+
<artifactId>jackson-databind</artifactId>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</dependency>
|
| 37 |
</dependencies>
|
| 38 |
|
|
|
|
| 44 |
</plugin>
|
| 45 |
</plugins>
|
| 46 |
</build>
|
|
|
|
| 47 |
</project>
|
src/main/java/com/example/demo/DemoApplication.java
CHANGED
|
@@ -2,10 +2,18 @@ package com.example.demo;
|
|
| 2 |
|
| 3 |
import org.springframework.boot.SpringApplication;
|
| 4 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
|
|
| 5 |
|
| 6 |
@SpringBootApplication
|
|
|
|
| 7 |
public class DemoApplication {
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
public static void main(String[] args) {
|
| 10 |
SpringApplication.run(DemoApplication.class, args);
|
| 11 |
}
|
|
|
|
| 2 |
|
| 3 |
import org.springframework.boot.SpringApplication;
|
| 4 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
| 5 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
| 6 |
+
import org.springframework.web.bind.annotation.RestController;
|
| 7 |
|
| 8 |
@SpringBootApplication
|
| 9 |
+
@RestController
|
| 10 |
public class DemoApplication {
|
| 11 |
|
| 12 |
+
@GetMapping("/user")
|
| 13 |
+
public User getUser() {
|
| 14 |
+
return new User("Kevan", 21);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
public static void main(String[] args) {
|
| 18 |
SpringApplication.run(DemoApplication.class, args);
|
| 19 |
}
|
src/main/java/com/example/demo/User.java
CHANGED
|
@@ -1,32 +1,19 @@
|
|
| 1 |
package com.example.demo;
|
| 2 |
|
| 3 |
-
import jakarta.persistence.Entity;
|
| 4 |
-
import jakarta.persistence.GeneratedValue;
|
| 5 |
-
import jakarta.persistence.GenerationType;
|
| 6 |
-
import jakarta.persistence.Id;
|
| 7 |
-
|
| 8 |
-
@Entity
|
| 9 |
public class User {
|
| 10 |
-
|
| 11 |
-
@Id
|
| 12 |
-
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
| 13 |
-
private Long id;
|
| 14 |
-
|
| 15 |
private String name;
|
| 16 |
-
private
|
| 17 |
|
| 18 |
-
// Constructors
|
| 19 |
public User() {}
|
| 20 |
-
|
|
|
|
| 21 |
this.name = name;
|
| 22 |
-
this.
|
| 23 |
}
|
| 24 |
|
| 25 |
-
// Getters and setters
|
| 26 |
-
public Long getId() { return id; }
|
| 27 |
-
public void setId(Long id) { this.id = id; }
|
| 28 |
public String getName() { return name; }
|
| 29 |
public void setName(String name) { this.name = name; }
|
| 30 |
-
|
| 31 |
-
public
|
|
|
|
| 32 |
}
|
|
|
|
| 1 |
package com.example.demo;
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
public class User {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
private String name;
|
| 5 |
+
private int age;
|
| 6 |
|
|
|
|
| 7 |
public User() {}
|
| 8 |
+
|
| 9 |
+
public User(String name, int age) {
|
| 10 |
this.name = name;
|
| 11 |
+
this.age = age;
|
| 12 |
}
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
public String getName() { return name; }
|
| 15 |
public void setName(String name) { this.name = name; }
|
| 16 |
+
|
| 17 |
+
public int getAge() { return age; }
|
| 18 |
+
public void setAge(int age) { this.age = age; }
|
| 19 |
}
|
target/classes/com/example/demo/DemoApplication.class
CHANGED
|
Binary files a/target/classes/com/example/demo/DemoApplication.class and b/target/classes/com/example/demo/DemoApplication.class differ
|
|
|
target/classes/com/example/demo/User.class
CHANGED
|
Binary files a/target/classes/com/example/demo/User.class and b/target/classes/com/example/demo/User.class differ
|
|
|