From fe15fde037b3a9dad90f69c2ca8cf0e111edf645 Mon Sep 17 00:00:00 2001 From: Nils Bergmann Date: Sat, 27 Apr 2024 19:20:36 +0200 Subject: [PATCH] feat: use mergerfs to create shared cache between image and host --- reactive_home/Dockerfile | 14 +++++++++++++- reactive_home/config.yaml | 5 +++++ reactive_home/get-version.ts | 11 +++++++++++ reactive_home/run.sh | 16 ++++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 reactive_home/get-version.ts diff --git a/reactive_home/Dockerfile b/reactive_home/Dockerfile index 4b16848..bb69234 100644 --- a/reactive_home/Dockerfile +++ b/reactive_home/Dockerfile @@ -5,15 +5,27 @@ FROM denoland/deno:bin-$DENO_VERSION AS deno FROM $BUILD_FROM +ENV DEBIAN_FRONTEND=noninteractive + COPY --from=deno /deno /usr/local/bin/deno +RUN apt update && \ + apt install mergerfs -yq && \ + rm -rf /var/lib/apt/lists/* + COPY run.sh / COPY deno.lock / COPY run.ts / COPY loader.ts / COPY config.yaml / COPY update-import-map.ts / +COPY get-version.ts / + +ENV DENO_DIR=/deno_image_cache -RUN chmod a+x /run.sh +RUN chmod a+x /run.sh && \ + mkdir /deno_image_cache && \ + deno cache "https://deno.land/x/reactivehome@$(deno run --allow-all /get-version.ts)/mod.ts" && \ + deno cache /loader.ts CMD [ "/run.sh" ] \ No newline at end of file diff --git a/reactive_home/config.yaml b/reactive_home/config.yaml index 04097e1..58ebf00 100644 --- a/reactive_home/config.yaml +++ b/reactive_home/config.yaml @@ -9,3 +9,8 @@ arch: homeassistant_api: true map: - config:rw +devices: + - /dev/fuse +apparmor: unconfined +privileged: + - SYS_ADMIN diff --git a/reactive_home/get-version.ts b/reactive_home/get-version.ts new file mode 100644 index 0000000..a093448 --- /dev/null +++ b/reactive_home/get-version.ts @@ -0,0 +1,11 @@ +const versionRegex = /version: "(.+?)"/gim; + +const configYaml = await Deno.readTextFile("/config.yaml"); + +const result = versionRegex.exec(configYaml); + +const version = result?.at?.(1); + +if (version) { + console.log(version); +} diff --git a/reactive_home/run.sh b/reactive_home/run.sh index ecabf5a..6f847cb 100644 --- a/reactive_home/run.sh +++ b/reactive_home/run.sh @@ -14,5 +14,17 @@ if [[ ! -f /config/reactive-home/import_map.json ]]; then }" >> /config/reactive-home/import_map.json fi -deno run --lock=/deno.lock --allow-read=/config/reactive-home/import_map.json,/config.yaml --allow-write=/config/reactive-home/import_map.json /update-import-map.ts -deno run --lock=/deno.lock --allow-env --allow-net --allow-run --allow-sys --allow-read /run.ts --root /config/reactive-home \ No newline at end of file +mkdir -p /config/reactive-home/deno_cache/npm +mkdir -p /config/reactive-home/deno_cache/deps +mkdir -p /config/reactive-home/deno_cache/gen + +mkdir -p /deno_cache/npm +mkdir -p /deno_cache/deps +mkdir -p /deno_cache/gen + +mergerfs /deno_image_cache/npm=RO:/config/reactive-home/deno_cache/npm /deno_cache/npm +mergerfs /deno_image_cache/deps=RO:/config/reactive-home/deno_cache/deps /deno_cache/deps +mergerfs /deno_image_cache/gen=RO:/config/reactive-home/deno_cache/gen /deno_cache/gen + +DENO_DIR=/deno_cache deno run --lock=/deno.lock --allow-read=/config/reactive-home/import_map.json,/config.yaml --allow-write=/config/reactive-home/import_map.json /update-import-map.ts +DENO_DIR=/deno_cache deno run --lock=/deno.lock --allow-env --allow-net --allow-run --allow-sys --allow-read /run.ts --root /config/reactive-home \ No newline at end of file