predownload sqlite3

This commit is contained in:
2024-01-29 12:31:50 +08:00
parent 1bf82f5dff
commit dc1e1ffbf2
3 changed files with 32 additions and 2 deletions

View File

@@ -90,13 +90,14 @@ ENV LD_LIBRARY_PATH=/app/lib
ENV PATH=/app/bin:$PATH
RUN deno task fetch && deno task server-build && deno task prebuild && \
deno task cache && rm -rf ~/.cache && \
deno task cache && deno task download_ffi && rm -rf ~/.cache && \
mkdir -p ./thumbnails && chmod 777 ./thumbnails && \
mkdir -p ./downloads && chmod 777 ./downloads && \
mkdir -p ./data && chmod 777 ./data && chmod 777 /deno-dir
ENV DENO_DEPLOYMENT_ID=${DENO_DEPLOYMENT_ID}
ENV DOCKER=true
ENV DB_USE_FFI=true
ENV DENO_SQLITE_PATH=/app/lib/libsqlite3.so
EXPOSE 8000
ENTRYPOINT ["/tini", "--", "deno", "task", "server"]

View File

@@ -12,7 +12,8 @@
"fetch": "deno run --allow-read=./ --allow-write=./ --allow-net fetch_static_files.ts",
"gen_meili_server_key": "deno run --allow-net scripts/gen_meili_server_key.ts",
"server-build": "deno run -A server-dev.ts build",
"prebuild": "deno run -A scripts/prebuild.ts"
"prebuild": "deno run -A scripts/prebuild.ts",
"download_ffi": "deno run --allow-read=./ --allow-write=./lib --allow-net scripts/download_ffi.ts"
},
"fmt": {
"indentWidth": 4,

28
scripts/download_ffi.ts Normal file
View File

@@ -0,0 +1,28 @@
import { dirname } from "std/path/mod.ts";
import { sure_dir } from "../utils.ts";
const map = JSON.parse(await Deno.readTextFile("./import_map.json")).imports;
const re = /x\/sqlite3@([0-9\.]+)/;
const sqlite3_version = map["sqlite3/"].match(re)[1];
async function fetch_file(u: string | URL, p: string) {
await sure_dir(dirname(p));
const f = await Deno.open(p, { create: true, write: true, truncate: true });
try {
const r = await fetch(u);
if (!r.body) throw Error("No body.");
await r.body.pipeTo(f.writable);
} finally {
try {
f.close();
} catch (_) {
null;
}
}
}
await fetch_file(
`https://github.com/denodrivers/sqlite3/releases/download/${sqlite3_version}/libsqlite3.so`,
`./lib/libsqlite3.so`,
);
Deno.exit(0);