Skip to content

Commit

Permalink
feat: use mergerfs to create shared cache between image and host
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Apr 27, 2024
1 parent 8bdfbeb commit fe15fde
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
14 changes: 13 additions & 1 deletion reactive_home/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
5 changes: 5 additions & 0 deletions reactive_home/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ arch:
homeassistant_api: true
map:
- config:rw
devices:
- /dev/fuse
apparmor: unconfined
privileged:
- SYS_ADMIN
11 changes: 11 additions & 0 deletions reactive_home/get-version.ts
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 14 additions & 2 deletions reactive_home/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit fe15fde

Please sign in to comment.