cstr commited on
Commit
bc25d66
·
verified ·
1 Parent(s): 4bf75b2

fix docker cache handling

Browse files
Files changed (3) hide show
  1. Dockerfile +6 -3
  2. README.md +13 -0
  3. start.sh +21 -2
Dockerfile CHANGED
@@ -2,7 +2,7 @@ FROM ubuntu:22.04 AS build
2
  WORKDIR /src
3
 
4
  RUN apt-get update && \
5
- apt-get install -y build-essential cmake git curl && \
6
  rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
7
 
8
  ARG CRISPASR_REPO=https://github.com/CrispStrobe/CrispASR
@@ -12,8 +12,10 @@ RUN git clone --depth 1 "${CRISPASR_REPO}" /src/CrispASR && \
12
  git -C /src/CrispASR fetch --depth 1 origin "${CRISPASR_REF}" && \
13
  git -C /src/CrispASR checkout --detach FETCH_HEAD
14
  WORKDIR /src/CrispASR
15
- RUN cmake -B build -DWHISPER_BUILD_TESTS=OFF && \
16
- cmake --build build -j"$(nproc)" --target whisper-cli
 
 
17
 
18
  FROM ubuntu:22.04 AS runtime
19
  WORKDIR /space
@@ -35,6 +37,7 @@ RUN chmod +x /space/start.sh && \
35
 
36
  ENV PATH=/opt/crispasr/build/bin:$PATH
37
  ENV CRISPASR_SERVER_URL=http://127.0.0.1:8080
 
38
  ENV GRADIO_SERVER_NAME=0.0.0.0
39
  ENV GRADIO_SERVER_PORT=7860
40
 
 
2
  WORKDIR /src
3
 
4
  RUN apt-get update && \
5
+ apt-get install -y build-essential cmake git curl ninja-build && \
6
  rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
7
 
8
  ARG CRISPASR_REPO=https://github.com/CrispStrobe/CrispASR
 
12
  git -C /src/CrispASR fetch --depth 1 origin "${CRISPASR_REF}" && \
13
  git -C /src/CrispASR checkout --detach FETCH_HEAD
14
  WORKDIR /src/CrispASR
15
+ ARG CRISPASR_BUILD_JOBS
16
+ RUN jobs="${CRISPASR_BUILD_JOBS:-$(nproc)}" && \
17
+ cmake -S . -B build -G Ninja -DWHISPER_BUILD_TESTS=OFF && \
18
+ cmake --build build -j"${jobs}" --target whisper-cli
19
 
20
  FROM ubuntu:22.04 AS runtime
21
  WORKDIR /space
 
37
 
38
  ENV PATH=/opt/crispasr/build/bin:$PATH
39
  ENV CRISPASR_SERVER_URL=http://127.0.0.1:8080
40
+ ENV CRISPASR_CACHE_DIR=/cache
41
  ENV GRADIO_SERVER_NAME=0.0.0.0
42
  ENV GRADIO_SERVER_PORT=7860
43
 
README.md CHANGED
@@ -19,6 +19,7 @@ This folder contains a Hugging Face Docker Space wrapper for CrispASR:
19
  - `CRISPASR_BACKEND=whisper` or another backend name
20
  - `CRISPASR_LANGUAGE=en`
21
  - `CRISPASR_AUTO_DOWNLOAD=1`
 
22
  - `CRISPASR_EXTRA_ARGS=`
23
 
24
  ## Local build
@@ -30,3 +31,15 @@ docker run --rm -p 7860:7860 -p 8080:8080 \
30
  -v "$PWD/models:/models" \
31
  crispasr-hf-space
32
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  - `CRISPASR_BACKEND=whisper` or another backend name
20
  - `CRISPASR_LANGUAGE=en`
21
  - `CRISPASR_AUTO_DOWNLOAD=1`
22
+ - `CRISPASR_CACHE_DIR=/cache`
23
  - `CRISPASR_EXTRA_ARGS=`
24
 
25
  ## Local build
 
31
  -v "$PWD/models:/models" \
32
  crispasr-hf-space
33
  ```
34
+
35
+ For auto-downloads, mount a writable cache volume if you want models to survive container restarts:
36
+
37
+ ```bash
38
+ docker volume create crispasr-cache
39
+ docker run --rm -p 7860:7860 -p 8080:8080 \
40
+ -e CRISPASR_AUTO_DOWNLOAD=1 \
41
+ -v crispasr-cache:/cache \
42
+ crispasr-hf-space
43
+ ```
44
+
45
+ Build parallelism can be tuned with `--build-arg CRISPASR_BUILD_JOBS=8`.
start.sh CHANGED
@@ -15,10 +15,29 @@ MODEL_PATH="${CRISPASR_MODEL:-/models/model.gguf}"
15
  LANGUAGE="${CRISPASR_LANGUAGE:-en}"
16
  BACKEND="${CRISPASR_BACKEND:-whisper}"
17
  AUTO_DOWNLOAD="${CRISPASR_AUTO_DOWNLOAD:-1}"
 
18
  EXTRA_ARGS="${CRISPASR_EXTRA_ARGS:-}"
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  declare -a cmd
21
- cmd=(crispasr --server --host "$SERVER_HOST" --port "$SERVER_PORT" -l "$LANGUAGE")
22
 
23
  if [[ "$AUTO_DOWNLOAD" == "1" ]]; then
24
  cmd+=(-m auto --auto-download)
@@ -35,7 +54,7 @@ if [[ -n "$EXTRA_ARGS" ]]; then
35
  fi
36
 
37
  log "startup"
38
- log "server_host=$SERVER_HOST server_port=$SERVER_PORT backend=$BACKEND language=$LANGUAGE auto_download=$AUTO_DOWNLOAD"
39
  if [[ "$AUTO_DOWNLOAD" == "1" ]]; then
40
  log "model=auto"
41
  else
 
15
  LANGUAGE="${CRISPASR_LANGUAGE:-en}"
16
  BACKEND="${CRISPASR_BACKEND:-whisper}"
17
  AUTO_DOWNLOAD="${CRISPASR_AUTO_DOWNLOAD:-1}"
18
+ CACHE_DIR="${CRISPASR_CACHE_DIR:-/cache}"
19
  EXTRA_ARGS="${CRISPASR_EXTRA_ARGS:-}"
20
 
21
+ ensure_writable_dir() {
22
+ local dir="$1"
23
+ if [[ ! -d "$dir" ]]; then
24
+ if ! mkdir -p "$dir" 2>/dev/null; then
25
+ log "ERROR: could not create cache directory '$dir'"
26
+ exit 70
27
+ fi
28
+ fi
29
+ if [[ ! -w "$dir" ]]; then
30
+ log "ERROR: cache directory '$dir' is not writable by uid=$(id -u) gid=$(id -g)"
31
+ ls -ld "$dir" >&2 || true
32
+ log "If this is a bind mount, chown the host directory or set CRISPASR_CACHE_DIR to a writable path."
33
+ exit 70
34
+ fi
35
+ }
36
+
37
+ ensure_writable_dir "$CACHE_DIR"
38
+
39
  declare -a cmd
40
+ cmd=(crispasr --server --host "$SERVER_HOST" --port "$SERVER_PORT" -l "$LANGUAGE" --cache-dir "$CACHE_DIR")
41
 
42
  if [[ "$AUTO_DOWNLOAD" == "1" ]]; then
43
  cmd+=(-m auto --auto-download)
 
54
  fi
55
 
56
  log "startup"
57
+ log "server_host=$SERVER_HOST server_port=$SERVER_PORT backend=$BACKEND language=$LANGUAGE auto_download=$AUTO_DOWNLOAD cache_dir=$CACHE_DIR"
58
  if [[ "$AUTO_DOWNLOAD" == "1" ]]; then
59
  log "model=auto"
60
  else