Add App into docker

This commit is contained in:
2019-10-13 16:24:13 +02:00
parent f76f6f83bb
commit e73a7b5a18
6 changed files with 47 additions and 13 deletions

2
.env
View File

@@ -2,6 +2,8 @@ NAME=dc-project
DATABASE_URL=jdbc:postgresql:dc-project
APP_PORT=8080
ELASTIC_REST=9200
ELASTIC_NODES=9300

View File

@@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.owasp.dependencycheck.reporting.ReportGenerator
@@ -35,16 +33,13 @@ tasks.withType<KotlinCompile> {
jvmTarget = "1.8"
}
}
tasks.withType(ShadowJar::class) {
enabled = true
manifest.attributes["Main-Class"] = application.mainClassName
archiveFileName.set("dcproject.jar")
transform(ServiceFileTransformer::class.java) {
setPath("META-INF/services")
include("org.eclipse.jetty.http.HttpFieldPreEncoder")
tasks.withType<Jar> {
manifest {
attributes(
mapOf(
"Main-Class" to application.mainClassName
)
)
}
}

View File

@@ -3,6 +3,20 @@
version: '3.7'
services:
app:
container_name: app_${NAME}
build:
context: ./build
dockerfile: ../docker/app/Dockerfile
restart: always
ports:
- ${APP_PORT}:8080
environment:
DB_HOST: db
depends_on:
- elasticsearch
- db
elasticsearch:
container_name: elasticsearch_${NAME}
image: elasticsearch:6.7.1

15
docker/app/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM adoptopenjdk/openjdk11:jre-11.0.4_11-alpine
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./libs/dcproject-0.0.1-all.jar /app/dcproject.jar
COPY ./resources /app/resources
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "dcproject.jar"]

View File

@@ -5,12 +5,19 @@ import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import com.typesafe.config.ConfigFactory
import fr.dcproject.entity.User
import org.eclipse.jetty.util.resource.JarResource
import java.io.File
import java.util.*
class Config {
private var config = ConfigFactory.load()
val sqlFiles = File(this::class.java.getResource("/sql").toURI())
val sqlFiles: File = try {
File(this::class.java.getResource("/sql").toURI())
} catch (e: IllegalArgumentException) {
JarResource.newResource("./resources/sql").file
}
val envName: String = config.getString("app.envName")
val domain: String = config.getString("app.domain")

View File

@@ -15,6 +15,7 @@ app {
db {
host = localhost
host = ${?DB_HOST}
database = dc-project
username = dc-project
password = dc-project