dockerize application

This commit is contained in:
Denis Savosin
2024-10-07 13:14:50 +07:00
parent 983a9badf2
commit 01ce385c30
8 changed files with 53 additions and 10 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
*
!build/libs/

7
.env.example Normal file
View File

@@ -0,0 +1,7 @@
DB_URL=localhost:5432
DB_NAME=demo
DB_SCHEMA=public
DB_USERNAME=postgres
DB_PASSWORD=postgres
KAFKA_SERVERS=localhost:9095

3
.gitignore vendored
View File

@@ -30,3 +30,6 @@ out/
### Kotlin ###
.kotlin
.env
docker-compose.override.yml

3
Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM openjdk:17-jdk-slim
COPY --chmod=777 build/libs/demo-single-version.jar /application/demo.jar
CMD ["java", "-jar", "/application/demo.jar"]

View File

@@ -11,7 +11,7 @@ plugins {
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
version = "single-version"
java {
sourceCompatibility = JavaVersion.VERSION_17
@@ -69,4 +69,3 @@ tasks.test {
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}

17
docker-compose.yml Normal file
View File

@@ -0,0 +1,17 @@
---
services:
demo:
image: localhost/spring-boot-demo:latest
build:
dockerfile: Dockerfile
context: .
environment:
DB_URL: $DB_URL
DB_NAME: $DB_NAME
DB_SCHEMA: $DB_SCHEMA
DB_USERNAME: $DB_USERNAME
DB_PASSWORD: $DB_PASSWORD
KAFKA_SERVERS: $KAFKA_SERVERS
expose:
- 8080
- 8081

View File

@@ -7,7 +7,7 @@ Demo приложение для изучения языка `kotlin` и фре
* `jdk` версии `17`
* `postgresql` версии `14`
* `kafka` без авторизации
* `docker` + `compose` (для тестов)
* `docker` + `compose`
## Доступные команды
@@ -20,3 +20,15 @@ Demo приложение для изучения языка `kotlin` и фре
```shell
./gradlew bootRun
```
## Запуск с docker-compose
Перед каждым запуском необходимо собрать приложение:
```shell
./gradlew assemble
```
Затем можно запускать контейнер:
```shell
docker compose up -d
```

View File

@@ -3,20 +3,20 @@ spring:
application:
name: Demo
datasource:
url: jdbc:postgresql://localhost:5432/demo?currentSchema=public
username: postgres
password: postgres
url: jdbc:postgresql://${DB_URL:localhost:5432}/${DB_NAME:demo}?currentSchema=${DB_SCHEMA:public}
username: ${DB_USERNAME:postgres}
password: ${DB_PASSWORD:postgres}
driver-class-name: org.postgresql.Driver
hikari:
schema: public
schema: ${DB_SCHEMA:public}
flyway: #flyway automatically uses the datasource from the application to connect to the DB
enabled: true # enables flyway database migration
locations: classpath:db/migration/structure, classpath:db/migration/data # the location where flyway should look for migration scripts
validate-on-migrate: true
default-schema: public
default-schema: ${DB_SCHEMA:public}
kafka:
bootstrap-servers: localhost:9095
bootstrap-servers: ${KAFKA_SERVERS:localhost:9095}
producer:
product:
default-sync-topic: demo-product-sync