main
text 62 lines 1.52 KB
Raw
1 FROM debian:bookworm-slim
2
3 ARG HFS_VERSION
4 ARG TARGETARCH
5
6 WORKDIR /opt/hfs
7
8 RUN apt-get update \
9 && apt-get install -y --no-install-recommends ca-certificates curl unzip \
10 && rm -rf /var/lib/apt/lists/*
11
12 RUN set -eux; \
13 version="${HFS_VERSION#v}"; \
14 case "$TARGETARCH" in \
15 amd64) arch="x64" ;; \
16 arm64) arch="arm64" ;; \
17 *) echo "unsupported TARGETARCH: $TARGETARCH" >&2; exit 1 ;; \
18 esac; \
19 url="https://github.com/rejetto/hfs/releases/download/v${version}/hfs-linux-${arch}-${version}.zip"; \
20 curl -fsSL "$url" -o hfs.zip; \
21 unzip hfs.zip; \
22 rm hfs.zip
23
24 RUN cat <<'EOF' > /opt/hfs/docker-entrypoint.sh \
25 && chmod +x /opt/hfs/docker-entrypoint.sh
26 #!/bin/sh
27 set -e
28 export DISABLE_UPDATE=1
29
30 bootstrap_config() {
31 cwd="$1"
32 config="$cwd/config.yaml"
33 [ -f "$config" ] && return
34
35 mkdir -p "$cwd"
36 {
37 admin_pw="${HFS_CREATE_ADMIN:-please-change}"
38 esc="$(printf '%s' "$admin_pw" | sed "s/'/''/g")"
39 printf "create-admin: '%s'\\n" "$esc"
40 printf "vfs:\\n source: /shares\\n"
41 } > "$config"
42 }
43
44 if [ -n "${HFS_CWD:-}" ]; then
45 bootstrap_config "$HFS_CWD"
46 exec /opt/hfs/hfs --cwd "$HFS_CWD" "$@"
47 fi
48
49 # Legacy compatibility: keep older images working (config mounted at /home/hfs/.hfs).
50 if [ -d /home/hfs/.hfs ] || [ -f /home/hfs/.hfs/config.yaml ]; then
51 bootstrap_config /home/hfs/.hfs
52 exec /opt/hfs/hfs --cwd /home/hfs/.hfs "$@"
53 fi
54
55 bootstrap_config /data
56 exec /opt/hfs/hfs --cwd /data "$@"
57 EOF
58
59 EXPOSE 80
60 VOLUME ["/data"]
61
62 ENTRYPOINT ["/opt/hfs/docker-entrypoint.sh"]