Skip to content

Commit 5e99025

Browse files
committed
docker integration
1 parent c6e4dcb commit 5e99025

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ out/
4141

4242
### Logs ###
4343
logs/
44+
45+
**/application-prod.properties

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM openjdk:11
2+
VOLUME /tmp
3+
EXPOSE 8080
4+
ARG JAR_FILE=build/libs/kaput-0.0.1-SNAPSHOT.jar
5+
ADD ${JAR_FILE} app.jar
6+
ENTRYPOINT ["java", "-jar", "/app.jar"]

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@
44
The app is named after the sound my car makes, which I'm hoping to replace once
55
I no longer need to use such an app.
66

7-
Requirements:
8-
- Java 11 or Newer
9-
- PostgreSQL v14+ (will replace once Docker set up)
7+
## Setup
108

11-
You will have to first create a database named `kaput` in PostgreSQL, then update the DB credentials
12-
in `build.gradle` (under the liquibase task) and `application.properties`.
9+
Requirements:
10+
- [Docker](https://docs.docker.com/get-docker/) Engine version 19.03.0+
11+
- [Docker Compose](https://docs.docker.com/compose/install/)
1312

14-
With the DB created and credentials updated, Liquibase should read `changelog-root.xml` to initialize the
15-
tables and data for you.
13+
Steps:
14+
1. Run `docker compose up`. This starts two docker instances: one for the app and another for PostgreSQL.
15+
2. Then find the container id for the docker container with image name `kaput-api`.
16+
3. Find the IP address this container is running on with `docker container inspect <the container id>`. This is the host where you will send requests to on port 8080 (e.g. http://\<container ip address\>:8080/api/users).
1617

17-
Run locally by executing the command `gradlew runBoot` from the project root directory. Once the app is up and
18-
running, go to `localhost:8080` from a browser.
18+
Will update Swagger docs with instructions on how to use API.
1919

20+
## ERD
2021
Only two entites are needed for this application.
21-
![entity-relationship diagram](./img/erd.png)
22+
![entity-relationship diagram](./img/erd.png)
2223

24+
##Notes
2325
### Exception Handling
2426
Exception handling is composed of two parts:
2527
1. Providing a custom exception response body

docker-compose.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
image: 'kaput-api:latest'
6+
build:
7+
context: .
8+
container_name: app
9+
depends_on:
10+
- db
11+
environment:
12+
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/kaput
13+
- SPRING_DATASOURCE_USERNAME=postgres
14+
- SPRING_DATASOURCE_PASSWORD=password
15+
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
16+
17+
db:
18+
image: 'postgres:14.7-alpine'
19+
container_name: db
20+
environment:
21+
- POSTGRES_USER=postgres
22+
- POSTGRES_PASSWORD=password
23+
- POSTGRES_DB=kaput

src/main/resources/config/application-dev.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
1+
spring.jpa.show-sql=true
2+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
23
spring.jpa.hibernate.ddl-auto=update
34
spring.jpa.hibernate.show-sql=true
45
spring.datasource.url=jdbc:postgresql://localhost:5432/kaput

src/main/resources/config/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
server.address=0.0.0.0
12
spring.liquibase.change-log=classpath:db/changelog-root.xml
23
spring.liquibase.databaseChangeLogTable=changelogs
34
java.lang.NoSuchMethodError: 'java.lang.String ch.qos.logback.core.util.EnvUtil.logbackVersion()'

0 commit comments

Comments
 (0)