Skip to content

Commit

Permalink
Add docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
barcellos-pedro committed Feb 6, 2024
1 parent 27dfe9c commit e81bea7
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21-jre-alpine
FROM eclipse-temurin:21-jdk-alpine
VOLUME /tmp
WORKDIR /app
COPY run.sh .
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Project based on [Spring Guide](https://spring.io/guides/tutorials/rest/)

### Todo

*For the sake of simplicity, only the Employee model has tests*
For the sake of simplicity, only the Employee model has tests

- [Tests](https://docs.spring.io/spring-boot/docs/3.2.2/reference/html/features.html#features.testing)

Expand All @@ -25,19 +25,18 @@ Project based on [Spring Guide](https://spring.io/guides/tutorials/rest/)
- [x] Integration
- [x] [WebMvc](https://spring.io/guides/gs/testing-web/)


- [CI/CD GitHub Actions](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven)

- [x] Build
- [x] Test
- [ ] Publish API Docs
- [ ] Publish API Docs (Bônus)

### Bônus 🎁

- [ ] Replace H2 for Postgres
- [ ] Monitor Postgres with PGAdmin
- [x] Replace H2 for [Postgres](https://www.docker.com/blog/how-to-use-the-postgres-docker-official-image/)
- [x] [Monitor Postgres with PGAdmin](https://github.com/docker/awesome-compose/tree/master/postgresql-pgadmin)
- [ ] [Caching (Redis)](https://docs.spring.io/spring-framework/reference/integration/cache/annotations.html)
- [x] [Docker Compose](https://github.com/docker/awesome-compose/tree/master/spring-postgres)
- [ ] Nginx
- [ ] Docker Compose
- [ ] [Performance Test (Jmeter)](https://jmeter.apache.org/index.html)
- [ ] [API Docs with Restdocs](https://spring.io/guides/gs/testing-restdocs/)
42 changes: 42 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3.8'

volumes:
pgdata:

services:
app:
container_name: app
build: .
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy

postgres:
container_name: postgres
image: postgres:14.5
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
ports:
- "5432:5432"
restart: always
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME} -h 127.0.0.1 -p 5432" ]
interval: 10s
timeout: 5s
retries: 3

pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:8.2
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL=${PGADMIN_MAIL}
- PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
ports:
- "5050:80"
6 changes: 6 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_URL=<your-value>
DB_USERNAME=<your-value>
DB_PASSWORD=<your-value>
DB_NAME=<your-value>
PGADMIN_MAIL=<your-value>
PGADMIN_PASSWORD=<your-value>
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.h2database</groupId>-->
<!-- <artifactId>h2</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->

<!-- Metrics -->
<dependency>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Database
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

# Enable SQL logging
spring.datasource.log-statement=true

# Hibernate specific: Show SQL with formatted parameters
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

# Observability
# management.wavefront.application.name=rest
# management.wavefront.application.service-name=app
Expand Down

0 comments on commit e81bea7

Please sign in to comment.