diff --git a/backend/app.py b/backend/app.py index 9ba87da..9946711 100644 --- a/backend/app.py +++ b/backend/app.py @@ -26,7 +26,7 @@ from datetime import datetime from database import db, User, Projeto, Area, Ambiente, Circuito, Modulo, Vinculacao, Keypad, KeypadButton, QuadroEletrico, Cena, Acao, CustomAcao -app = Flask(__name__, instance_relative_config=True) +app = Flask(__name__, instance_relative_config=True, static_folder='static', static_url_path='') # Garante que a pasta da instância exista try: @@ -4073,8 +4073,10 @@ def delete_cena(cena_id): @app.route("/") def spa_catch_all(path): # Não intercepta APIs ou arquivos estáticos - if path.startswith("api/") or path.startswith("static/") or path.startswith("exportar-pdf/"): + if path.startswith("api/") or path.startswith("exportar-pdf/"): abort(404) + if os.path.exists(os.path.join(app.static_folder, path)): + return send_from_directory(app.static_folder, path) return send_from_directory(app.static_folder, "index.html") diff --git a/hassio_addon/Dockerfile b/hassio_addon/Dockerfile new file mode 100644 index 0000000..b131720 --- /dev/null +++ b/hassio_addon/Dockerfile @@ -0,0 +1,25 @@ +# Stage 1: Build the React frontend +FROM node:18-slim as frontend +WORKDIR /app +COPY ../package.json ../package-lock.json ./ +RUN npm install +COPY ../public/ ./public/ +COPY ../src/ ./src/ +COPY ../index.html . +COPY ../postcss.config.js . +COPY ../tailwind.config.ts . +COPY ../tsconfig.app.json . +COPY ../tsconfig.json . +COPY ../tsconfig.node.json . +COPY ../vite.config.ts . +RUN npm run build + +# Stage 2: Create the Python backend +ARG BUILD_FROM +FROM $BUILD_FROM +WORKDIR /app +COPY ../backend/requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY --from=frontend /app/dist ./static +COPY ../backend/ ./ +EXPOSE 5000 diff --git a/hassio_addon/README.md b/hassio_addon/README.md new file mode 100644 index 0000000..448e94e --- /dev/null +++ b/hassio_addon/README.md @@ -0,0 +1,48 @@ +# Roehn-Automacao Home Assistant Add-on + +This document explains how to install the Roehn-Automacao application as a local add-on in your Home Assistant instance. + +## Prerequisites + +- You must have a working Home Assistant installation. +- You need a way to access the Home Assistant file system. The easiest way is by installing and configuring one of the following add-ons: + - **Samba share**: Allows you to access the configuration files from another computer on your network. + - **Advanced SSH & Web Terminal**: Allows you to access the file system via an SSH connection. + +## Installation Instructions + +1. **Copy the Add-on Folder**: + - The entire contents of this `hassio_addon` directory need to be copied into the `/addons` directory of your Home Assistant installation. + - Connect to your Home Assistant instance using Samba or SSH. + - Navigate to the root of your Home Assistant configuration (where you see `configuration.yaml`). + - If it doesn't already exist, create a new folder named `addons`. + - Copy the `hassio_addon` directory into the `addons` folder. You can rename `hassio_addon` to something more descriptive, like `roehn_automacao`, if you wish. The name of the folder inside `/addons` will be the slug of your local add-on. + + After copying, your directory structure should look like this: + ``` + /addons + └── roehn_automacao/ + ├── Dockerfile + ├── build.yaml + ├── config.yaml + ├── run.sh + └── ... (other files) + ``` + +2. **Install the Add-on in Home Assistant**: + - In your Home Assistant UI, navigate to **Settings > Add-ons**. + - In the bottom right corner, click on the **Add-on Store** button. + - In the top right corner, click the three-dots menu and select **Check for updates**. This will force Home Assistant to look for new add-ons. + - You should now see a new section at the top of the store called **Local add-ons**. The "Roehn-Automacao" add-on will be listed there. + - Click on the "Roehn-Automacao" add-on card to open its details page. + +3. **Build and Start the Add-on**: + - On the add-on details page, click the **Install** button. This will trigger Home Assistant to build the Docker image based on the provided files. This process may take several minutes. + - Once the installation is complete, you can configure any options (if available) and then click **Start**. + - You can monitor the add-on's logs by navigating to the **Log** tab on the add-on's page. + +4. **Access the Application**: + - If the add-on starts successfully, you will find a new item labeled "Roehn-Automacao" in your Home Assistant sidebar. + - Clicking on it will open the application's user interface directly inside Home Assistant, thanks to the Ingress feature. + +You're all set! The application is now running as a fully integrated Home Assistant add-on. diff --git a/hassio_addon/build.yaml b/hassio_addon/build.yaml new file mode 100644 index 0000000..8e9824f --- /dev/null +++ b/hassio_addon/build.yaml @@ -0,0 +1,9 @@ +build_from: + aarch64: "homeassistant/aarch64-base-python:3.9-alpine3.13" + amd64: "homeassistant/amd64-base-python:3.9-alpine3.13" + armhf: "homeassistant/armhf-base-python:3.9-alpine3.13" + armv7: "homeassistant/armv7-base-python:3.9-alpine3.13" + i386: "homeassistant/i386-base-python:3.9-alpine3.13" +args: + TEMPIO_VERSION: "2021.09.0" + S6_OVERLAY_VERSION: "v3.1.2.1" diff --git a/hassio_addon/config.yaml b/hassio_addon/config.yaml new file mode 100644 index 0000000..7e2208c --- /dev/null +++ b/hassio_addon/config.yaml @@ -0,0 +1,33 @@ +name: "Roehn-Automacao" +version: "1.0.0" +slug: "roehn_automacao" +description: "Application for managing Roehn automation projects" +arch: + - "aarch64" + - "amd64" + - "armhf" + - "armv7" + - "i386" +ports: + "5000/tcp": null +ingress: true +panel_icon: "mdi:robot" +panel_title: "Roehn-Automacao" +apparmor: false +uart: false +gpio: false +usb: false +hassio_api: false +hassio_role: "default" +homeassistant_api: false +host_network: false +tmpfs: false +discovery: [] +map: + - "ssl:rw" + - "share:rw" +options: + log_level: "info" +schema: + log_level: "list(trace|debug|info|notice|warning|error|fatal)?" +image: "ghcr.io/{owner}/{repository}" diff --git a/hassio_addon/run.sh b/hassio_addon/run.sh new file mode 100755 index 0000000..1a1cb35 --- /dev/null +++ b/hassio_addon/run.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: Roehn Automacao +# +# This script starts the application. +# ============================================================================== + +bashio::log.info "Starting Roehn Automacao..." + +# Start the application +python3 /app/app.py