KevanSoon commited on
Commit
8b38cc3
·
1 Parent(s): 5203b31

major changes

Browse files
Dockerfile CHANGED
@@ -1,21 +1,25 @@
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"]
 
 
1
+ # Use Maven + JDK 17 image for building
2
+ FROM maven:3.9.3-eclipse-temurin-17 AS build
3
+
4
  WORKDIR /app
5
 
6
+ # Copy pom and java files
7
  COPY pom.xml .
8
+ COPY src ./src
9
 
10
+ # Build the jar
11
  RUN mvn clean package -DskipTests
12
 
13
+ # Use smaller JDK image for runtime
14
+ FROM eclipse-temurin:17-jdk-jammy
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"]
User.java DELETED
@@ -1,15 +0,0 @@
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 CHANGED
@@ -1,42 +1,67 @@
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
  <!-- Spring Boot Web -->
20
  <dependency>
21
  <groupId>org.springframework.boot</groupId>
22
  <artifactId>spring-boot-starter-web</artifactId>
23
  </dependency>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  </dependencies>
25
 
26
  <build>
27
- <!-- Look for Java files in root folder -->
28
- <sourceDirectory>${basedir}</sourceDirectory>
29
-
30
  <plugins>
31
- <!-- Spring Boot Maven Plugin -->
32
  <plugin>
33
  <groupId>org.springframework.boot</groupId>
34
  <artifactId>spring-boot-maven-plugin</artifactId>
35
- <version>3.2.5</version>
36
- <configuration>
37
- <!-- Specify main class -->
38
- <mainClass>DemoApplication</mainClass>
39
- </configuration>
40
  </plugin>
41
  </plugins>
42
  </build>
 
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
 
7
  <groupId>com.example</groupId>
8
+ <artifactId>demo</artifactId>
9
  <version>0.0.1-SNAPSHOT</version>
10
+ <packaging>jar</packaging>
11
+
12
+ <name>demo</name>
13
+ <description>Spring Boot app for Supabase</description>
14
 
15
  <parent>
16
  <groupId>org.springframework.boot</groupId>
17
  <artifactId>spring-boot-starter-parent</artifactId>
18
  <version>3.2.5</version>
19
+ <relativePath/>
20
  </parent>
21
 
22
+ <properties>
23
+ <java.version>17</java.version>
24
+ </properties>
25
+
26
  <dependencies>
27
  <!-- Spring Boot Web -->
28
  <dependency>
29
  <groupId>org.springframework.boot</groupId>
30
  <artifactId>spring-boot-starter-web</artifactId>
31
  </dependency>
32
+
33
+ <!-- Spring Data JPA -->
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>org.projectlombok</groupId>
49
+ <artifactId>lombok</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
 
60
  <build>
 
 
 
61
  <plugins>
 
62
  <plugin>
63
  <groupId>org.springframework.boot</groupId>
64
  <artifactId>spring-boot-maven-plugin</artifactId>
 
 
 
 
 
65
  </plugin>
66
  </plugins>
67
  </build>
DemoApplication.java → src/main/java/com/example/demo/DemoApplication.java RENAMED
@@ -1,18 +1,12 @@
 
 
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
  }
 
1
+ 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
  }
 
 
 
 
 
12
  }
src/main/java/com/example/demo/User.java ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 String email;
17
+
18
+ // Constructors
19
+ public User() {}
20
+ public User(String name, String email) {
21
+ this.name = name;
22
+ this.email = email;
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
+ public String getEmail() { return email; }
31
+ public void setEmail(String email) { this.email = email; }
32
+ }
target/classes/com/example/demo/DemoApplication.class ADDED
Binary file (733 Bytes). View file
 
target/classes/com/example/demo/User.class ADDED
Binary file (1.37 kB). View file