Skip to content

Commit 97ac7c4

Browse files
Merge pull request #7 from vimal-tech-starter/feature/new-update-phase-5
Phase 5: PostgreSQL migration with Docker Compose,
2 parents c84833c + 07d9698 commit 97ac7c4

7 files changed

Lines changed: 95 additions & 8 deletions

File tree

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.git
2+
.gitignore
3+
target/
4+
node_modules/
5+
*.log
6+
*.md
7+
.idea
8+
.vscode
9+
Dockerfile
10+
docker-compose.yml

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ---------- Stage 1: Build ----------
2+
FROM maven:3.9.9-eclipse-temurin-21 AS builder
3+
4+
WORKDIR /app
5+
6+
COPY pom.xml .
7+
RUN mvn -B -q dependency:go-offline
8+
9+
COPY src ./src
10+
RUN mvn clean package -DskipTests
11+
12+
# ---------- Stage 2: Runtime ----------
13+
FROM eclipse-temurin:21-jre-alpine
14+
15+
WORKDIR /app
16+
17+
COPY --from=builder /app/target/*.jar app.jar
18+
19+
EXPOSE 8080
20+
21+
ENTRYPOINT ["java","-jar","app.jar"]

docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: "3.9"
2+
3+
services:
4+
5+
postgres:
6+
image: postgres:16
7+
container_name: vimaltech-postgres
8+
environment:
9+
POSTGRES_DB: contactdb
10+
POSTGRES_USER: contactuser
11+
POSTGRES_PASSWORD: contactpass
12+
TZ: Asia/Kolkata
13+
ports:
14+
- "5432:5432"
15+
volumes:
16+
- vimaltech_pgdata:/var/lib/postgresql/data
17+
healthcheck:
18+
test: [ "CMD-SHELL", "pg_isready -U contactuser -d contactdb" ]
19+
interval: 10s
20+
timeout: 5s
21+
retries: 5
22+
23+
contact-api:
24+
build: .
25+
container_name: vimaltech-contact-api
26+
depends_on:
27+
postgres:
28+
condition: service_healthy
29+
ports:
30+
- "8080:8080"
31+
environment:
32+
SPRING_PROFILES_ACTIVE: dev
33+
restart: unless-stopped
34+
35+
volumes:
36+
vimaltech_pgdata:

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
<dependency>
5151
<groupId>com.h2database</groupId>
5252
<artifactId>h2</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.postgresql</groupId>
57+
<artifactId>postgresql</artifactId>
5358
<scope>runtime</scope>
5459
</dependency>
5560
<dependency>

src/main/resources/application-dev.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
spring:
22
datasource:
3-
url: jdbc:h2:mem:contactdb
4-
driver-class-name: org.h2.Driver
5-
username: sa
6-
password:
3+
url: jdbc:postgresql://postgres:5432/contactdb?serverTimezone=UTC
4+
username: contactuser
5+
password: contactpass
6+
driver-class-name: org.postgresql.Driver
77

88
jpa:
99
hibernate:
1010
ddl-auto: validate
11+
properties:
12+
hibernate:
13+
jdbc:
14+
time_zone: UTC
1115
open-in-view: false
1216

13-
h2:
14-
console:
15-
enabled: true
16-
1717
springdoc:
1818
api-docs:
1919
enabled: true

src/test/java/com/vimaltech/contactapi/ContactApiApplicationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.junit.jupiter.api.Test;
44
import org.springframework.boot.test.context.SpringBootTest;
5+
import org.springframework.test.context.ActiveProfiles;
56

67
@SpringBootTest
8+
@ActiveProfiles("test")
79
class ContactApiApplicationTests {
810

911
@Test
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
spring:
2+
datasource:
3+
url: jdbc:h2:mem:testdb
4+
driver-class-name: org.h2.Driver
5+
username: sa
6+
password:
7+
8+
jpa:
9+
hibernate:
10+
ddl-auto: create-drop
11+
12+
flyway:
13+
enabled: false

0 commit comments

Comments
 (0)