Skip to content

Commit

Permalink
chore: adding watch mode compatibility to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
hhertout committed Jan 7, 2024
1 parent 9ea5afe commit c8cfa55
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PG_HOST=
PG_PORT=
PG_USER=
PG_PASSWORD=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ build/

### VS Code ###
.vscode/
.env
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM maven

RUN apt update && apt install -y inotify-tools

WORKDIR /app

COPY mvnw .
Expand All @@ -10,4 +12,4 @@ COPY src src
RUN mvn install -DskipTests
RUN mvn compiler:compile

CMD ["mvn", "spring-boot:run"]
COPY run.sh run.sh
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ services:
build:
context: .
dockerfile: Dockerfile
command: sh run.sh
container_name: api_java
env_file:
- .env
volumes:
- ./src:/app/src
ports:
- "8080:8080"
- "35729:35729"
- "5005:5005"

db:
image: postgres
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

<!-- Dépendance Hibernate Validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down
5 changes: 5 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" &
while true; do
inotifywait -e modify,create,delete,move -r ./src/ && mvn compile
done
15 changes: 10 additions & 5 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
spring.datasource.url=jdbc:postgresql://db:5432/api_java
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.datasource.url=jdbc:postgresql://${PG_HOST}:${PG_PORT}/api_java
spring.datasource.username=${PG_USER}
spring.datasource.password=${PG_PASSWORD}
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=update
spring.devtools.livereload.enabled=true
spring.devtools.restart.enabled=true
spring.devtools.restart.poll-interval=2s
spring.devtools.restart.quiet-period=1s

0 comments on commit c8cfa55

Please sign in to comment.