import os import shutil import datetime import threading import time import json from flask import jsonify from utils.websocket_utils import send_websocket_message, active_websockets from utils.app_configs import (get_app_configs) ### shared_models-v0.9.1 by lutzapps, Oct 30th 2024 ### ### dev-my-v0.6 # to run (and optionally DEBUG) this docker image "better-ai-launcher" in a local container on your own machine # you need to define the ENV var "LOCAL_DEBUG" in the "VSCode Docker Extension" # file ".vscode/tasks.json" in the ENV settings of the "dockerRun" section (or any other way), # and pass into the docker container: # tasks.json: # ... # "dockerRun": { # "containerName": "madiator2011-better-launcher", // no "/" allowed here for container name # "image": "madiator2011/better-launcher:dev", # "envFiles": ["${workspaceFolder}/.env"], // pass additional env-vars (hf_token, civitai token, ssh public-key) from ".env" file to container # "env": { // this ENV vars go into the docker container to support local debugging # "LOCAL_DEBUG": "True", // change app to localhost Urls and local Websockets (unsecured) # "FLASK_APP": "app/app.py", # "FLASK_ENV": "development", // changed from "production" # "GEVENT_SUPPORT": "True" // gevent monkey-patching is being used, enable gevent support in the debugger # // "FLASK_DEBUG": "0" // "1" allows debugging in Chrome, but then VSCode debugger not works # }, # "volumes": [ # { # "containerPath": "/app", # "localPath": "${workspaceFolder}" // the "/app" folder (and sub-folders) will be mapped locally for debugging and hot-reload # }, # { # "containerPath": "/workspace", # // TODO: create this folder before you run! # "localPath": "${userHome}/Projects/Docker/Madiator/workspace" # } # ], # "ports": [ # { # "containerPort": 7222, // main Flask app port "AppManager" # "hostPort": 7222 # }, # ... # # # NOTE: to use the "LOCAL_DEBUG" ENV var just for local consumption of this image, you can run it like # # docker run -it -d --name madiator-better-launcher -p 22:22 -p 7777:7777 -p 7222:7222 -p 3000:3000 -p 7862:7862 -p 7863:7863 # -e LOCAL_DEBUG="True" -e RUNPOD_PUBLIC_IP="127.0.0.1" -e RUNPOD_TCP_PORT_22="22" # -e PUBLIC_KEY="ssh-ed25519 XXXXXXX...XXXXX user@machine-DNS.local" # --mount type=bind,source=/Users/test/Projects/Docker/madiator/workspace,target=/workspace # madiator2011/better-launcher:dev # # To run the full 'app.py' / 'index.html' webserver locally, is was needed to "patch" the # '/app/app.py' main application file and the # '/app/templates/index.html'file according to the "LOCAL_DEBUG" ENV var, # to switch the CF "proxy.runpod.net" Url for DEBUG: # ### '/app/app.py' CHANGES ###: # # lutzapps - CHANGE #1 # LOCAL_DEBUG = os.environ.get('LOCAL_DEBUG', 'False') # support local browsing for development/debugging # ... # filebrowser_status = get_filebrowser_status() # return render_template('index.html', # apps=app_configs, # app_status=app_status, # pod_id=RUNPOD_POD_ID, # RUNPOD_PUBLIC_IP=os.environ.get('RUNPOD_PUBLIC_IP'), # RUNPOD_TCP_PORT_22=os.environ.get('RUNPOD_TCP_PORT_22'), # # lutzapps - CHANGE #2 - allow localhost Url for unsecure "http" and "ws" WebSockets protocol, # according to LOCAL_DEBUG ENV var (used 3x in "index.html" changes) # enable_unsecure_localhost=os.environ.get('LOCAL_DEBUG'), # ... # other (non-related) app.py changes omitted here # ### '/app/template/index.html' CHANGES ###: #