Add footer

This commit is contained in:
Stéphane Bidoul 2021-11-21 12:29:36 +01:00
parent 8906a8908f
commit 361411b03f
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
8 changed files with 58 additions and 8 deletions

View file

@ -9,3 +9,4 @@ RUNBOAT_BUILD_TEMPLATE_VARS={"storageClassName": "my-storage-class"}
RUNBOAT_GITHUB_TOKEN= RUNBOAT_GITHUB_TOKEN=
RUNBOAT_LOG_CONFIG=log-config.yaml RUNBOAT_LOG_CONFIG=log-config.yaml
RUNBOAT_BASE_URL=https://runboat.odoo-community.org RUNBOAT_BASE_URL=https://runboat.odoo-community.org
RUNBOAT_ADDITIONAL_FOOTER_HTML=""

View file

@ -20,6 +20,7 @@ ENV RUNBOAT_BUILD_SECRET_ENV='{"PGPASSWORD": "..."}'
ENV RUNBOAT_BUILD_TEMPLATE_VARS='{}' ENV RUNBOAT_BUILD_TEMPLATE_VARS='{}'
ENV RUNBOAT_GITHUB_TOKEN= ENV RUNBOAT_GITHUB_TOKEN=
ENV RUNBOAT_BASE_URL=https://runboat.example.com 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 # KUBECONFIG to be provided by user, unless running in cluster with a service account
# having the necessary permissions. # having the necessary permissions.

View file

@ -1,7 +1,4 @@
from pathlib import Path
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from . import __version__, api, controller, k8s, webhooks, webui 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(api.router, prefix="/api/v1", tags=["api"])
app.include_router(webhooks.router, tags=["webhooks"]) app.include_router(webhooks.router, tags=["webhooks"])
app.include_router(webui.router, tags=["webui"]) 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") @app.on_event("startup")

View file

@ -49,6 +49,8 @@ class Settings(BaseSettings):
# The base url where the runboat UI and API is exposed on internet. # The base url where the runboat UI and API is exposed on internet.
# Used to generate backlinks in GitHub statuses # Used to generate backlinks in GitHub statuses
base_url: str = "http://localhost:8000" base_url: str = "http://localhost:8000"
# HTML fragment for second footer.
additional_footer_html: str = ""
class Config: class Config:
env_prefix = "RUNBOAT_" env_prefix = "RUNBOAT_"

View file

@ -14,7 +14,8 @@
<body> <body>
<runboat-build id="build"></runboat-build> <runboat-build id="build"></runboat-build>
<div id="footer"> <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> </div>
<script type="module"> <script type="module">
import {RunboatBuildElement} from './runboat-build-element.js' import {RunboatBuildElement} from './runboat-build-element.js'

View file

@ -24,7 +24,8 @@
<body> <body>
<div id="builds"></div> <div id="builds"></div>
<div id="footer"> <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> </div>
<script type="module"> <script type="module">
import {RunboatBuildElement} from './runboat-build-element.js' import {RunboatBuildElement} from './runboat-build-element.js'

View file

@ -1,14 +1,62 @@
import shutil
from importlib import resources
from pathlib import Path
from typing import Optional from typing import Optional
import jinja2
from fastapi import APIRouter, HTTPException, Response, status from fastapi import APIRouter, HTTPException, Response, status
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles
from .controller import controller from .controller import controller
from .models import BuildStatus from .models import BuildStatus
from .settings import settings
router = APIRouter() 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) @router.get("/builds", response_class=RedirectResponse)
async def builds(repo: str, target_branch: Optional[str] = None) -> Response: async def builds(repo: str, target_branch: Optional[str] = None) -> Response:
url = f"/webui/builds.html?repo={repo}" url = f"/webui/builds.html?repo={repo}"