Skip to content

Commit

Permalink
remove copied env
Browse files Browse the repository at this point in the history
  • Loading branch information
storytellerF committed Jan 12, 2025
1 parent 618573f commit 588b694
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ WORKDIR /app
COPY --from=builder /app/server/build/libs/*-all.jar ./lib/ktor-server.jar
COPY --from=builder /app/cli/build/decompressed/cli .
COPY --from=builder /app/deploy ./deploy
COPY --from=builder /app/build/envs/*.env .
COPY scripts/tool_scripts/flush-database-singleton.sh ./scripts/tool_scripts/flush-database-singleton.sh

ENTRYPOINT ["java","-jar","./lib/ktor-server.jar"]
19 changes: 19 additions & 0 deletions Dockerfile.patched
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ ARG BUNKER_PORT
ENV BUNKER_PORT=$BUNKER_PORT
ARG BUNKER_PORT_SECRET
ENV BUNKER_PORT_SECRET=$BUNKER_PORT_SECRET
ARG BUNKER_ADMIN
ENV BUNKER_ADMIN=$BUNKER_ADMIN
ARG BUNKER_PASS
ENV BUNKER_PASS=$BUNKER_PASS
ARG BUNKER_DB
ENV BUNKER_DB=$BUNKER_DB
ARG BUNKER_DB_URI
ENV BUNKER_DB_URI=$BUNKER_DB_URI
ARG BUNKER_DB_USER
ENV BUNKER_DB_USER=$BUNKER_DB_USER
ARG BUNKER_DB_PASS
ENV BUNKER_DB_PASS=$BUNKER_DB_PASS
ARG SERVER_PORT
ENV SERVER_PORT=$SERVER_PORT
ARG SERVER_URL
Expand Down Expand Up @@ -142,6 +154,12 @@ HMAC_KEY=${HMAC_KEY}
BUNKER_VERSION=${BUNKER_VERSION}
BUNKER_PORT=${BUNKER_PORT}
BUNKER_PORT_SECRET=${BUNKER_PORT_SECRET}
BUNKER_ADMIN=${BUNKER_ADMIN}
BUNKER_PASS=${BUNKER_PASS}
BUNKER_DB=${BUNKER_DB}
BUNKER_DB_URI=${BUNKER_DB_URI}
BUNKER_DB_USER=${BUNKER_DB_USER}
BUNKER_DB_PASS=${BUNKER_DB_PASS}
SERVER_PORT=${SERVER_PORT}
SERVER_URL=${SERVER_URL}
WS_SERVER_URL=${WS_SERVER_URL}
Expand Down Expand Up @@ -174,6 +192,7 @@ WORKDIR /app
COPY --from=builder /app/server/build/libs/*-all.jar ./lib/ktor-server.jar
COPY --from=builder /app/cli/build/decompressed/cli .
COPY --from=builder /app/deploy ./deploy
COPY --from=builder /app/build/envs/*.env .
COPY scripts/tool_scripts/flush-database-singleton.sh ./scripts/tool_scripts/flush-database-singleton.sh

ENTRYPOINT ["java","-jar","./lib/ktor-server.jar"]
24 changes: 12 additions & 12 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ sourceSets {
main {
resources {
srcDirs(
layout.buildDirectory.dir("copied/resources"),
layout.buildDirectory.dir("copied-ca/resources"),
// layout.buildDirectory.dir("copied/resources"),
// layout.buildDirectory.dir("copied-ca/resources"),
layout.buildDirectory.dir("merged/services")
)
}
Expand All @@ -58,15 +58,15 @@ sourceSets {

val flavor = project.findProperty("buildkonfig.flavor")

val copyTask = tasks.register("copyEnv", Copy::class) {
group = "copy"
from("../${flavor}.env")
enabled = File(rootDir, "${flavor}.env").exists()
into(layout.buildDirectory.dir("copied/resources"))
rename {
".env"
}
}
//val copyTask = tasks.register("copyEnv", Copy::class) {
// group = "copy"
// from("../${flavor}.env")
// enabled = File(rootDir, "${flavor}.env").exists()
// into(layout.buildDirectory.dir("copied/resources"))
// rename {
// ".env"
// }
//}

val mergeServiceFiles = tasks.register("mergeServiceFiles") {
group = "build"
Expand Down Expand Up @@ -104,6 +104,6 @@ val mergeServiceFiles = tasks.register("mergeServiceFiles") {
}
}

tasks.processResources.dependsOn(copyTask)
//tasks.processResources.dependsOn(copyTask)
tasks.processResources.dependsOn(mergeServiceFiles)

16 changes: 15 additions & 1 deletion backend/src/main/kotlin/com/storyteller_f/Backend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import io.github.aakira.napier.Napier
import org.jetbrains.exposed.sql.Query
import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.andWhere
import java.io.File
import java.io.FileInputStream
import java.nio.file.Paths
import java.util.*

Expand Down Expand Up @@ -41,7 +43,7 @@ class MergedEnv(val list: List<Map<String, String>?>) {
}

fun readEnv(map: Map<String, String> = emptyMap()): MergedEnv {
return MergedEnv(listOf(map, readResourceEnv(".env"), System.getenv()))
return MergedEnv(listOf(map, readFileEnv(".env"), readResourceEnv(".env"), System.getenv()))
}

fun readResourceEnv(resName: String) = ClassLoader.getSystemClassLoader().getResourceAsStream(resName)?.use {
Expand All @@ -52,6 +54,18 @@ fun readResourceEnv(resName: String) = ClassLoader.getSystemClassLoader().getRes
it.key as String to it.value as String
}?.associate { it }

fun readFileEnv(resName: String) = (if (File(resName).exists()) {
FileInputStream(resName).use {
Properties().apply {
load(it)
}
}.map {
it.key as String to it.value as String
}.associate { it }
} else {
emptyMap()
})

fun buildBackendFromEnv(env: MergedEnv): Backend {
println("load env: ${env["COMPOSE_PROJECT_NAME"]}")

Expand Down
1 change: 1 addition & 0 deletions scripts/build_scripts/build-server-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FILE="build/images/$FLAVOR.image.tar"
# 检查文件是否存在
if [ ! -f "$FILE" ]; then
./scripts/build_scripts/build-all-in-flavor.sh "$FLAVOR" true
mkdir -p build/envs && cp $FLAVOR.env build/envs/.env
docker build --platform linux/amd64 --build-arg IS_PROD=$IS_PROD --build-arg FLAVOR=$FLAVOR --build-arg BUILD_ON=$BUILD_ON -t a-server:latest .
else
echo "$FILE already exists. Skipping docker image build."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ fun main(args: Array<String>) {

processPreSetData(map)

val serverPort = (map["SERVER_PORT"] as String).toInt()
val serverPort = map["SERVER_PORT"].toInt()
val extraArgs = arrayOf("-port=$serverPort")

EngineMain.main(args + extraArgs)
}

private fun processPreSetData(env: MergedEnv) {
val preSetEnable = (env["PRESET_ENABLE"] as String).toBoolean()
val preSetEnable = env["PRESET_ENABLE"].toBoolean()
if (preSetEnable) {
val preSetScript = env["PRESET_SCRIPT"] as String
val workingDir = env["PRESET_WORKING_DIR"] as String
val preSetScript = env["PRESET_SCRIPT"]
val workingDir = env["PRESET_WORKING_DIR"]
if (preSetScript.isNotBlank() && workingDir.isNotBlank()) {
val scriptArray = preSetScript.trim('\'').split(" ").map {
if (it.startsWith("~")) {
Expand Down

0 comments on commit 588b694

Please sign in to comment.