From 340459f7833e1b623a01ddcdbc46b0300cb42ce1 Mon Sep 17 00:00:00 2001 From: slhafzjw Date: Tue, 24 Feb 2026 18:35:12 +0800 Subject: [PATCH] chore: add Docker support for running the web host --- .dockerignore | 8 ++++++++ Dockerfile | 23 +++++++++++++++++++++++ README.md | 20 ++++++++++++++++++++ build.gradle.kts | 2 +- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6b53659 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git +.gradle +.gradle-user +.idea +.kotlin +build +kls_database.db +scripts/.host-api-token diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d7c17d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +ARG BUILD_IMAGE=gradle:9.0.0-jdk17 +ARG RUNTIME_IMAGE=eclipse-temurin:17-jre + +FROM ${BUILD_IMAGE} AS build +WORKDIR /workspace + +COPY gradlew gradlew +COPY gradle gradle +COPY build.gradle.kts settings.gradle.kts ./ +COPY src src + +RUN ./gradlew --no-daemon clean installDist + +FROM ${RUNTIME_IMAGE} +WORKDIR /app + +COPY --from=build /workspace/build/install/kotlin-scripts-host /app/kotlin-scripts-host +RUN mkdir -p /app/scripts + +EXPOSE 8080 + +ENTRYPOINT ["/app/kotlin-scripts-host/bin/kotlin-scripts-host"] +CMD ["--port=8080", "--scripts-dir=/app/scripts"] diff --git a/README.md b/README.md index 40801bb..77b840e 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,23 @@ Create/Edit/Delete behavior: Editor selection: - First uses `$EDITOR` - Fallback to first available of `nvim`, `vim`, `nano` + +## Docker +Build image: +```bash +docker build -t slhaf-hub:latest . +``` + +Run container (mount local scripts directory): +```bash +docker run --rm -p 8080:8080 \ + -v /tmp/kotlin-scripts/scripts:/app/scripts \ + -e HOST_API_TOKEN=your-token \ + slhaf-hub:latest +``` + +Then call APIs: +```bash +curl http://127.0.0.1:8080/health +curl -H "Authorization: Bearer your-token" http://127.0.0.1:8080/scripts +``` diff --git a/build.gradle.kts b/build.gradle.kts index 2447c4a..b762289 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,7 +29,7 @@ kotlin { } application { - mainClass.set("work.slhaf.hub.CliHostKt") + mainClass.set("work.slhaf.hub.WebHostKt") } val runCli by tasks.registering(JavaExec::class) {