Skip to content

Commit 03069ef

Browse files
committed
Make following changes:
- Bump up kapt version - Modify Dockerfile - Rename main app class and its related classes - Update README file
1 parent 7e8de5a commit 03069ef

File tree

10 files changed

+79
-62
lines changed

10 files changed

+79
-62
lines changed

Dockerfile

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
FROM openjdk:8
2-
COPY build/libs/sb-kotlin-java-app-0.1.jar /app/sb-kotlin-java-app-0.1.jar
3-
COPY wait-for-it.sh wait-for-it.sh
4-
RUN chmod +x wait-for-it.sh
5-
#COPY ormconfig.docker.json ./ormconfig.json
6-
7-
EXPOSE 8080 8081 5432 5440
8-
9-
ADD build/libs/sb-kotlin-java-app-0.1.jar sb-kotlin-java-app-0.1.jar
10-
ADD ./wait-for-it.sh wait-for-it.sh
11-
12-
# TODO: fix CMD/ENTRYPOINT for wait-for-it script so following error does NOT occur:
13-
#nikola@ns-dell3537:~/IntellIJIDEA_WS/first-java-kotlin-gradle-project$ docker run -p 8080:8080 nixos89/sb-kotlin-java-app
14-
#Error: you need to provide a host and port to test.
15-
#Usage:
16-
# wait-for-it.sh host:port [-s] [-t timeout] [-- command args]
17-
# -h HOST | --host=HOST Host or IP under test
18-
# -p PORT | --port=PORT TCP port under test
19-
# Alternatively, you specify the host and port as host:port
20-
# -s | --strict Only execute subcommand if the test succeeds
21-
# -q | --quiet Don't output any status messages
22-
# -t TIMEOUT | --timeout=TIMEOUT
23-
# Timeout in seconds, zero for no timeout
24-
# -- COMMAND ARGS Execute command with args after the test finishes
25-
26-
27-
ENTRYPOINT [ "/bin/bash", "-c" ]
28-
# modify 2nd argumet in next (i.e. `CMD`) line
29-
CMD ["/wait-for-it.sh" , "[localhost:5432]" , "--strict" , "--timeout=300" , "--" , "java -jar /app/sb-kotlin-java-app-0.1.jar"]
30-
#ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/sb-kotlin-java-app-0.1.jar"]
1+
FROM gradle:jdk8-jammy AS build
2+
LABEL maintainer="Nikola Stevanovic <[email protected]>"
3+
COPY --chown=gradle:gradle . /home/gradle/src
4+
WORKDIR /home/gradle/src
5+
RUN gradle build
6+
7+
# Example by https://dev.to/scaledynamics/deploy-a-spring-boot-kotlin-application-with-docker-4do3
8+
FROM openjdk:8-jre-slim
9+
COPY --from=build /home/gradle/src/build/libs/todo-app-0.1.jar /app/
10+
RUN bash -c 'touch /app/todo-app-0.1.jar'
11+
EXPOSE 8080
12+
ENTRYPOINT ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app/todo-app-0.1.jar"]

Dockerfile2

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM openjdk:8
2+
COPY build/libs/sb-kotlin-java-app-0.1.jar /app/sb-kotlin-java-app-0.1.jar
3+
COPY wait-for-it.sh wait-for-it.sh
4+
RUN chmod +x wait-for-it.sh
5+
#COPY ormconfig.docker.json ./ormconfig.json
6+
7+
EXPOSE 8080 8081 5432 5440
8+
9+
ADD build/libs/sb-kotlin-java-app-0.1.jar sb-kotlin-java-app-0.1.jar
10+
ADD ./wait-for-it.sh wait-for-it.sh
11+
12+
# TODO: fix CMD/ENTRYPOINT for wait-for-it script so following error does NOT occur:
13+
#nikola@ns-dell3537:~/IntellIJIDEA_WS/first-java-kotlin-gradle-project$ docker run -p 8080:8080 nixos89/sb-kotlin-java-app
14+
#Error: you need to provide a host and port to test.
15+
#Usage:
16+
# wait-for-it.sh host:port [-s] [-t timeout] [-- command args]
17+
# -h HOST | --host=HOST Host or IP under test
18+
# -p PORT | --port=PORT TCP port under test
19+
# Alternatively, you specify the host and port as host:port
20+
# -s | --strict Only execute subcommand if the test succeeds
21+
# -q | --quiet Don't output any status messages
22+
# -t TIMEOUT | --timeout=TIMEOUT
23+
# Timeout in seconds, zero for no timeout
24+
# -- COMMAND ARGS Execute command with args after the test finishes
25+
26+
27+
ENTRYPOINT [ "/bin/bash", "-c" ]
28+
# modify 2nd argumet in next (i.e. `CMD`) line
29+
CMD ["/wait-for-it.sh" , "[localhost:5432]" , "--strict" , "--timeout=300" , "--" , "java -jar /app/sb-kotlin-java-app-0.1.jar"]
30+
#ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/sb-kotlin-java-app-0.1.jar"]

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,33 @@ Simple ToDo app containing REST API written in Java and Kotlin using:
77
* JUnit5
88

99

10-
## Steps for setting and running app:
10+
## 1. Setting up and running the app
11+
To properly set up and run the app perform following steps:
1112
1. Create `todo_db` database in Postgres DB ver 12 using following credentials:
1213
**username**=`postgres`<br/>
13-
**password**=`system`<br/>
14+
**password**=`postgres`<br/>
1415
**NOTE**: Make sure they are matching `spring.datasource.username` / `spring.flyway.user` properties in `application.properties` file
1516
2. Enter directory of `todo-kotlin-java-app` module
1617
3. Make sure property `spring.flyway.enabled` is set to `true` located in `src/main/resources/application.properties`
1718
4. Execute `./gradlew bootRun` command
1819
5. Before 2nd and every other app run (i.e. before executing Step4) set `spring.flyway.enabled` property to `false` located in `src/main/resources/application.properties`
1920

20-
## Target one of following endpoints:
21+
## 2. App containerization
22+
If you prefer not to have...
23+
#TODO: Finish this!
2124

25+
26+
## 3. REST Endpoints
27+
Target one of following endpoints
2228
1. **GET** all Todo(s) [http://localhost:8080/api/todos](http://localhost:8080/api/todos) <br/>
2329
2. **GET** Single Todo (with id=1) [http://localhost:8080/api/todos/1](http://localhost:8080/api/todos/1) <br/>
24-
3. **POST** Todo [http://localhost:8080/api/todos](http://localhost:8080/api/todos) <br/>
25-
...using following body
30+
3. **POST** Todo [http://localhost:8080/api/todos](http://localhost:8080/api/todos) <br/>...using following body
2631
```json
2732
{
2833
"title": "Kotlin app review",
2934
"description": "Survive the Kotlin app review"
3035
}
31-
```
36+
```
3237
4. **PATCH** Todo [http://localhost:8080/api/todos/3](http://localhost:8080/api/todos/3) <br/>
3338
...using following body
3439
```json

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
kotlin("plugin.spring") version "1.5.10"
1111
kotlin("plugin.jpa") version "1.5.10"
1212
kotlin("plugin.allopen") version "1.5.10"
13-
kotlin("kapt") version "1.5.10"
13+
kotlin("kapt") version "1.6.0"
1414
}
1515

1616
allOpen {
@@ -69,10 +69,10 @@ tasks.withType<Test> {
6969
}
7070

7171
application {
72-
mainClass.set("org.example.java_kotlin.FirstJavaKotlinGradleApp")
72+
mainClass.set("org.example.java_kotlin.TodoKotlinJavaApp")
7373
}
7474

7575
tasks.bootJar {
76-
archiveBaseName.set("sb-kotlin-java-app")
76+
archiveBaseName.set("todo-app")
7777
archiveVersion.set("0.1")
7878
}

docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
version: "3.7"
2+
# TODO Read following docs:
23
# https://github.com/docker-library/docs/blob/master/postgres/README.md
34
# https://github.com/docker-library/docs/tree/master/openjdk
45
# https://docs.docker.com/compose/startup-order/
@@ -15,7 +16,7 @@ services:
1516
- postgres-data:/var/lib/postgresql/data
1617
environment:
1718
POSTGRES_USER: postgres
18-
POSTGRES_PASSWORD: root
19+
POSTGRES_PASSWORD: postgres
1920
POSTGRES_DB: todo_db
2021
# TODO: try mapping to different host and container ports
2122
ports:
@@ -28,18 +29,18 @@ services:
2829
- postgres-db
2930
ports:
3031
- "8080:8080"
31-
- "8081:8080"
3232
volumes:
3333
- ./build/libs:/app
34-
command: wait-for-it.sh localhost:5432 -t 20 && java -jar /app/sb-kotlin-java-app-0.1.jar
34+
# TODO: modify `command` statement in order to execute
35+
command: wait-for-it.sh localhost:5432 -t 20 && java -jar /app/todo-app-0.1.jar
3536
# entrypoint:
3637
environment:
3738
- SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/todo_db
3839
- SPRING_DATASOURCE_DRIVER_CLASS_NAME=org.postgresql.Driver
3940
- SPRING_DATASOURCE_USERNAME=postgres
40-
- SPRING_DATASOURCE_PASSWORD=root
41+
- SPRING_DATASOURCE_PASSWORD=postgres
4142
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
4243
- SPRING_FLYWAY_USER=postgres
43-
- SPRING_FLYWAY_PASSWORD=root
44+
- SPRING_FLYWAY_PASSWORD=postgres
4445
volumes:
4546
postgres-data:

src/main/java/org/example/java_kotlin/FirstJavaKotlinGradleApp.java renamed to src/main/java/org/example/java_kotlin/TodoKotlinJavaApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
@SpringBootApplication
99
@EnableConfigurationProperties(ToDoConfiguration.class)
10-
public class FirstJavaKotlinGradleApp {
10+
public class TodoKotlinJavaApp {
1111

1212
public static void main(String[] args) {
13-
SpringApplication.run(FirstJavaKotlinGradleApp.class, args);
13+
SpringApplication.run(TodoKotlinJavaApp.class, args);
1414
}
1515
}

src/main/java/org/example/java_kotlin/controller/TodoController.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.springframework.util.ObjectUtils
99
import org.springframework.validation.annotation.Validated
1010
import org.springframework.web.bind.annotation.*
1111

12+
// TODO: Remove all unnecessary and unused variables in this class
13+
1214
@RestController
1315
@RequestMapping("/api/todos")
1416
class TodoController(private val todoRepository: TodoRepository, private val toDoService: ToDoService) {

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ management.endpoints.web.exposure.include=health,info,shutdown
55
# setting up Postgres DB
66
spring.datasource.url=jdbc:postgresql://localhost:5432/todo_db
77
spring.datasource.username=postgres
8-
spring.datasource.password=root
8+
spring.datasource.password=postgres
99
spring.datasource.driverClassName=org.postgresql.Driver
1010

1111
spring.flyway.enabled=true
@@ -19,5 +19,5 @@ spring.flyway.repeatable-sql-migration-prefix=R
1919
spring.flyway.sql-migration-separator=__
2020
spring.flyway.sql-migration-suffixes=.sql
2121
spring.flyway.user=postgres
22-
spring.flyway.password=root
22+
spring.flyway.password=postgres
2323
spring.flyway.locations=classpath:db/migration

src/test/java/org/example/java_kotlin/FirstJavaKotlinGradleAppTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.example.java_kotlin;
2+
3+
4+
//@SpringBootTest
5+
public class TodoKotlinJavaAppTest {
6+
7+
// @Test
8+
// void contextLoads() {
9+
// }
10+
11+
}

0 commit comments

Comments
 (0)