diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index a73f6c1..34855f3 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -40,5 +40,7 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha,scope=docker-cache + cache-to: type=gha,mode=max,scope=docker-cache build-args: | DENO_DEPLOYMENT_ID=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index d9b3030..c93516a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,16 +85,12 @@ COPY ./deno.json ./ COPY ./import_map.json ./ COPY ./LICENSE ./ -RUN apt-get update && apt-get install -y --no-install-recommends \ - zlib1g \ - && rm -rf /var/lib/apt/lists/* - ENV LD_LIBRARY_PATH=/app/lib ENV PATH=/app/bin:$PATH -RUN deno task fetch && deno task server-build && mkdir -p ./thumbnails && chmod 777 ./thumbnails && mkdir -p ./downloads && chmod 777 ./downloads +RUN deno task fetch && deno task server-build && mkdir -p ./thumbnails && chmod 777 ./thumbnails && mkdir -p ./downloads && chmod 777 ./downloads && mkdir -p ./data && chmod 777 ./data ENV DENO_DEPLOYMENT_ID=${DENO_DEPLOYMENT_ID} -ENV DOCKER=1 +ENV DOCKER=true EXPOSE 8000 ENTRYPOINT deno task server diff --git a/config.ts b/config.ts index 6f6a8a6..4516bc4 100644 --- a/config.ts +++ b/config.ts @@ -1,5 +1,6 @@ import { exists } from "std/fs/exists.ts"; import { JsonValue, parse } from "std/jsonc/mod.ts"; +import { isDocker } from "./utils.ts"; export type ConfigType = { cookies: boolean; @@ -81,6 +82,9 @@ export class Config { return this._return_string("cookies"); } get db_path() { + if (isDocker()) { + return this._return_string("db_path") || "./data"; + } return this._return_string("db_path"); } get ua() { @@ -114,7 +118,10 @@ export class Config { return this._return_bool("export_zip_jpn_title") || false; } get hostname() { - return this._return_string("hostname") || "0.0.0.0"; + if (isDocker()) { + return this._return_string("hostname") || "0.0.0.0"; + } + return this._return_string("hostname") || "127.0.0.1"; } get meili_host() { return this._return_string("meili_host"); diff --git a/server-run.ts b/server-run.ts index c94e152..8e30b81 100644 --- a/server-run.ts +++ b/server-run.ts @@ -1,3 +1,6 @@ import { startServer } from "./server.ts"; +import { isDocker } from "./utils.ts"; -await startServer("./config.json"); +const configPath = isDocker() ? "./data/config.json" : "./config.json"; + +await startServer(configPath); diff --git a/utils.ts b/utils.ts index 264054a..b02cbbe 100644 --- a/utils.ts +++ b/utils.ts @@ -270,3 +270,10 @@ export class TimeoutError extends Error { super("Timeout"); } } + +let _isDocker: boolean | undefined = undefined; + +export function isDocker() { + if (_isDocker === undefined) _isDocker = parse_bool(Deno.env.get("DOCKER") ?? "false"); + return _isDocker; +}