diff --git a/Dockerfile b/Dockerfile index 0d7c17d..346dbc5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY gradle gradle COPY build.gradle.kts settings.gradle.kts ./ COPY src src -RUN ./gradlew --no-daemon clean installDist +RUN gradle --no-daemon clean installDist FROM ${RUNTIME_IMAGE} WORKDIR /app @@ -20,4 +20,4 @@ RUN mkdir -p /app/scripts EXPOSE 8080 ENTRYPOINT ["/app/kotlin-scripts-host/bin/kotlin-scripts-host"] -CMD ["--port=8080", "--scripts-dir=/app/scripts"] +CMD ["--host=0.0.0.0", "--port=8080", "--scripts-dir=/app/scripts"] diff --git a/README.md b/README.md index b3686ef..32380b4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Watch mode: ## Run Web host (Ktor) ```bash -./gradlew runWeb --args='--port=8080 --scripts-dir=./scripts' +./gradlew runWeb --args='--host=0.0.0.0 --port=8080 --scripts-dir=./scripts' ``` Auth: diff --git a/docker-compose.yml b/docker-compose.yml index e6e60d6..13e97c8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,4 +15,4 @@ services: HOST_API_TOKEN: ${HOST_API_TOKEN:-} volumes: - ./scripts:/app/scripts - command: ["--port=8080", "--scripts-dir=/app/scripts"] + command: ["--host=0.0.0.0", "--port=8080", "--scripts-dir=/app/scripts"] diff --git a/src/main/kotlin/work/slhaf/hub/WebHost.kt b/src/main/kotlin/work/slhaf/hub/WebHost.kt index 2e201bc..932ab45 100644 --- a/src/main/kotlin/work/slhaf/hub/WebHost.kt +++ b/src/main/kotlin/work/slhaf/hub/WebHost.kt @@ -16,7 +16,7 @@ import java.io.File private const val DEFAULT_PORT = 8080 private const val DEFAULT_SCRIPTS_DIR = "scripts" -private const val HOST = "127.0.0.1" +private const val DEFAULT_HOST = "0.0.0.0" private fun Application.module(scriptsDir: File, apiToken: String) { routing { @@ -74,7 +74,7 @@ private fun usage() { println( """ Usage: - ./gradlew runWeb --args='[--port=8080] [--scripts-dir=./scripts]' + ./gradlew runWeb --args='[--host=0.0.0.0] [--port=8080] [--scripts-dir=./scripts]' Routes: GET /health Authorization: @@ -104,12 +104,13 @@ fun main(args: Array) { } val port = cli.optionValue("--port=")?.toIntOrNull() ?: DEFAULT_PORT + val host = cli.optionValue("--host=")?.ifBlank { DEFAULT_HOST } ?: DEFAULT_HOST val scriptsDir = File(cli.optionValue("--scripts-dir=") ?: DEFAULT_SCRIPTS_DIR).absoluteFile if (!scriptsDir.exists()) scriptsDir.mkdirs() val auth = loadOrCreateApiToken(scriptsDir) - println("Starting script web host on http://$HOST:$port") + println("Starting script web host on http://$host:$port") println("Scripts directory: ${scriptsDir.absolutePath}") println("Auth token source: ${auth.source}") when { @@ -119,7 +120,7 @@ fun main(args: Array) { else -> println("Auth token loaded from file: ${auth.tokenFile?.absolutePath}") } - embeddedServer(Netty, port = port, host = HOST) { + embeddedServer(Netty, port = port, host = host) { module(scriptsDir, auth.token) }.start(wait = true) }