Update postgres-json to Add ShadowJar compatibility

Add .env for redis and ES
change group name of project
This commit is contained in:
2020-05-11 01:50:40 +02:00
parent b4be28ddc8
commit 8640d9146d
15 changed files with 135 additions and 51 deletions

7
.env
View File

@@ -4,10 +4,11 @@ DATABASE_URL=jdbc:postgresql:dc-project
APP_PORT=8080
OPENAPI_PORT=8181
SONARQUBE_PORT=9000
SONARQUBE_PORT=9002
ELASTIC_REST=9200
ELASTIC_NODES=9300
ELASTICSEARCH_CONNECTION=http://elasticsearch:9200
POSTGRESQL_PORT=5432
DB_HOST=db
@@ -17,9 +18,9 @@ DB_USER=dc-project
DB_PWD=dc-project
REDIS_PORT=6379
REDIS_CONNECTION=redis://localhost:6379
REDIS_CONNECTION=redis://redis:6379
REDIS_COMMANDER_PORT=8081
RABBITMQ_PORT=5672
RABBITMQ_CONNECTION=amqp://localhost:5672
RABBITMQ_CONNECTION=amqp://rabbitmq:5672
RABBITMQ_MANAGEMENT_PORT=15672

31
.idea/runConfigurations/Build.xml generated Normal file
View File

@@ -0,0 +1,31 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" />
</ENTRIES>
</extension>
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
<method v="2" />
</configuration>
</component>

View File

@@ -0,0 +1,31 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Build without test" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-x test -x ktlintKotlinScriptCheck -x ktlintTestSourceSetCheck -x ktlintMainSourceSetCheck" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<extension name="net.ashald.envfile">
<option name="IS_ENABLED" value="false" />
<option name="IS_SUBST" value="false" />
<option name="IS_PATH_MACRO_SUPPORTED" value="false" />
<option name="IS_IGNORE_MISSING_FILES" value="false" />
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" />
<ENTRIES>
<ENTRY IS_ENABLED="true" PARSER="runconfig" />
</ENTRIES>
</extension>
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
<method v="2" />
</configuration>
</component>

13
.idea/runConfigurations/SQL_Fixtures.xml generated Normal file
View File

@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SQL Fixtures" type="ShConfigurationType">
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/src/main/resources/sql/fixtures/fixtures.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/src/main/resources/sql/fixtures/" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="false" />
<option name="INTERPRETER_PATH" value="C:/Program Files/Git/bin/bash.exe" />
<option name="INTERPRETER_OPTIONS" value="" />
<method v="2" />
</configuration>
</component>

View File

@@ -1,12 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SQL Tests" type="ShConfigurationType">
<option name="INDEPENDENT_SCRIPT_PATH" value="false" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/src/test/test.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/src/test" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="false" />
<option name="INTERPRETER_PATH" value="C:/Program Files/Git/git-bash.exe" />
<option name="INTERPRETER_PATH" value="C:/Program Files/Git/bin/bash.exe" />
<option name="INTERPRETER_OPTIONS" value="" />
<method v="2" />
</configuration>

View File

@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.owasp.dependencycheck.reporting.ReportGenerator
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
val ktor_version: String by project
val kotlin_version: String by project
@@ -9,7 +10,7 @@ val koinVersion: String by project
val jackson_version: String by project
val cucumber_version: String by project
group = "fr.dcproject"
group = "com.github.flecomte"
version = "0.0.1"
plugins {
@@ -19,7 +20,7 @@ plugins {
id("maven-publish")
id("org.jetbrains.kotlin.jvm") version "1.3.50"
id("com.github.johnrengelman.shadow") version "5.0.0"
id("com.github.johnrengelman.shadow") version "5.2.0"
id("org.jlleitschuh.gradle.ktlint") version "8.2.0"
id("org.owasp.dependencycheck") version "5.1.0"
id("org.sonarqube") version "2.7"
@@ -44,6 +45,12 @@ tasks.withType<Jar> {
}
}
tasks {
named<ShadowJar>("shadowJar") {
mergeServiceFiles("META-INF/services")
}
}
jacoco {
toolVersion = "0.8.3"
}
@@ -86,7 +93,7 @@ dependencies {
implementation("net.pearx.kasechange:kasechange-jvm:1.1.0")
implementation("com.auth0:java-jwt:3.8.2")
implementation("com.github.jasync-sql:jasync-postgresql:1.0.7")
implementation("com.github.flecomte:postgres-json:1.0.4")
implementation("com.github.flecomte:postgres-json:1.1.1")
implementation("com.github.flecomte:ktor-voter:1.0.1")
implementation("com.sendgrid:sendgrid-java:4.4.1")
implementation("io.lettuce:lettuce-core:5.2.2.RELEASE")

View File

@@ -42,10 +42,11 @@ services:
ports:
- ${APP_PORT}:8080
environment:
DB_HOST: db
DB_HOST: ${DB_HOST}
SEND_GRID_KEY: ${SEND_GRID_KEY}
REDIS_CONNECTION: redis://redis:6379
RABBITMQ_CONNECTION: amqp://rabbitmq:5671
REDIS_CONNECTION: ${REDIS_CONNECTION}
RABBITMQ_CONNECTION: ${RABBITMQ_CONNECTION}
ELASTICSEARCH_CONNECTION: ${ELASTICSEARCH_CONNECTION}
depends_on:
- elasticsearch
- db

View File

@@ -9,7 +9,6 @@ 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

@@ -73,7 +73,6 @@ fun Application.module(env: Env = PROD) {
}
install(DataConversion) {
// TODO move to postgresJson lib
convert<UUID> {
decode { values, _ ->
values.singleOrNull()?.let { UUID.fromString(it) }
@@ -359,7 +358,6 @@ fun Application.module(env: Env = PROD) {
maxAge = Duration.ofDays(1)
}
// TODO move to postgresJson lib
if (env == PROD) {
get<Migrations>().run()
}

View File

@@ -5,17 +5,16 @@ import com.auth0.jwt.JWTVerifier
import com.auth0.jwt.algorithms.Algorithm
import com.typesafe.config.ConfigFactory
import fr.dcproject.entity.UserI
import org.eclipse.jetty.util.resource.JarResource
import java.io.File
import java.util.*
import java.net.URI
class Config {
object Config {
private var config = ConfigFactory.load()
val sqlFiles: File = try {
File(this::class.java.getResource("/sql").toURI())
} catch (e: IllegalArgumentException) {
JarResource.newResource("./resources/sql").file
object Sql {
val migrationFiles: URI = this::class.java.getResource("/sql/migrations").toURI()
val functionFiles: URI = this::class.java.getResource("/sql/functions").toURI()
val fixtureFiles: URI = this::class.java.getResource("/sql/fixtures").toURI()
}
val envName: String = config.getString("app.envName")
@@ -27,6 +26,7 @@ class Config {
var password: String = config.getString("db.password")
val port: Int = config.getInt("db.port")
val redis: String = config.getString("redis.connection")
val elasticsearch: String = config.getString("elasticsearch.connection")
val rabbitmq: String = config.getString("rabbitmq.connection")
val exchangeNotificationName = "notification"
val sendGridKey: String = config.getString("mail.sendGrid.key")

View File

@@ -39,35 +39,33 @@ import fr.dcproject.repository.VoteComment as VoteCommentRepository
import fr.dcproject.repository.VoteConstitution as VoteConstitutionRepository
import fr.dcproject.repository.Workgroup as WorkgroupRepository
val config = Config()
@KtorExperimentalAPI
val Module = module {
single { config }
single { Config }
// SQL connection
single {
Connection(
host = config.host,
port = config.port,
database = config.database,
username = config.username,
password = config.password
host = Config.host,
port = Config.port,
database = Config.database,
username = Config.username,
password = Config.password
)
}
// Launch Database migration
single { Migrations(connection = get(), directory = config.sqlFiles) }
single { Migrations(get(), Config.Sql.migrationFiles, Config.Sql.functionFiles) }
// Redis client
single<RedisAsyncCommands<String, String>> {
RedisClient.create(config.redis).connect()?.async() ?: error("Unable to connect to redis")
RedisClient.create(Config.redis).connect()?.async() ?: error("Unable to connect to redis")
}
// RabbitMQ
single<ConnectionFactory> {
ConnectionFactory().apply { setUri(config.rabbitmq) }
ConnectionFactory().apply { setUri(Config.rabbitmq) }
}
// JsonSerializer
@@ -93,7 +91,7 @@ val Module = module {
single {
Requester.RequesterFactory(
connection = get(),
functionsDirectory = config.sqlFiles.resolve("functions")
functionsDirectory = Config.Sql.functionFiles
).createRequester()
}
@@ -117,15 +115,15 @@ val Module = module {
// Elasticsearch Client
single<RestClient> {
RestClient.builder(
HttpHost("localhost", 9200, "http")
HttpHost.create(Config.elasticsearch)
).build()
}
single { ArticleViewManager(get()) }
// Mailler
single { Mailer(config.sendGridKey) }
single { Mailer(Config.sendGridKey) }
// SSO Manager for connection
single { SsoManager(get<Mailer>(), config.domain, get()) }
single { SsoManager(get<Mailer>(), Config.domain, get()) }
}

View File

@@ -3,7 +3,7 @@ package fr.dcproject.event
import com.fasterxml.jackson.databind.ObjectMapper
import com.rabbitmq.client.*
import com.rabbitmq.client.BuiltinExchangeType.DIRECT
import fr.dcproject.config
import fr.dcproject.Config
import fr.dcproject.entity.Article
import fr.dcproject.event.publisher.Publisher
import fr.dcproject.repository.Follow
@@ -32,7 +32,7 @@ fun EventSubscriber.Configuration.configEvent(
serialiser: ObjectMapper
) {
/* Config Rabbit */
val exchangeName = config.exchangeNotificationName
val exchangeName = Config.exchangeNotificationName
rabbitFactory.newConnection().use { connection ->
connection.createChannel().use { channel ->
channel.queueDeclare("push", true, false, false, null)

View File

@@ -2,7 +2,7 @@ package fr.dcproject.event.publisher
import com.fasterxml.jackson.databind.ObjectMapper
import com.rabbitmq.client.ConnectionFactory
import fr.dcproject.config
import fr.dcproject.Config
import fr.dcproject.event.EntityEvent
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
@@ -19,7 +19,7 @@ class Publisher(
return GlobalScope.launch {
factory.newConnection().use { connection ->
connection.createChannel().use { channel ->
channel.basicPublish(config.exchangeNotificationName, "", null, it.serialize().toByteArray())
channel.basicPublish(Config.exchangeNotificationName, "", null, it.serialize().toByteArray())
logger.debug("Publish message ${it.target.id}")
}
}

View File

@@ -32,6 +32,11 @@ rabbitmq {
connection = ${?RABBITMQ_CONNECTION}
}
elasticsearch {
connection = "http://localhost:9200"
connection = ${?ELASTICSEARCH_CONNECTION}
}
mail {
sendGrid {
key = ${?SEND_GRID_KEY}

View File

@@ -1,6 +1,6 @@
import feature.KtorServerContext
import fr.dcproject.Config
import fr.dcproject.Env.CUCUMBER
import fr.dcproject.config
import fr.dcproject.module
import fr.dcproject.utils.LoggerDelegate
import fr.postgresjson.connexion.Connection
@@ -36,9 +36,9 @@ class RunCucumberTest : En, KoinTest {
init {
if (!unitialized) {
config.database = "test"
config.username = "test"
config.password = "test"
Config.database = "test"
Config.username = "test"
Config.password = "test"
withTestApplication({ module(CUCUMBER) }) {
migrations()
@@ -47,9 +47,9 @@ class RunCucumberTest : En, KoinTest {
}
Before(-1) { _: Scenario ->
config.database = "test"
config.username = "test"
config.password = "test"
Config.database = "test"
Config.username = "test"
Config.password = "test"
ktorContext.start()
//language=PostgreSQL
get<Connection>().sendQuery("start transaction;", listOf())
@@ -63,9 +63,9 @@ class RunCucumberTest : En, KoinTest {
}
private fun migrations() {
config.database = "test"
config.username = "test"
config.password = "test"
Config.database = "test"
Config.username = "test"
Config.password = "test"
val migrations: Migrations = get()
migrations.forceAllDown()
migrations.run()
@@ -89,7 +89,7 @@ class RunCucumberTest : En, KoinTest {
private fun getFixturesRequester(): Requester {
return Requester.RequesterFactory(
connection = get(),
queriesDirectory = config.sqlFiles.resolve("fixtures")
queriesDirectory = Config.Sql.fixtureFiles
).createRequester()
}
}