From f4852cd3bea7cdbdab6e6e28de8cbfa3042bee64 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Fri, 13 Mar 2026 13:16:00 +0200 Subject: [PATCH 01/11] docker deployment --- .gitignore | 1 + Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ Makefile | 16 ++++++++++++++++ docker-compose.yml | 21 +++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adbb97d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..877ac35 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM python:3.12-slim AS builder + +# Set working directory +WORKDIR /app + +# Install git only to clone the repo +RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* + +COPY . . + +# Install dependencies to a specific folder +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt + +FROM python:3.12-slim + +# Set environment variables +ENV APP_DIR=/opt/filament-management \ + PYTHONPATH=/opt/filament-management \ + UI_PORT=8005 + +WORKDIR $APP_DIR + +# Copy ONLY the installed libraries from the builder stage +COPY --from=builder /install /usr/local + +# Copy ONLY the application code from the builder stage +COPY --from=builder /app $APP_DIR + +# Expose the UI port +EXPOSE 8005 + +# Start the application +# We use the direct path to uvicorn instead of activating a venv +CMD printf '{\n "printer_url": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s"\n}\n' \ + "$PRINTER_URL" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" > $APP_DIR/data/config.json && \ + uvicorn main:app --host 0.0.0.0 --port 8005 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d87de09 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +up: + docker-compose up -d + +down: + docker-compose down + +restart: + docker-compose down && docker-compose up -d + +logs: + docker-compose logs -f + +pull: + docker-compose pull +build: + docker-compose build \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bd624d5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + cfsync: + build: . + container_name: cfsync + restart: unless-stopped + ports: + - "8005:8005" + environment: + - UI_PORT=8005 + - TZ=Asia/Jerusalem + - PRINTER_URL=PRINTER_IP_PLACEHOLDER + - FILAMENT_DIAMETER=1.75 + - SPOOLMAN_URL=http://SPOOLMAN_IP_PLACEHOLDER:7912 + volumes: + # This ensures your filament data survives container updates + - ./data:/opt/filament-management/data + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8005/"] + interval: 30s + timeout: 10s + retries: 3 From db4405f0823cc05bad5e38be05c92cfcbababe46 Mon Sep 17 00:00:00 2001 From: YogevBokobza Date: Fri, 13 Mar 2026 13:17:35 +0200 Subject: [PATCH 02/11] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index adbb97d..8fce603 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -data/ \ No newline at end of file +data/ From 2cf91ed1f48618707434176026f128b326486d47 Mon Sep 17 00:00:00 2001 From: YogevBokobza Date: Fri, 13 Mar 2026 13:18:08 +0200 Subject: [PATCH 03/11] Update Dockerfile --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 877ac35..acf4f48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,6 @@ COPY --from=builder /app $APP_DIR EXPOSE 8005 # Start the application -# We use the direct path to uvicorn instead of activating a venv CMD printf '{\n "printer_url": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s"\n}\n' \ "$PRINTER_URL" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" > $APP_DIR/data/config.json && \ - uvicorn main:app --host 0.0.0.0 --port 8005 \ No newline at end of file + uvicorn main:app --host 0.0.0.0 --port 8005 From aa4a38976d62a3cccabd5398da2b2505eadacf21 Mon Sep 17 00:00:00 2001 From: YogevBokobza Date: Fri, 13 Mar 2026 13:18:20 +0200 Subject: [PATCH 04/11] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d87de09..c504df3 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,4 @@ logs: pull: docker-compose pull build: - docker-compose build \ No newline at end of file + docker-compose build From 636a56bfe79f48b778f844ca873e334e31d18789 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Fri, 13 Mar 2026 13:22:51 +0200 Subject: [PATCH 05/11] fix --- Makefile | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index c504df3..bd73be1 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,12 @@ up: - docker-compose up -d - + docker-compose up -d down: - docker-compose down - + docker-compose down restart: - docker-compose down && docker-compose up -d - + docker-compose down && docker-compose up -d logs: - docker-compose logs -f - + docker-compose logs -f pull: - docker-compose pull + docker-compose pull build: - docker-compose build + docker-compose build From 810a6821b01b963e9e6b49c9bad46e017c3d09e9 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Sun, 15 Mar 2026 16:22:50 +0200 Subject: [PATCH 06/11] fix --- Dockerfile | 4 ++-- docker-compose.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index acf4f48..dbf44e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,6 @@ COPY --from=builder /app $APP_DIR EXPOSE 8005 # Start the application -CMD printf '{\n "printer_url": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s"\n}\n' \ - "$PRINTER_URL" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" > $APP_DIR/data/config.json && \ +CMD printf '{\n "printer_url": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s",\n "spoolman_mode": "%s"\n}\n' \ + "$PRINTER_URL" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" "$SPOOLMAN_MODE" > $APP_DIR/data/config.json && \ uvicorn main:app --host 0.0.0.0 --port 8005 diff --git a/docker-compose.yml b/docker-compose.yml index bd624d5..578af19 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - PRINTER_URL=PRINTER_IP_PLACEHOLDER - FILAMENT_DIAMETER=1.75 - SPOOLMAN_URL=http://SPOOLMAN_IP_PLACEHOLDER:7912 + - SPOOLMAN_MODE=direct # direct or moonraker volumes: # This ensures your filament data survives container updates - ./data:/opt/filament-management/data From b641790c754bb349698914276fe58504bddb0f70 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Sun, 15 Mar 2026 14:33:12 +0000 Subject: [PATCH 07/11] fix --- .gitignore | 1 + docker-compose.yml | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8fce603..0c54f60 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ data/ +.env diff --git a/docker-compose.yml b/docker-compose.yml index 578af19..1d30627 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,13 +5,14 @@ services: restart: unless-stopped ports: - "8005:8005" + # Create .env file here and override the settings below environment: - UI_PORT=8005 - TZ=Asia/Jerusalem - - PRINTER_URL=PRINTER_IP_PLACEHOLDER - - FILAMENT_DIAMETER=1.75 - - SPOOLMAN_URL=http://SPOOLMAN_IP_PLACEHOLDER:7912 - - SPOOLMAN_MODE=direct # direct or moonraker + - PRINTER_URL=$PRINTER_URL + - FILAMENT_DIAMETER=$FILAMENT_DIAMETER # Mostly 1.75 + - SPOOLMAN_URL=$SPOOLMAN_URL + - SPOOLMAN_MODE=$SPOOLMAN_MODE # direct or moonraker volumes: # This ensures your filament data survives container updates - ./data:/opt/filament-management/data From 5f53bb30a78321bc385c620d897eef818f5ecbb6 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Thu, 19 Mar 2026 12:19:16 +0200 Subject: [PATCH 08/11] fixes --- Dockerfile | 12 ++++++------ docker-compose.yml | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index dbf44e8..3240e98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,8 +3,8 @@ FROM python:3.12-slim AS builder # Set working directory WORKDIR /app -# Install git only to clone the repo -RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* +# Install packages +RUN apt-get update && apt-get install -y sshpass && rm -rf /var/lib/apt/lists/* COPY . . @@ -27,9 +27,9 @@ COPY --from=builder /install /usr/local COPY --from=builder /app $APP_DIR # Expose the UI port -EXPOSE 8005 +EXPOSE $UI_PORT # Start the application -CMD printf '{\n "printer_url": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s",\n "spoolman_mode": "%s"\n}\n' \ - "$PRINTER_URL" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" "$SPOOLMAN_MODE" > $APP_DIR/data/config.json && \ - uvicorn main:app --host 0.0.0.0 --port 8005 +CMD printf '{\n "printer_urls": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s",\n "spoolman_mode": "%s"\n}\n' \ + "$PRINTER_URLs" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" "$SPOOLMAN_MODE" > $APP_DIR/data/config.json && \ + uvicorn main:app --host 0.0.0.0 --port $UI_PORT diff --git a/docker-compose.yml b/docker-compose.yml index 1d30627..290ef2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,16 +8,16 @@ services: # Create .env file here and override the settings below environment: - UI_PORT=8005 - - TZ=Asia/Jerusalem - - PRINTER_URL=$PRINTER_URL - - FILAMENT_DIAMETER=$FILAMENT_DIAMETER # Mostly 1.75 - - SPOOLMAN_URL=$SPOOLMAN_URL - - SPOOLMAN_MODE=$SPOOLMAN_MODE # direct or moonraker + - TZ=${TZ:-Asia/Jerusalem} + - PRINTER_URLS=${PRINTER_URLS:-["127.0.0.1"]} + - FILAMENT_DIAMETER=${FILAMENT_DIAMETER:-1.75} + - SPOOLMAN_URL=${SPOOLMAN_URL:http://127.0.0.1:7912} + - SPOOLMAN_MODE=${SPOOLMAN_MODE:-direct} # direct or moonraker volumes: # This ensures your filament data survives container updates - ./data:/opt/filament-management/data healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8005/"] + test: ["CMD", "curl", "-f", "http://localhost:8005/api/health"] interval: 30s timeout: 10s retries: 3 From 535385337ccceb7a8c326b38662ae196dca8ac51 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Thu, 19 Mar 2026 12:20:20 +0200 Subject: [PATCH 09/11] fix --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 290ef2d..f0bb80e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,7 @@ services: - TZ=${TZ:-Asia/Jerusalem} - PRINTER_URLS=${PRINTER_URLS:-["127.0.0.1"]} - FILAMENT_DIAMETER=${FILAMENT_DIAMETER:-1.75} - - SPOOLMAN_URL=${SPOOLMAN_URL:http://127.0.0.1:7912} + - SPOOLMAN_URL=${SPOOLMAN_URL:-http://127.0.0.1:7912} - SPOOLMAN_MODE=${SPOOLMAN_MODE:-direct} # direct or moonraker volumes: # This ensures your filament data survives container updates From 17323029523b73f9f5a56d8809ae08aa4d56137b Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Thu, 19 Mar 2026 10:37:46 +0000 Subject: [PATCH 10/11] fixes --- Dockerfile | 21 ++++++++++++--------- entrypoint.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 3240e98..7766826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,6 @@ FROM python:3.12-slim AS builder # Set working directory WORKDIR /app -# Install packages -RUN apt-get update && apt-get install -y sshpass && rm -rf /var/lib/apt/lists/* - COPY . . # Install dependencies to a specific folder @@ -13,6 +10,9 @@ RUN pip install --no-cache-dir --prefix=/install -r requirements.txt FROM python:3.12-slim +# Install packages +RUN apt-get update && apt-get install -y sshpass && rm -rf /var/lib/apt/lists/* + # Set environment variables ENV APP_DIR=/opt/filament-management \ PYTHONPATH=/opt/filament-management \ @@ -20,16 +20,19 @@ ENV APP_DIR=/opt/filament-management \ WORKDIR $APP_DIR -# Copy ONLY the installed libraries from the builder stage +# Copy Python libs and app code COPY --from=builder /install /usr/local - -# Copy ONLY the application code from the builder stage COPY --from=builder /app $APP_DIR +# Setup Entrypoint +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + # Expose the UI port EXPOSE $UI_PORT +ENTRYPOINT ["/entrypoint.sh"] + # Start the application -CMD printf '{\n "printer_urls": "%s",\n "filament_diameter_mm": %s,\n "spoolman_url": "%s",\n "spoolman_mode": "%s"\n}\n' \ - "$PRINTER_URLs" "$FILAMENT_DIAMETER" "$SPOOLMAN_URL" "$SPOOLMAN_MODE" > $APP_DIR/data/config.json && \ - uvicorn main:app --host 0.0.0.0 --port $UI_PORT +CMD uvicorn main:app --host 0.0.0.0 --port $UI_PORT + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..571734d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh +set -e + +CONFIG_PATH="$APP_DIR/data/config.json" + +# Only generate the file if it does not exist +if [ ! -f "$CONFIG_PATH" ]; then + echo "Config not found. Generating from environment variables..." + + # Ensure the directory exists (important for mounts) + mkdir -p "$(dirname "$CONFIG_PATH")" + + python3 -c " +import os, json + +config = { + \"printer_urls\": json.loads(os.getenv('PRINTER_URLS', '[]')), + \"filament_diameter_mm\": float(os.getenv('FILAMENT_DIAMETER', '1.75')), + \"spoolman_url\": os.getenv('SPOOLMAN_URL', ''), + \"spoolman_mode\": os.getenv('SPOOLMAN_MODE', 'remote') +} + +with open('$CONFIG_PATH', 'w') as f: + json.dump(config, f, indent=4) +" +else + echo "Config file already exists in volume, skipping generation." +fi + +# Hand off to the CMD (uvicorn) +exec "$@" + From e5d48e6ae2886f7dfca652ad55d25a5eb60bf230 Mon Sep 17 00:00:00 2001 From: Yogev Bokobza Date: Thu, 19 Mar 2026 10:40:24 +0000 Subject: [PATCH 11/11] fix --- .env.template | 5 +++++ docker-compose.yml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .env.template diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..a29c2d3 --- /dev/null +++ b/.env.template @@ -0,0 +1,5 @@ +PRINTER_URLS=["127.0.0.1"] +FILAMENT_DIAMETER=1.75 +SPOOLMAN_URL=http://127.0.0.1:7912 +SPOOLMAN_MODE=direct + diff --git a/docker-compose.yml b/docker-compose.yml index f0bb80e..565eefb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: restart: unless-stopped ports: - "8005:8005" - # Create .env file here and override the settings below + # Create .env file here and override the settings below (See .env.template for example) environment: - UI_PORT=8005 - TZ=${TZ:-Asia/Jerusalem}