feat: docker and nomad config
This commit is contained in:
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from pages import router as pages_router
|
||||
from pages import router as pages_router, ensure_default_pages
|
||||
from graph import router as graph_router
|
||||
from docker_utils import router as docker_router
|
||||
from converter import router as converter_router
|
||||
@@ -17,6 +17,11 @@ app.include_router(graph_router, prefix="/api")
|
||||
app.include_router(docker_router, prefix="/api")
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
ensure_default_pages()
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
@@ -12,6 +12,48 @@ router = APIRouter()
|
||||
PAGES_DIR = Path(os.environ.get("PAGES_DIR", "/data/pages"))
|
||||
SOURCES_DIR = Path(os.environ.get("SOURCES_DIR", "/data/sources"))
|
||||
|
||||
DEFAULT_INDEX_SOURCE = '''\
|
||||
page "Welcome" 60
|
||||
bigtitle "uFrame" thin
|
||||
|
||||
box rounded "Micronomicon"
|
||||
align center
|
||||
text "Decentralized Page Server"
|
||||
text "Powered by @bold{Reticulum} and @bold{NomadNet}"
|
||||
|
||||
spacer
|
||||
|
||||
heading 2 "Pages"
|
||||
text "This node is serving pages built with the uFrame DSL."
|
||||
text "Use the web IDE to create and publish new pages."
|
||||
|
||||
spacer
|
||||
|
||||
divider light
|
||||
|
||||
label "Node" "Micronomicon"
|
||||
label "Engine" "uFrame v1"
|
||||
status "Node" online
|
||||
'''
|
||||
|
||||
|
||||
def ensure_default_pages():
|
||||
"""Create a default index page if none exists."""
|
||||
PAGES_DIR.mkdir(parents=True, exist_ok=True)
|
||||
SOURCES_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
index_mu = PAGES_DIR / "index.mu"
|
||||
index_src = SOURCES_DIR / "index.uf"
|
||||
|
||||
if not index_mu.is_file():
|
||||
# Compile and publish the default index
|
||||
result = uframe.compile(DEFAULT_INDEX_SOURCE)
|
||||
index_mu.write_text(result.micron, encoding="utf-8")
|
||||
index_mu.chmod(0o644)
|
||||
|
||||
if not index_src.is_file():
|
||||
index_src.write_text(DEFAULT_INDEX_SOURCE, encoding="utf-8")
|
||||
|
||||
|
||||
class PageMeta(BaseModel):
|
||||
name: str
|
||||
|
||||
Reference in New Issue
Block a user