Skip to content

Commit

Permalink
Prepare for multiple server implementations (#33)
Browse files Browse the repository at this point in the history
* Move the current Spring-based server implementation under a gradle module
* Use Gradle plugin for working with docker-compose
* Get rid of bash scripts / Makefile used in CI and for local development
* Introduce a separate source set called integrationTest
  • Loading branch information
ilya40umov authored Dec 1, 2021
1 parent e83e467 commit 1630256
Show file tree
Hide file tree
Showing 164 changed files with 420 additions and 410 deletions.
7 changes: 0 additions & 7 deletions .dockerignore

This file was deleted.

21 changes: 0 additions & 21 deletions .envrc

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
java-version: '11'
distribution: 'adopt'
- name: Run Tests & Build JAR
run: ./environment/bin/kotlink_ci
run: ./gradlew clean build jacocoTestReport
- name: Upload JAR File
uses: actions/upload-artifact@v2
with:
name: jar_file
path: build/libs/kotlink.jar
path: server-spring/build/libs/kotlink.jar
- name: Report Detekt Issues
if: github.ref == 'refs/heads/master'
uses: github/codeql-action/upload-sarif@v1
Expand All @@ -44,7 +44,7 @@ jobs:
uses: actions/download-artifact@v2
with:
name: jar_file
path: build/libs/
path: server-spring/build/libs/
- name: Login To DockerHub
uses: docker/login-action@v1
with:
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Build & Push Image
uses: docker/build-push-action@v2
with:
context: .
context: ./server-spring/
platforms: linux/amd64
push: true
tags: ilya40umov/kotlink:develop
Expand All @@ -67,7 +67,7 @@ jobs:
uses: actions/download-artifact@v2
with:
name: jar_file
path: build/libs/
path: server-spring/build/libs/
- name: Login To DockerHub
uses: docker/login-action@v1
with:
Expand All @@ -83,7 +83,7 @@ jobs:
- name: Build & Push Image
uses: docker/build-push-action@v2
with:
context: .
context: ./server-spring/
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
14 changes: 0 additions & 14 deletions Makefile

This file was deleted.

19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ by typing *kk␣vim␣shortcuts↵*, the user will be redirected to the actual l

Please beware that to make use of the browser extension,
you will first need to set up a dedicated KotLink server,
as it's going to store all of the links / namespaces for your team.
as it's going to store all the links / namespaces for your team.

### Supported Browsers

Expand All @@ -55,9 +55,16 @@ KotLink server requires an instance of PostgreSQL as the backend store,
and encapsulates all the logic around storing / resolving URL aliases,
as well as UI for creating / editing them.

For evaluation purposes, you can run KotLink server on your machine with the following commands,
given that you have [Docker](https://en.wikipedia.org/wiki/Docker_(software)) installed
(you may have to add `sudo` before all calls to `docker` depending on your system):
Assuming you have [Docker](https://en.wikipedia.org/wiki/Docker_(software)) and `docker-compose` installed,
you can run KotLink server on your machine for evaluation purposes with the following commands:

```
git clone https://github.com/ilya40umov/KotLink.git && cd KotLink
./gradlew bootRun
```

Alternatively, if you don't want to clone the repository, you can use the following set of commands:

```
docker network create kotlink-network
Expand Down Expand Up @@ -97,6 +104,10 @@ Through environment variables, you will also be able to restrict who can access

When you are done evaluating, you can run the following command to clean up containers from your machine:

```./gradlew composeDownForce```

or if you chose the second approach:

```docker rm -f kotlink-postgres && docker network rm kotlink-network```

For the detailed instructions on how to permanently set up your own KotLink server,
Expand Down
197 changes: 79 additions & 118 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,80 +1,101 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "org.kotlink"

repositories {
mavenCentral()
}

plugins {
// built-in plugins
java
jacoco
// versions of all kotlin plugins are resolved by logic in 'settings.gradle.kts'
kotlin("jvm")
kotlin("kapt")
kotlin("plugin.spring")
kotlin("plugin.allopen")
// version of spring boot plugin is also resolved by 'settings.gradle.kts'
id("org.springframework.boot")
// other plugins require a version to be mentioned
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("io.gitlab.arturbosch.detekt") version "1.17.0"

val kotlinVersion = "1.6.0"
kotlin("jvm") version kotlinVersion apply false
kotlin("kapt") version kotlinVersion apply false
kotlin("plugin.spring") version kotlinVersion apply false
kotlin("plugin.allopen") version kotlinVersion apply false

id("io.gitlab.arturbosch.detekt") version "1.19.0"
id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
id("com.github.ben-manes.versions") version "0.39.0"
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
allprojects {
group = "org.kotlink"
version = "0.0.1-SNAPSHOT"

repositories {
mavenLocal()
mavenCentral()
}
}

jacoco {
toolVersion = "0.8.7"
subprojects {
apply<JavaPlugin>()
apply<JacocoPlugin>()

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
withType<Test> {
testLogging.apply {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
debug {
showStandardStreams = true
}
}
}
}
}

dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.19.0")
}

detekt {
buildUponDefaultConfig = true
config = files("src/main/resources/detekt-config.yml")
reports {
html.enabled = true
xml.enabled = true
txt.enabled = true
sarif.enabled = true
ktlint {
enableExperimentalRules.set(false)
disabledRules.set(setOf("final-newline"))
filter {
disabledRules.set(setOf("final-newline", "indent"))
}
filter {
exclude("**.kts")
}
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = listOf("-Xjsr305=strict")
val detekt by named("detekt", Detekt::class) {
description = "Runs Detekt to perform code analysis"
buildUponDefaultConfig = true
config.setFrom(files(projectDir.resolve("detekt.yml")))
setSource(files(*subprojects.map { "${it.projectDir}/src" }.toTypedArray()))
autoCorrect = false
ignoreFailures = false
reports {
sarif.required.set(true)
}
}
withType<Test> {
useJUnitPlatform {
val properties = mapOf(
"spring.datasource.url" to "jdbc:postgresql://localhost:55432/kotlink",
"spring.redis.url" to "redis://localhost:6379"
)
properties.forEach { (name, defaultValue) ->
systemProperty(name, System.getProperty(name) ?: defaultValue)
}
}
testLogging.apply {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
}
val check by registering {
dependsOn(detekt)
}
withType<JacocoReport> {
reports {
xml.apply {
isEnabled = true
}
html.apply {
isEnabled = false
}
register("build") {
dependsOn(check)
}
register("jacocoAggregatedReport", JacocoReport::class) {
reports.html.required.set(true)
reports.xml.required.set(true)
subprojects.filter { it.name != "assembly" }.forEach { subProject ->
dependsOn(subProject.tasks.findByPath("test"))
executionData(subProject.tasks.findByPath("test"))
additionalSourceDirs(files("${subProject.projectDir}/src/kotlin/main"))
additionalClassDirs(files("${subProject.buildDir}/classes/kotlin/main"))
}
}

Expand All @@ -93,64 +114,4 @@ tasks {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
}
}

dependencies {

val exposedVersion = "0.31.1"
val logbackVersion = "1.2.3"

implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")

implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-aop")
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("org.springframework.session:spring-session-jdbc")
implementation("org.springframework.session:spring-session-data-redis")
implementation("org.springframework.boot:spring-boot-devtools")

compileOnly("org.springframework.boot:spring-boot-configuration-processor")
kapt("org.springframework.boot:spring-boot-configuration-processor")

implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5")

implementation("com.github.ben-manes.caffeine:caffeine")
implementation("io.micrometer:micrometer-registry-prometheus")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.github.microutils:kotlin-logging:2.0.6")
implementation("org.slf4j:slf4j-api:1.7.30")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("ch.qos.logback:logback-core:$logbackVersion")
implementation("ch.qos.logback:logback-access:$logbackVersion")
implementation("org.apache.logging.log4j:log4j-to-slf4j:2.14.1")
implementation("org.postgresql:postgresql:42.2.20")
implementation("org.flywaydb:flyway-core:7.9.1")

implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:spring-transaction:$exposedVersion")

implementation("nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.5.3")

val jupiterVersion = "5.7.2"

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testImplementation("org.amshove.kluent:kluent:1.65")
testImplementation("io.projectreactor:reactor-test")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
testImplementation("org.mockito:mockito-junit-jupiter:3.10.0")

detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.17.0")
}
}
6 changes: 6 additions & 0 deletions src/main/resources/detekt-config.yml → detekt.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# https://detekt.github.io/detekt/configurations.html

config:
excludes: ''

build:
maxIssues: 25

complexity:
TooManyFunctions:
excludes: ['**/integrationTest/**', '**/test/**', '**/*Test.kt', '**/*Spec.kt']
thresholdInClasses: 20
thresholdInInterfaces: 20
LongParameterList:
constructorThreshold: 10

style:
MagicNumber:
excludes: ['**/integrationTest/**', '**/test/**', '**/*Test.kt', '**/*Spec.kt']
NewLineAtEndOfFile:
active: false

Expand Down
2 changes: 1 addition & 1 deletion docs/deployment-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ for more details.

To enable using Redis as a backing store for cache (by default lives in memory)
and for session information (by default is stored in Postgres),
which in turn will help improving performance and availability
which in turn will help to improve performance and availability
(e.g. without a stand-alone cache you can only have a single-node deployment of KotLink server,
as local caches on each node will quickly become stale and cause issues),
you can tweak the following properties:
Expand Down
Loading

0 comments on commit 1630256

Please sign in to comment.