-
Notifications
You must be signed in to change notification settings - Fork 26
Add sample using Docker Compose #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b5c8da0
Add Docker Compose sample for Doma Spring Boot (#291)
devin-ai-integration[bot] 492079e
Fix code formatting issues
devin-ai-integration[bot] 9a54fdc
Update Docker Compose sample to use Spring Boot's built-in Docker Com…
devin-ai-integration[bot] f8fca44
Fix code formatting issues
devin-ai-integration[bot] 22218e7
Address PR feedback: Use Spring Boot Docker Compose support correctly
devin-ai-integration[bot] 0c1d0e9
Address PR feedback: Remove duplicate properties and auto-detect dialect
devin-ai-integration[bot] 54abc1d
Address PR feedback: Remove H2 dependency and update README
devin-ai-integration[bot] 8d4b1e1
Remove openrewrite maven plugin from pom.xml
making b833b87
Add TestContainers sample for Doma Spring Boot (#310)
devin-ai-integration[bot] c2b2c05
Update Docker Compose sample to match TestContainers sample tests
devin-ai-integration[bot] bc628f6
Add schema-test.sql to reset database sequence for tests
devin-ai-integration[bot] 8f69bac
Merge branch 'master' into devin/1747645402-add-docker-compose-sample
making ccbb570
Address PR feedback: Move sequence reset to test code, update logging…
devin-ai-integration[bot] 0090fb5
Remove test application.properties as it's redundant with main applic…
devin-ai-integration[bot] b616f81
Add TestContainers fallback for Docker Compose sample in CI
devin-ai-integration[bot] bd35370
Format DockerComposeTestConfiguration.java
devin-ai-integration[bot] a68bdde
Revert "Format DockerComposeTestConfiguration.java"
making 10064a2
Revert "Add TestContainers fallback for Docker Compose sample in CI"
making 739caf8
update
making File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/Dockerfile
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/HELP.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Getting Started | ||
|
|
||
| ### Reference Documentation | ||
| For further reference, please consider the following sections: | ||
|
|
||
| * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) | ||
| * [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.5/maven-plugin) | ||
| * [Create an OCI image](https://docs.spring.io/spring-boot/3.4.5/maven-plugin/build-image.html) | ||
| * [Docker Compose Support](https://docs.spring.io/spring-boot/3.4.5/reference/features/dev-services.html#features.dev-services.docker-compose) | ||
| * [Spring Web](https://docs.spring.io/spring-boot/3.4.5/reference/web/servlet.html) | ||
|
|
||
| ### Guides | ||
| The following guides illustrate how to use some features concretely: | ||
|
|
||
| * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) | ||
| * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) | ||
| * [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) | ||
|
|
||
| ### Docker Compose support | ||
| This project contains a Docker Compose file named `compose.yaml`. | ||
| In this file, the following services have been defined: | ||
|
|
||
| * postgres: [`postgres:latest`](https://hub.docker.com/_/postgres) | ||
|
|
||
| Please review the tags of the used images and set them to the same as you're running in production. | ||
|
|
||
| ### Maven Parent overrides | ||
|
|
||
| Due to Maven's design, elements are inherited from the parent POM to the project POM. | ||
| While most of the inheritance is fine, it also inherits unwanted elements like `<license>` and `<developers>` from the parent. | ||
| To prevent this, the project POM contains empty overrides for these elements. | ||
| If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. | ||
|
|
||
65 changes: 38 additions & 27 deletions
65
doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,58 +1,69 @@ | ||
| # Doma Spring Boot Sample with Docker Compose | ||
|
|
||
| This sample demonstrates how to use Doma with Spring Boot using Docker Compose. | ||
| This sample demonstrates how to use Doma with Spring Boot's Docker Compose support. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Docker | ||
| - Docker Compose | ||
|
|
||
| ## How it works | ||
|
|
||
| This sample uses Spring Boot's built-in Docker Compose support, which automatically: | ||
|
|
||
| 1. Detects the `compose.yaml` file in the project root | ||
| 2. Starts the PostgreSQL container defined in the compose file | ||
| 3. Configures the application to connect to the database | ||
|
|
||
| The `spring-boot-docker-compose` dependency enables this functionality, allowing the application to seamlessly integrate with Docker Compose services. | ||
|
|
||
| ## Running the sample | ||
|
|
||
| From the sample directory, run: | ||
|
|
||
| ```bash | ||
| docker compose up | ||
| ./mvnw spring-boot:run | ||
| ``` | ||
|
|
||
| This will: | ||
| 1. Start a PostgreSQL database container | ||
| 2. Build the Spring Boot application | ||
| 3. Start the application container linked to the database | ||
| Spring Boot will automatically: | ||
| - Start the PostgreSQL container defined in compose.yaml | ||
| - Configure the application to connect to the database | ||
| - Run the application | ||
|
|
||
| ## Using the application | ||
|
|
||
| Once both containers are running, you can access the application at http://localhost:8080 | ||
| Once the application is running, you can access it at http://localhost:8080 | ||
|
|
||
| ### API Endpoints | ||
|
|
||
| - `GET /` - List all messages | ||
| - `GET /?text=hello` - Add a new message with the text "hello" | ||
|
|
||
| ## Running the application locally | ||
| ## Configuration | ||
|
|
||
| If you want to run the application locally while using the Docker PostgreSQL database: | ||
| The PostgreSQL configuration is defined in the `compose.yaml` file: | ||
|
|
||
| 1. Start only the database container: | ||
| ```bash | ||
| docker compose up postgres | ||
| ``` | ||
| ```yaml | ||
| services: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update README |
||
| postgres: | ||
| image: 'postgres:latest' | ||
| environment: | ||
| - 'POSTGRES_DB=${POSTGRES_DB}' | ||
| - 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD}' | ||
| - 'POSTGRES_USER=${POSTGRES_USER}' | ||
| ports: | ||
| - '5432' | ||
| ``` | ||
|
|
||
| Before running the application, you should set the following environment variables: | ||
| - `POSTGRES_DB`: The name of the PostgreSQL database (e.g., "domadb") | ||
| - `POSTGRES_USER`: The PostgreSQL username (e.g., "doma") | ||
| - `POSTGRES_PASSWORD`: The PostgreSQL password | ||
|
|
||
| 2. Run the application: | ||
| ```bash | ||
| ./mvnw spring-boot:run | ||
| ``` | ||
| Spring Boot automatically configures the application to connect to this database. | ||
|
|
||
| ## Notes | ||
|
|
||
| - The PostgreSQL data is persisted in a Docker volume | ||
| - The application connects to PostgreSQL using environment variables with default values | ||
| - You can customize the database configuration by setting the following environment variables: | ||
| - `POSTGRES_DB`: Database name (default: domadb) | ||
| - `POSTGRES_USER`: Database username (default: doma) | ||
| - `POSTGRES_PASSWORD`: Database password (default: changeme) | ||
| - No manual configuration of database connection properties is needed | ||
| - The schema.sql file is automatically executed when the application starts | ||
|
|
||
| ## Security Note | ||
|
|
||
| For production use, always set secure passwords through environment variables rather than using the defaults. | ||
| - Spring Boot manages the lifecycle of the Docker containers | ||
9 changes: 9 additions & 0 deletions
9
doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/compose.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| services: | ||
| postgres: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the generated compose.yaml as is |
||
| image: 'postgres:latest' | ||
| environment: | ||
| - 'POSTGRES_DB=${POSTGRES_DB}' | ||
| - 'POSTGRES_PASSWORD=${POSTGRES_PASSWORD}' | ||
| - 'POSTGRES_USER=${POSTGRES_USER}' | ||
| ports: | ||
| - '5432' | ||
31 changes: 0 additions & 31 deletions
31
doma-spring-boot-samples/doma-spring-boot-sample-docker-compose/docker-compose.yml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HELP.mdshould not be managed in git.Add
HELP.mdinto.gitignore