Skip to content

Commit 70bfacd

Browse files
committed
Added postgres to k8
1 parent 79c0c92 commit 70bfacd

13 files changed

Lines changed: 162 additions & 56 deletions

File tree

k8s/loanservice-deployment.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ spec:
2121
- containerPort: 8082
2222
env:
2323
- name: SPRING_DATASOURCE_URL
24-
value: jdbc:postgresql://host.docker.internal:5432/postgres
24+
value: jdbc:postgresql://postgres-service:5432/p2p_loandb
2525
- name: SPRING_DATASOURCE_USERNAME
26-
value: postgres
26+
valueFrom:
27+
secretKeyRef:
28+
name: postgres-secret
29+
key: SPRING_DATASOURCE_USERNAME
2730
- name: SPRING_DATASOURCE_PASSWORD
28-
value: root
31+
valueFrom:
32+
secretKeyRef:
33+
name: postgres-secret
34+
key: SPRING_DATASOURCE_PASSWORD
35+
- name: SPRING_JPA_HIBERNATE_DDL_AUTO
36+
value: update
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: postgres
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: postgres
10+
template:
11+
metadata:
12+
labels:
13+
app: postgres
14+
spec:
15+
containers:
16+
- name: postgres
17+
image: postgres:15
18+
ports:
19+
- containerPort: 5432
20+
env:
21+
- name: POSTGRES_DB
22+
value: p2p_fintech
23+
- name: POSTGRES_USER
24+
valueFrom:
25+
secretKeyRef:
26+
name: postgres-secret
27+
key: SPRING_DATASOURCE_USERNAME
28+
- name: POSTGRES_PASSWORD
29+
valueFrom:
30+
secretKeyRef:
31+
name: postgres-secret
32+
key: SPRING_DATASOURCE_PASSWORD
33+
volumeMounts:
34+
- name: postgres-storage
35+
mountPath: /var/lib/postgresql/data
36+
volumes:
37+
- name: postgres-storage
38+
persistentVolumeClaim:
39+
claimName: postgres-pvc

k8s/postgres/postgres-pv.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: postgres-pv
5+
spec:
6+
capacity:
7+
storage: 1Gi
8+
accessModes:
9+
- ReadWriteOnce
10+
hostPath:
11+
path: "/data/postgres"

k8s/postgres/postgres-pvc.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: postgres-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 1Gi

k8s/postgres/postgres-secret.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: postgres-secret
5+
type: Opaque
6+
data:
7+
SPRING_DATASOURCE_USERNAME: cG9zdGdyZXM= # base64 of 'username'
8+
SPRING_DATASOURCE_PASSWORD: UHJhdGlrQDEyMw== # base64 of 'passwrod'

k8s/postgres/postgres-service.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: postgres-service
5+
spec:
6+
type: ClusterIP
7+
selector:
8+
app: postgres
9+
ports:
10+
- port: 5432
11+
targetPort: 5432

k8s/userservice-deployment.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,17 @@ spec:
2020
ports:
2121
- containerPort: 8081
2222
env:
23-
- name: SPRING_PROFILES_ACTIVE
24-
value: production
23+
- name: SPRING_DATASOURCE_URL
24+
value: jdbc:postgresql://postgres-service:5432/p2p_loandb
25+
- name: SPRING_DATASOURCE_USERNAME
26+
valueFrom:
27+
secretKeyRef:
28+
name: postgres-secret
29+
key: SPRING_DATASOURCE_USERNAME
30+
- name: SPRING_DATASOURCE_PASSWORD
31+
valueFrom:
32+
secretKeyRef:
33+
name: postgres-secret
34+
key: SPRING_DATASOURCE_PASSWORD
35+
- name: SPRING_JPA_HIBERNATE_DDL_AUTO
36+
value: update

loanservice/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ build/
3131

3232
### VS Code ###
3333
.vscode/
34+
35+
/src/main/resources/application.properties
36+
k8s/postgres/postgres-secret.yaml

loanservice/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
1+
# Stage 1: Build
22
FROM eclipse-temurin:17-jdk-jammy AS build
33

44
WORKDIR /app
55

6+
# Copy everything for Maven context
67
COPY . .
78

9+
# Grant permission to mvnw
810
RUN chmod +x mvnw
911

10-
RUN ./mvnw -pl loanservice dependency:go-offline
11-
12-
COPY loanservice/src src
12+
# Download dependencies
13+
RUN ./mvnw dependency:go-offline
1314

14-
RUN ./mvnw -pl loanservice -am clean package -DskipTests
15+
# Build the fat JAR
16+
RUN ./mvnw clean package -DskipTests
1517

18+
# Stage 2: Run
1619
FROM eclipse-temurin:17-jre-jammy
17-
WORKDIR /app
1820

21+
WORKDIR /app
1922

20-
COPY --from=build /app/loanservice/target/*.jar app.jar
23+
# Copy fat JAR
24+
COPY --from=build /app/loanservice/target/loanservice-0.0.1-SNAPSHOT.jar app.jar
2125

2226
EXPOSE 8082
2327

loanservice/pom.xml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,42 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
55

66
<modelVersion>4.0.0</modelVersion>
7-
87
<parent>
9-
<groupId>com.p2plending</groupId>
10-
<artifactId>fintech-platform</artifactId>
11-
<version>1.0.0-SNAPSHOT</version>
12-
<relativePath>../pom.xml</relativePath> <!-- adjust if needed -->
8+
<groupId>org.springframework.boot</groupId>
9+
<artifactId>spring-boot-starter-parent</artifactId>
10+
<version>3.5.0</version>
11+
<relativePath/> <!-- lookup parent from repository -->
1312
</parent>
14-
13+
<groupId>com.p2plending</groupId>
1514
<artifactId>loanservice</artifactId>
1615
<version>0.0.1-SNAPSHOT</version>
1716
<name>loanservice</name>
18-
<description>Loan Service for P2P Lending</description>
17+
<description>Loan Service</description>
1918

2019
<properties>
2120
<java.version>17</java.version>
2221
</properties>
2322

2423
<dependencies>
25-
<!-- Spring Boot starters -->
24+
<!-- Spring Boot Starters -->
2625
<dependency>
2726
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-data-jpa</artifactId>
27+
<artifactId>spring-boot-starter-web</artifactId>
2928
</dependency>
3029
<dependency>
3130
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-security</artifactId>
31+
<artifactId>spring-boot-starter-data-jpa</artifactId>
3332
</dependency>
3433
<dependency>
3534
<groupId>org.springframework.boot</groupId>
36-
<artifactId>spring-boot-starter-validation</artifactId>
35+
<artifactId>spring-boot-starter-security</artifactId>
3736
</dependency>
3837
<dependency>
3938
<groupId>org.springframework.boot</groupId>
40-
<artifactId>spring-boot-starter-web</artifactId>
39+
<artifactId>spring-boot-starter-validation</artifactId>
4140
</dependency>
4241

43-
<!-- PostgreSQL driver -->
42+
<!-- PostgreSQL -->
4443
<dependency>
4544
<groupId>org.postgresql</groupId>
4645
<artifactId>postgresql</artifactId>
@@ -54,7 +53,7 @@
5453
<optional>true</optional>
5554
</dependency>
5655

57-
<!-- JWT -->
56+
<!-- JSON Web Token -->
5857
<dependency>
5958
<groupId>io.jsonwebtoken</groupId>
6059
<artifactId>jjwt-api</artifactId>
@@ -80,7 +79,7 @@
8079
<version>2.3.0</version>
8180
</dependency>
8281

83-
<!-- Testing -->
82+
<!-- Test Dependencies -->
8483
<dependency>
8584
<groupId>org.springframework.boot</groupId>
8685
<artifactId>spring-boot-starter-test</artifactId>
@@ -95,37 +94,34 @@
9594

9695
<build>
9796
<plugins>
98-
<!-- Maven Compiler Plugin for Lombok annotation processing -->
97+
<!-- Compiler Plugin -->
9998
<plugin>
10099
<groupId>org.apache.maven.plugins</groupId>
101100
<artifactId>maven-compiler-plugin</artifactId>
101+
<version>3.10.1</version>
102102
<configuration>
103-
<annotationProcessorPaths>
104-
<path>
105-
<groupId>org.projectlombok</groupId>
106-
<artifactId>lombok</artifactId>
107-
<version>1.18.30</version>
108-
</path>
109-
</annotationProcessorPaths>
103+
<source>${java.version}</source>
104+
<target>${java.version}</target>
105+
<encoding>UTF-8</encoding>
110106
</configuration>
111107
</plugin>
112108

113-
<!-- Spring Boot Maven Plugin -->
109+
<!-- Spring Boot Plugin -->
114110
<plugin>
115111
<groupId>org.springframework.boot</groupId>
116112
<artifactId>spring-boot-maven-plugin</artifactId>
117-
<version>3.5.0</version>
113+
<version>3.1.6</version>
118114
<configuration>
119115
<mainClass>com.p2plending.loanservice.LoanserviceApplication</mainClass>
120-
<excludes>
121-
<exclude>
122-
<groupId>org.projectlombok</groupId>
123-
<artifactId>lombok</artifactId>
124-
</exclude>
125-
</excludes>
126116
</configuration>
117+
<executions>
118+
<execution>
119+
<goals>
120+
<goal>repackage</goal>
121+
</goals>
122+
</execution>
123+
</executions>
127124
</plugin>
128125
</plugins>
129126
</build>
130-
131127
</project>

0 commit comments

Comments
 (0)