Add footer
This commit is contained in:
parent
8906a8908f
commit
361411b03f
8 changed files with 58 additions and 8 deletions
|
|
@ -9,3 +9,4 @@ RUNBOAT_BUILD_TEMPLATE_VARS={"storageClassName": "my-storage-class"}
|
|||
RUNBOAT_GITHUB_TOKEN=
|
||||
RUNBOAT_LOG_CONFIG=log-config.yaml
|
||||
RUNBOAT_BASE_URL=https://runboat.odoo-community.org
|
||||
RUNBOAT_ADDITIONAL_FOOTER_HTML=""
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ ENV RUNBOAT_BUILD_SECRET_ENV='{"PGPASSWORD": "..."}'
|
|||
ENV RUNBOAT_BUILD_TEMPLATE_VARS='{}'
|
||||
ENV RUNBOAT_GITHUB_TOKEN=
|
||||
ENV RUNBOAT_BASE_URL=https://runboat.example.com
|
||||
ENV RUNBOAT_ADDITIONAL_FOOTER_HTML=''
|
||||
|
||||
# KUBECONFIG to be provided by user, unless running in cluster with a service account
|
||||
# having the necessary permissions.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from . import __version__, api, controller, k8s, webhooks, webui
|
||||
|
||||
|
|
@ -11,9 +8,8 @@ app = FastAPI(
|
|||
app.include_router(api.router, prefix="/api/v1", tags=["api"])
|
||||
app.include_router(webhooks.router, tags=["webhooks"])
|
||||
app.include_router(webui.router, tags=["webui"])
|
||||
app.mount(
|
||||
"/webui", StaticFiles(directory=Path(__file__).parent / "webui"), name="webui"
|
||||
)
|
||||
|
||||
webui.mount(app)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ class Settings(BaseSettings):
|
|||
# The base url where the runboat UI and API is exposed on internet.
|
||||
# Used to generate backlinks in GitHub statuses
|
||||
base_url: str = "http://localhost:8000"
|
||||
# HTML fragment for second footer.
|
||||
additional_footer_html: str = ""
|
||||
|
||||
class Config:
|
||||
env_prefix = "RUNBOAT_"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
<body>
|
||||
<runboat-build id="build"></runboat-build>
|
||||
<div id="footer">
|
||||
<p>Runboat - Created with love for <a href="https://odoo-community.org"><img src="https://odoo-community.org/logo.png" style="height: 1em; vertical-align: text-top;"></a> by Stéphane Bidoul with support of <a href="https://acsone.eu"><img src="https://acsone.eu/logo.png" style="height: 1em; vertical-align: text-top;"></a>. Copyright © Runboat <a href="https://github.com/sbidoul/runboat/graphs/contributors">contributors</a>.</p>
|
||||
{{ footer_html }}
|
||||
{{ additional_footer_html }}
|
||||
</div>
|
||||
<script type="module">
|
||||
import {RunboatBuildElement} from './runboat-build-element.js'
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
<body>
|
||||
<div id="builds"></div>
|
||||
<div id="footer">
|
||||
<p>Runboat - Created with love for <a href="https://odoo-community.org"><img src="https://odoo-community.org/logo.png" style="height: 1em; vertical-align: text-top;"></a> by Stéphane Bidoul with support of <a href="https://acsone.eu"><img src="https://acsone.eu/logo.png" style="height: 1em; vertical-align: text-top;"></a>. Copyright © Runboat <a href="https://github.com/sbidoul/runboat/graphs/contributors">contributors</a>.</p>
|
||||
{{ footer_html }}
|
||||
{{ additional_footer_html }}
|
||||
</div>
|
||||
<script type="module">
|
||||
import {RunboatBuildElement} from './runboat-build-element.js'
|
||||
|
|
@ -1,14 +1,62 @@
|
|||
import shutil
|
||||
from importlib import resources
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import jinja2
|
||||
from fastapi import APIRouter, HTTPException, Response, status
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from .controller import controller
|
||||
from .models import BuildStatus
|
||||
from .settings import settings
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
FOOTER_HTML = """\
|
||||
<p>
|
||||
Runboat -
|
||||
Created with love for
|
||||
<a href="https://odoo-community.org">
|
||||
<img src="https://odoo-community.org/logo.png"
|
||||
style="height: 1em; vertical-align: text-bottom;"
|
||||
></a>
|
||||
by Stéphane Bidoul with support of
|
||||
<a href="https://acsone.eu">
|
||||
<img src="https://acsone.eu/logo.png"
|
||||
style="height: 1em; vertical-align: text-bottom;"
|
||||
></a>.
|
||||
Copyright © Runboat
|
||||
<a href="https://github.com/sbidoul/runboat/graphs/contributors">contributors</a>.
|
||||
</p>
|
||||
"""
|
||||
|
||||
|
||||
def mount(app) -> None:
|
||||
"""Render and and mount the webui templates.
|
||||
|
||||
Files and Jinja templates are rendered and copied to a working
|
||||
directory, which is then mounted under the /webui route.
|
||||
"""
|
||||
webui_path = Path(__file__).parent / "webui"
|
||||
with resources.path("runboat", "webui-templates") as webui_template_path:
|
||||
for path in webui_template_path.iterdir():
|
||||
if path.name.endswith(".jinja"):
|
||||
template = jinja2.Template(path.read_text())
|
||||
rendered = template.render(
|
||||
{
|
||||
"footer_html": FOOTER_HTML,
|
||||
"additional_footer_html": settings.additional_footer_html,
|
||||
}
|
||||
)
|
||||
(webui_path / path.name[:-6]).write_text(rendered)
|
||||
else:
|
||||
shutil.copy(path, webui_path / path.name)
|
||||
app.mount("/webui", StaticFiles(directory=webui_path), name="webui")
|
||||
|
||||
|
||||
@router.get("/builds", response_class=RedirectResponse)
|
||||
async def builds(repo: str, target_branch: Optional[str] = None) -> Response:
|
||||
url = f"/webui/builds.html?repo={repo}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue