add docker detect

This commit is contained in:
2024-01-21 15:39:19 +08:00
parent e4b0d4c872
commit 3542562a32
5 changed files with 23 additions and 8 deletions

View File

@@ -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 }}

View File

@@ -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

View File

@@ -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,8 +118,11 @@ export class Config {
return this._return_bool("export_zip_jpn_title") || false;
}
get hostname() {
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");
}

View File

@@ -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);

View File

@@ -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;
}