Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Add sample using Docker Compose

This PR adds a new sample demonstrating how to use Doma Spring Boot with Docker Compose and PostgreSQL.

The sample includes:

  • A Spring Boot application with Doma integration
  • Docker Compose configuration for PostgreSQL
  • A Dockerfile for building the application
  • Documentation on how to run and use the sample

Fixes #291

Link to Devin run: https://app.devin.ai/sessions/5c0405d96184477a850a6cac86d421c5
Requested by: [email protected]

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@making
Copy link
Member

making commented May 19, 2025

@devin-ai-integration

This is not expected work requested in #291

Here is the document for Docker Compose support in Spring Boot.
https://docs.spring.io/spring-boot/reference/features/dev-services.html#features.dev-services.docker-compose

You should create a project from Spring Initializr with "Docker Compose Support" dependency included.

@making making self-assigned this May 19, 2025
@@ -0,0 +1,9 @@
services:
postgres:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the generated compose.yaml as is

@@ -0,0 +1,33 @@
# Getting Started
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HELP.md should not be managed in git.
Add HELP.md into .gitignore

"spring.datasource.password=",
"spring.datasource.driver-class-name=org.h2.Driver",
"doma.dialect=H2"
"spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use docker compose in tests as well. That means PostgreSQL should be used in tests instead of H2.

By default, Spring Boot’s Docker Compose support is disabled when running tests.

To enable Docker Compose support in tests, set spring.docker.compose.skip.in-tests to false.

"spring.datasource.password=",
"spring.datasource.driver-class-name=org.h2.Driver",
"doma.dialect=H2"
"spring.docker.compose.skip.in-tests=false",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated with application.properties

@@ -0,0 +1,3 @@
# Enable Docker Compose in tests
spring.docker.compose.skip.in-tests=false
doma.dialect=POSTGRES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doma.dialect should be automatically detected by JdbcConnectionDetails

</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H2 is no longer needed

The PostgreSQL configuration is defined in the `compose.yaml` file:

```yaml
services:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update README

@making
Copy link
Member

making commented May 19, 2025

@devin-ai-integration rebase the master branch.

Add the same tests as in #310, and reflect the review comments in this PR as well.

<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this dependency as it's included in spring-boot-starter-test


# Doma configuration
doma.dialect=POSTGRES
logging.level.org.springframework.jdbc.datasource.DataSourceTransactionManager=DEBUG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSourceTransactionManager is old. Use JdbcTransactionManager instead.

logging.level.org.springframework.jdbc.support.JdbcTransactionManager=DEBUG

# Enable Docker Compose in tests
spring.docker.compose.skip.in-tests=false
spring.sql.init.mode=always
spring.sql.init.schema-locations=classpath:schema-test.sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having to manage the data twice using schema-test.sql and schema.sql. Instead of using schema-test.sql for testing, perform the reset process in the test code.

spring.sql.init.schema-locations=classpath:schema-test.sql

# Database configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/mydatabase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring.datasource.* props are useless as these are automatically resolved via Docker Compose based JdbcConnectionDetails

@@ -1,13 +1,12 @@
# Enable Docker Compose in tests
spring.docker.compose.skip.in-tests=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove src/test/resources/application.properties. Using src/main/resources/application.properties should be sufficient

@@ -1,12 +0,0 @@
# Enable Docker Compose in tests
spring.docker.compose.skip.in-tests=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move spring.docker.compose.skip.in-tests=false to src/main/resources/application.properties

@making making merged commit d6ea084 into master May 19, 2025
6 checks passed
@making making deleted the devin/1747645402-add-docker-compose-sample branch May 19, 2025 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add sample using Docker Compose

2 participants