Skip to content

Commit

Permalink
Merge pull request #39 from spt-development/create-docker-image
Browse files Browse the repository at this point in the history
Added instructions to README for creating and testing a docker image …
  • Loading branch information
SimonTaylor authored Oct 21, 2024
2 parents 29e0141 + 69219fa commit e334f30
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ through the use of environment variables to point at a postgres database running

```shell
$ SPRING_DATASOURCE_URL=jdbc:postgresql://127.0.0.1:59314/spt-recruitment-demo \
SPRING_DATASOURCE_USERNAME=postgres SPRING_DATASOURCE_PASSWORD=p@ssw0rd \
SPRING_DATASOURCE_USERNAME=postgres \
SPRING_DATASOURCE_PASSWORD=p@ssw0rd \
SPRING_ACTIVEMQ_BROKER_URL=tcp://localhost:59313 \
java -jar target/spt-development-demo-0.0.1-SNAPSHOT.jar
```
Expand All @@ -86,4 +87,20 @@ $ curl -v -u bob:password123! http://localhost:8080/api/v1.0/books/4
```
```shell
$ curl -v -u bob:password123! -X DELETE http://localhost:8080/api/v1.0/books/4
```
```
Running the demo in docker
==========================

There are multiple ways to [build a docker image](https://www.baeldung.com/spring-boot-docker-images) for Spring Boot
applications. The simplest way is to use Buildpacks.

```shell
$ ./mvnw spring-boot:build-image
```
The [docker-compose.service.yml](./docker-compose.service.yml) can then be used to run the image along with
[docker-compose.yml](./docker-compose.yml) to start up Postgres and ActiveMQ.

```shell
$ docker compose -f docker-compose.yml -f docker-compose.service.yml up -d
```
The cURL commands above can again be used to test the API.
12 changes: 12 additions & 0 deletions docker-compose.service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'

services:
api:
image: docker.io/library/spt-development-demo:0.0.1-SNAPSHOT
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://spt-development-demo-db-1:5432/spt-recruitment-demo
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: p@ssw0rd
SPRING_ACTIVEMQ_BROKER_URL: tcp://spt-development-demo-activemq-1:61616
ports:
- "8080:8080"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
ports:
- "5432"

artemis:
activemq:
image: apache/activemq-classic:6.1.0
ports:
- "61616"
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,17 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<!--
Prevents the following warning introduced in JDK 21, caused by Mockito or more specifically byte-buddy-agent:
WARNING: A Java agent has been loaded dynamically (/Users/khm/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.5/byte-buddy-agent-1.14.5.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
NOTE. argLine property is set by JaCoCo in prepare-agent stage.
-->
<argLine>-XX:+EnableDynamicAgentLoading ${argLine}</argLine>
<!--
classesDirectory is required to work around a bug that is discussed at
https://github.com/spring-projects/spring-boot/issues/6254. There are a number of different
workarounds, but this seems to be the cleanest.
Expand Down Expand Up @@ -487,6 +498,17 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!--
Prevents the following warning introduced in JDK 21, caused by Mockito or more specifically byte-buddy-agent:
WARNING: A Java agent has been loaded dynamically (/Users/khm/.m2/repository/net/bytebuddy/byte-buddy-agent/1.14.5/byte-buddy-agent-1.14.5.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
NOTE. argLine property is set by JaCoCo in prepare-agent stage.
-->
<argLine>-XX:+EnableDynamicAgentLoading ${argLine}</argLine>
<trimStackTrace>false</trimStackTrace>
<includes>
<include>**/*Test.java</include>
Expand Down

0 comments on commit e334f30

Please sign in to comment.