From 61b2cd997483d896666a738d55f0df1a713b9e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Socho=C5=84?= Date: Mon, 9 Dec 2024 00:28:09 +0100 Subject: [PATCH 1/3] Change paths to os.path.join so this is os agnostic --- .dockerignore | 8 +++++++- .env | 2 -- .gitignore | 11 ++++++++++- Dockerfile | 36 +++++++++++++----------------------- Dockerfile.old | 18 ------------------ app.py | 14 ++++++++------ db.py | 4 ++-- docker-compose.yaml | 8 +++++--- entrypoint.sh | 9 --------- logs/.gitkeep | 0 setup.py | 25 ------------------------- setup.sh | 6 ------ 12 files changed, 45 insertions(+), 96 deletions(-) delete mode 100644 .env delete mode 100644 Dockerfile.old delete mode 100644 entrypoint.sh create mode 100644 logs/.gitkeep delete mode 100644 setup.py delete mode 100644 setup.sh diff --git a/.dockerignore b/.dockerignore index 60586c7..6bf1a9e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,4 +13,10 @@ docker-compose.* **/*.test.ts* renovate.json Dockerfile* -*.bat \ No newline at end of file +*.bat +.idea +.vscode + + +!data/.gitignore +!images/.gitignore diff --git a/.env b/.env deleted file mode 100644 index 2a3da08..0000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -DATABASE_LOCATION=C:\Users\Justu\Documents\GitHub\M.I.M.O.S.A\M.I.M.O.S.A\data -IMAGE_LOCATION=C:\Users\Justu\Documents\GitHub\M.I.M.O.S.A\M.I.M.O.S.A\images diff --git a/.gitignore b/.gitignore index e1fbe65..6796880 100644 --- a/.gitignore +++ b/.gitignore @@ -199,4 +199,13 @@ $RECYCLE.BIN/ *.db *.sqlite *.jpg -*.webp \ No newline at end of file +*.webp + + +# project files +data/ + +!data/.gitkeep + +images/ +!images/demo.* diff --git a/Dockerfile b/Dockerfile index 4ec0845..4783265 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:alpine3.20 +FROM python:alpine3.20 as build # Metadata params ARG VCS_REF @@ -6,30 +6,20 @@ ARG BUILD_DATE ENV MIMOSA_VERSION=V4-2024.09.1dev ENV MIMOSA_DOCKER_VERSION=2024.09.2dev -WORKDIR /app -EXPOSE 5000 -COPY /setup.sh /setup.sh -RUN chmod +x /setup.sh -COPY requirements.txt ./ -RUN apk add --no-cache bash git curl && \ - apk upgrade && \ - cd /app && \ - pip install --upgrade pip && \ - pip install waitress && \ - pip install --no-cache-dir -r requirements.txt +# hadolint ignore=DL3013,DL3018 +RUN apk upgrade && \ + apk add --no-cache bash git curl && \ + pip install --no-cache-dir --upgrade pip +WORKDIR /app COPY . . +RUN pip install --no-cache-dir -r requirements.txt \ + && echo "$(date "+%d.%m.%Y %T") Spotlight Storage Docker ${MIMOSA_DOCKER_VERSION} Built from Spotlight Storage ${MIMOSA_VERSION}" >> /build_date.info -RUN /setup.sh - -RUN rm -rf /setup.sh /app/setup.sh -RUN echo "$(date "+%d.%m.%Y %T") Spotlight Storage Docker ${MIMOSA_DOCKER_VERSION} Built from Spotlight Storage ${MIMOSA_VERSION}" >> /build_date.info - - -COPY /entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -#HEALTHCHECK CMD curl --fail http://localhost:5000 || exit 1 +EXPOSE 5000 +HEALTHCHECK --interval=60s --timeout=5s \ + CMD curl --fail http://localhost:5000 || exit 1 -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +USER nobody +ENTRYPOINT ["python", "./app.py"] diff --git a/Dockerfile.old b/Dockerfile.old deleted file mode 100644 index a9e46b3..0000000 --- a/Dockerfile.old +++ /dev/null @@ -1,18 +0,0 @@ -FROM python:3.13 - -COPY static static -COPY app.py app.py -COPY db.py db.py -COPY favicon.ico favicon.ico -COPY requirements.txt requirements.txt -COPY templates templates -COPY setup.py setup.py -ENV TRANSLATIONS_DIR=/app/static/translations - - -RUN pip install -r requirements.txt -RUN python setup.py - -EXPOSE 5000 -EXPOSE 5001 -ENTRYPOINT python app.py diff --git a/app.py b/app.py index f353456..de96913 100644 --- a/app.py +++ b/app.py @@ -1,15 +1,17 @@ # Importing necessary modules and packages +import db + import json +import os import re -from flask import Flask, render_template, jsonify, request, send_from_directory, redirect, url_for, flash, Response - -from requests import Timeout -import db import requests import time -import os + +from flask import Flask, render_template, jsonify, request, send_from_directory, redirect, url_for, flash, Response +from requests import Timeout from werkzeug.utils import secure_filename + # Creating a Flask application instance app = Flask(__name__) app.config['JSON_SORT_KEYS'] = False @@ -20,7 +22,7 @@ app.timeout = 5 app.standbyColor = "#00ff00" app.locateColor = "#00ff00" -app.config['UPLOAD_FOLDER'] = './images' +app.config['UPLOAD_FOLDER'] = os.path.join('.','images') app.previous_positions = [] app.request_amount = 0 diff --git a/db.py b/db.py index cc8c8ab..39392f8 100644 --- a/db.py +++ b/db.py @@ -5,7 +5,7 @@ from collections import Counter # Define the path for the combined database -COMBINED_DATABASE = 'data/combined_data.db' +COMBINED_DATABASE = os.path.join('data','combined_data.db') def create_combined_db(): @@ -492,7 +492,7 @@ def perform_migration(): def move_db_to_data_dir(): main_dir_db = 'combined_data.db' # The original path in the main directory - data_dir_db = 'data/combined_data.db' # The new path inside the data directory + data_dir_db = os.path.join('data', 'combined_data.db') # The new path inside the data directory # Check if the database exists in the main directory if os.path.exists(main_dir_db): diff --git a/docker-compose.yaml b/docker-compose.yaml index c647011..12aff8c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,7 @@ services: spotlight-storage: + read_only: true + stop_signal: SIGINT # https://github.com/docker/compose/issues/4199#issuecomment-426109482 environment: - TRANSLATIONS_DIR=/app/static/translations image: mellowlabs/spotlight_storage:dev @@ -7,7 +9,7 @@ services: - "5000:5000" restart: on-failure volumes: - - ./data:/app/data - - ./images:/app/images - - ./logs:/app/logs + - ./data:/app/data:rw + - ./images:/app/images:rw + - ./logs:/app/logs:rw - ./static/translations:/app/static/translations:ro \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 6f33ce7..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -## Shell setting -if [[ -n "$DEBUG" ]]; then - set -ex -else - set -e -fi - -cd /app && python ./app.py \ No newline at end of file diff --git a/logs/.gitkeep b/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py deleted file mode 100644 index f0a7c7e..0000000 --- a/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -import os - -# Get current Spotlight Storage folder path -current_dir = os.path.dirname(os.path.abspath(__file__)) - -# Folder paths -data_dir = os.path.join(current_dir, "data") -images_dir = os.path.join(current_dir, "images") - -# Ensure the 'data' and 'images' directories exist -if not os.path.exists(data_dir): - os.makedirs(data_dir) - -if not os.path.exists(images_dir): - os.makedirs(images_dir) - -# Change .env-file -env_file = os.path.join(current_dir, ".env") - -# Add/Write the new paths in the .env-file -with open(env_file, "w") as f: - f.write(f"DATABASE_LOCATION={data_dir}\n") - f.write(f"IMAGE_LOCATION={images_dir}\n") - -print("Updated paths in .env-file!") diff --git a/setup.sh b/setup.sh deleted file mode 100644 index 9514f51..0000000 --- a/setup.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -rm -rf /app/requirements.txt /app/entrypoint.sh /app/.dockerignore - -sed -i 's/debug=True/debug=False/g' /app/app.py -sed -i "s/MIMOSA_VERSION/$MIMOSA_VERSION/g" /app/app.py \ No newline at end of file From 4353e7a5c122ea4c8f5d635eccc3b62c05b9e39f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Socho=C5=84?= Date: Mon, 9 Dec 2024 01:15:47 +0100 Subject: [PATCH 2/3] Fix readme formatting --- .markdownlint.yaml | 27 +++++++++++++++++++ README.md | 66 ++++++++++++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 .markdownlint.yaml diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..44c923d --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,27 @@ +# Example markdownlint configuration with all properties set to their default value + +# Default state for all rules +default: true + +# Path to configuration file to extend +extends: null + +# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.37.0/doc/md013.md +MD013: + # Number of characters + line_length: 140 + # Number of characters for headings + heading_line_length: 140 + # Number of characters for code blocks + code_block_line_length: 140 + # Include code blocks + code_blocks: true + # Include tables + tables: true + # Include headings + headings: true + # Strict length checking + strict: false + # Stern length checking + stern: false + diff --git a/README.md b/README.md index d2706ad..952d4a7 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,63 @@ # Spotlight Storage - The easy way to find your parts -![Spotlight-stor](https://github.com/user-attachments/assets/65a8ce23-b271-433b-a8d6-596360a2be69) - - +![Spotlight-stor](https://github.com/user-attachments/assets/65a8ce23-b271-433b-a8d6-596360a2be69) ## Spotlight Storage is from [Mellow Labs](https://github.com/FireMarshmellow/M.I.M.O.S.A) -On this repo you get a ready to install on windows docker container for the MIMOSA storage system. + +On this repo you get a ready to install on windows docker container for the MIMOSA storage system. Setup time is less then 10 minutes even for beginner users. -With this you can use any WS2812 or other led's that run [WLED](https://kno.wled.ge/) +With this you can use any WS2812 or other led's that run [WLED](https://kno.wled.ge/) ## Videos -The videos are not up to date and the content in them do not match the current Spotlight Storage (old: M.I.M.O.S.A) version. But they are a good starting point to see it working and how to setup the esp and ws2812 leds. -## -[Main video](https://youtu.be/7C4i-2IqSS4) -[Step by step video](https://youtu.be/QOd1apc0Lpo) +The videos are not up to date and the content in them do not match the current Spotlight Storage (old: M.I.M.O.S.A) version. +But they are a good starting point to see it working and how to setup the esp and ws2812 leds. + +* [Main video](https://youtu.be/7C4i-2IqSS4) +* [Step by step video](https://youtu.be/QOd1apc0Lpo) ## Hardware i used -[ESP32-C3](https://www.amazon.de/Waveshare-Development-ESP32-S3FH4R2-Castellated-Applications/dp/B0CHYHGYRH/ref=sr_1_3?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=3HT19BBR039GT&dib=eyJ2IjoiMSJ9.yV2RTYatG7l54mT4TmFs41gUutfrpBPcC-gNcJjW5yrX18ynT5ARl4Q363-yduVYFbXaiIDiG0O_OKJwcpUODORDJywTWMIIUHu_6GFNiXwqHgM4ZCQqe2FDi0h_BT4InKffRyJEq28FkhdjnfdLetRaF4Uk4hTL-Brc5Qjb8kmWcPcPNoRb4uG-FDWQU1Nj3aow_Y54AF_bpCq7385eE0SDKwWei3MRFSzsHGJvdIg.XqcFwKVecXx0t8aSXZ8k-3qn2ApPvE-6qe_Vg8m5CO4&dib_tag=se&keywords=esp32-s3+mini&qid=1723273994&sprefix=esp32-s3+mini%2Caps%2C92&sr=8-3) +* [ESP32-C3](https://www.amazon.de/Waveshare-Development-ESP32-S3FH4R2-Castellated-Applications/dp/B0CHYHGYRH/ref=sr_1_3?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=3HT19BBR039GT&dib=eyJ2IjoiMSJ9.yV2RTYatG7l54mT4TmFs41gUutfrpBPcC-gNcJjW5yrX18ynT5ARl4Q363-yduVYFbXaiIDiG0O_OKJwcpUODORDJywTWMIIUHu_6GFNiXwqHgM4ZCQqe2FDi0h_BT4InKffRyJEq28FkhdjnfdLetRaF4Uk4hTL-Brc5Qjb8kmWcPcPNoRb4uG-FDWQU1Nj3aow_Y54AF_bpCq7385eE0SDKwWei3MRFSzsHGJvdIg.XqcFwKVecXx0t8aSXZ8k-3qn2ApPvE-6qe_Vg8m5CO4&dib_tag=se&keywords=esp32-s3+mini&qid=1723273994&sprefix=esp32-s3+mini%2Caps%2C92&sr=8-3) -[LEDs](https://www.amazon.de/BTF-LIGHTING-Individuell-adressierbar-Vollfarbiger-DIY-Projekte/dp/B088BPGMXB/ref=sr_1_1_sspa?dib=eyJ2IjoiMSJ9.PnDQdOUPg0UohlqZWxHQ8xYtwlm0N3cqEYbM29-REkcFFp9UB1Dpmwter90G4I3xpW5k3PxKchdsn5po5skd0NmraUfUk1Z0m6hhIzBw8DHe135MoTHnt8yXO20BuzfVKimMGoHR81c-6jKIZwOG8GXNTYY077dAJ_CyzHpVEKXWE1WTF9WiD2xEmnyKsdQoKSUqKqMxmGJsM9DwHy0iucC5qQfnJrEKCsChlFBLzvCyiBcP6sdf3W7pgMddlRcIAkP-XPp3WV2RBak6UxZTPv49qdQzKoJFiCnQfBfhBgY.qLxtFwyIAQ7sA-UBBsXBx2MR-kBGaU0054Z07bD3TGg&dib_tag=se&keywords=Ws2812b+Led+Strip&qid=1723274094&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1) +* [LEDs](https://www.amazon.de/BTF-LIGHTING-Individuell-adressierbar-Vollfarbiger-DIY-Projekte/dp/B088BPGMXB/ref=sr_1_1_sspa?dib=eyJ2IjoiMSJ9.PnDQdOUPg0UohlqZWxHQ8xYtwlm0N3cqEYbM29-REkcFFp9UB1Dpmwter90G4I3xpW5k3PxKchdsn5po5skd0NmraUfUk1Z0m6hhIzBw8DHe135MoTHnt8yXO20BuzfVKimMGoHR81c-6jKIZwOG8GXNTYY077dAJ_CyzHpVEKXWE1WTF9WiD2xEmnyKsdQoKSUqKqMxmGJsM9DwHy0iucC5qQfnJrEKCsChlFBLzvCyiBcP6sdf3W7pgMddlRcIAkP-XPp3WV2RBak6UxZTPv49qdQzKoJFiCnQfBfhBgY.qLxtFwyIAQ7sA-UBBsXBx2MR-kBGaU0054Z07bD3TGg&dib_tag=se&keywords=Ws2812b+Led+Strip&qid=1723274094&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1) ## Features -- inventory management -- search -- locate items -- sort items in groups -- set up multible storage locations in different rooms, only wifi is needed. + +* inventory management +* search +* locate items +* sort items in groups +* set up multible storage locations in different rooms, only wifi is needed. ## Install WLED on ESP devices -1. Go to WLED [installation page ](https://install.wled.me/) and select the latest release and intall it on the esp device. + +1. Go to WLED [installation page](https://install.wled.me/) and select the latest release and intall it on the esp device. 2. Put in your wifi data. 3. Go to the ip address of your esp, to `Config -> LED Preferences` and set up your led's like in the video. 4. Make note of the esp ip address, you will need it later to put into your MIMOSA settings. ## Installation of Spotlight Storage with `Installation.bat` file -1. Download this Repo as zip and extract it to the location you want to install MIMOSA on your pc. (you can put it anywhere you want e.g. Downloads,Documents,Desktop,C it doesn's matter) +1. Download this Repo as zip and extract it to the location you want to install MIMOSA on your pc. +(you can put it anywhere you want e.g. Downloads,Documents,Desktop,C it doesn's matter) + 2. Install and start the Docker Desktop https://www.docker.com/products/docker-desktop/ 3. Docker Desktop must be startet at least once before, to set it up for the next step. 4. In the location where you have put the MIMOSA folder, open that folder, then doubble click on the file `install.bat` and let the magic happen. -5. Now if everything is correct, it will start a terminal, open Docker Desktop when it is not allready running, build the Spotlight Storage V4-Container and start it. -7. The terminal closes after 5 second automatically -8. That's it, go to `localhost:5000` in any browser, you can now enjoy the easy life with Spotlight Storage. +5. Now if everything is correct, it will start a terminal, open Docker Desktop when it is not allready running, + build the Spotlight Storage V4-Container and start it. +6. The terminal closes after 5 second automatically +7. That's it, go to `localhost:5000` in any browser, you can now enjoy the easy life with Spotlight Storage. -- To get access to Spotlight Storage over other browsers in your network e.g. with your smartphone you need to find the ip address of your computer, mine is for example 192.168.1.20 and behind the ip adress you need to put in the port 5000 and this is what you put into the browser `http://yourcomputerip:5000` +* To get access to Spotlight Storage over other browsers in your network e.g. with your smartphone + you need to find the ip address of your computer, mine is for example 192.168.1.20 and behind the ip adress + you need to put in the port 5000 and this is what you put into the browser `http://yourcomputerip:5000` -- Remove or turn off Spotlight Storage System with the `uninstall.bat`, no data will be lost. It just turns off docker container and removes it. If you hit `install.bat` after the `uninstall.bat` it will turn on docker container, build it and you can reach the same page and data as before. +* Remove or turn off Spotlight Storage System with the `uninstall.bat`, no data will be lost. + It just turns off docker container and removes it. If you hit `install.bat` after the `uninstall.bat` + it will turn on docker container, build it and you can reach the same page and data as before. ## Installation of Spotlight Storage with docker-compose @@ -60,14 +69,14 @@ Spotlight Storage requires Docker Compose version 2.x or higher. Create a new directory to hold the `docker-compose.yml` file. -```bash +```shell mkdir Spotlight_Storage cd Spotlight_Storage ``` Download the [docker-compose.yml](https://raw.githubusercontent.com/FireMarshmellow/Spotlight_Storage/main/docker-compose.yml) file. -```bash +```shell wget -O docker-compose.yml https://raw.githubusercontent.com/FireMarshmellow/Spotlight_Storage/main/docker-compose.yml ``` @@ -77,11 +86,10 @@ or download the files manually from the repository. From the directory where the `docker-compose.yml` file is located, run the following command: -```bash +```shell docker compose up -d ``` +## Dependencies -## dependencies: - -- python 3.6 +* python 3.6 at least, 3.10 is recommended From 356581b0553ed9e2d6097502f60d8fdb41857141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Socho=C5=84?= Date: Mon, 9 Dec 2024 01:16:12 +0100 Subject: [PATCH 3/3] Fix Dockerfile labels --- Dockerfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4783265..d32aafd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,21 @@ -FROM python:alpine3.20 as build +ARG BASE_IMAGE=docker.io/library/python:alpine3.20 +FROM ${BASE_IMAGE} # Metadata params ARG VCS_REF ARG BUILD_DATE - +ARG GIT_COMMIT=${GITHUB_HEAD_REF} +ARG GIT_SOURCE=${GITHUB_REPOSITORY} ENV MIMOSA_VERSION=V4-2024.09.1dev ENV MIMOSA_DOCKER_VERSION=2024.09.2dev +LABEL org.opencontainers.image.description="Mellow_Labs Inventory Management and Organization System Apparatus" +LABEL org.opencontainers.image.revision="${GIT_COMMIT}" +LABEL org.opencontainers.image.source="${GIT_SOURCE}" +LABEL org.opencontainers.image.url="https://github.com/FireMarshmellow/Spotlight_Storage" +LABEL org.opencontainers.image.licenses="MIT" +LABEL org.opencontainers.image.authors="Tomasz Burzy" + # hadolint ignore=DL3013,DL3018 RUN apk upgrade && \ apk add --no-cache bash git curl && \