Add docker service for the api + env variables + ...

This commit is contained in:
Hubert Van De Walle 2020-04-30 12:11:00 +02:00
parent a2ac8d19af
commit 8cf8457a54
6 changed files with 48 additions and 16 deletions

5
.env.dist Normal file
View File

@ -0,0 +1,5 @@
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=
JWT_SECRET=

14
api/Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM openjdk:13-alpine
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./target/api-0.0.1-jar-with-dependencies.jar /app/notes-api.jar
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "notes-api.jar"]

View File

@ -24,7 +24,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.compiler.jvmTarget>12</kotlin.compiler.jvmTarget>
<main.class>io.ktor.server.netty.EngineMain</main.class>
<main.class>be.vandewalleh.NotesApplicationKt</main.class>
<java.version>13</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
@ -150,11 +150,6 @@
<artifactId>HikariCP</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.sksamuel.hoplite</groupId>
<artifactId>hoplite-core</artifactId>
<version>${hoplite_version}</version>
</dependency>
<dependency>
<groupId>com.sksamuel.hoplite</groupId>
<artifactId>hoplite-yaml</artifactId>

View File

@ -1,18 +1,18 @@
env: staging
database:
host: 127.0.0.1
host: ${MYSQL_HOST}
port: 3306
name: Notes
username: test
password: test
name: ${MYSQL_DATABASE}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
server:
host: 0.0.0.0
port: 8081
jwt:
secret: ${random.string(25)}
secret: ${JWT_SECRET}
auth:
validity: 1
unit: HOURS

View File

@ -19,6 +19,7 @@ import org.kodein.di.generic.singleton
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.sql.DataSource
import kotlin.system.exitProcess
val kodein = Kodein {
import(serviceModule)

View File

@ -1,18 +1,35 @@
version: '3'
version: '2.2'
services:
db:
image: mariadb
container_name: notes-mariadb
env_file:
- .env
environment:
- PUID=1000
- PGID=1000
- MYSQL_ROOT_PASSWORD=test
- TZ=Europe/Brussels
- MYSQL_DATABASE=Notes
- MYSQL_USER=test
- MYSQL_PASSWORD=test
ports:
# This is only for testing
- 3306:3306
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
api:
build: ./api
container_name: notes-api
ports:
- 8081:8081
env_file:
- .env
environment:
- TZ=Europe/Brussels
- MYSQL_HOST=db
depends_on:
db:
condition: service_healthy