Use .env handling in docker compose

This commit is contained in:
Mikołaj Pich 2022-11-24 01:41:08 +01:00
parent 0863115011
commit 9537ebdea2
3 changed files with 6 additions and 11 deletions

View file

@ -43,7 +43,6 @@ dependencies {
implementation("io.ktor:ktor-server-cors:$ktor_version")
implementation("io.ktor:ktor-server-call-logging:$ktor_version")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
implementation("io.github.cdimascio:dotenv-kotlin:6.3.1")
// client
implementation("io.ktor:ktor-client-cio-jvm:$ktor_version")

View file

@ -2,6 +2,8 @@ version: "3.5"
services:
manager:
build: .
env_file:
- .env
ports:
- "3001:3001"
networks:

View file

@ -1,6 +1,5 @@
package io.github.wulkanowy.manager.server
import io.github.cdimascio.dotenv.dotenv
import io.github.wulkanowy.manager.server.repositories.BitriseRepository
import io.github.wulkanowy.manager.server.repositories.GithubRepository
import io.github.wulkanowy.manager.server.services.BuildsService
@ -17,8 +16,6 @@ import kotlinx.serialization.json.Json
import org.koin.core.qualifier.named
import org.koin.dsl.module
val dotenv = dotenv()
val mainModule = module {
single { UnstableService(get(), get()) }
single { BuildsService(get()) }
@ -41,7 +38,7 @@ val mainModule = module {
}
install(HttpCache)
defaultRequest {
header("Authorization", "token " + dotenv["BITRISE_API_KEY"])
header("Authorization", "token " + System.getenv("BITRISE_API_KEY"))
}
}
}
@ -51,15 +48,12 @@ val mainModule = module {
level = LogLevel.INFO
}
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
})
json()
}
install(HttpCache)
defaultRequest {
val githubToken = dotenv["API_GITHUB_TOKEN"]
if (!githubToken.isNullOrBlank()) {
header("Authorization", "token $githubToken")
System.getenv("API_GITHUB_TOKEN").takeIf { !it.isNullOrBlank() }?.let {
header("Authorization", "token $it")
}
}
}