Skip to content

Commit

Permalink
Build info (smallcloudai#287)
Browse files Browse the repository at this point in the history
* add refact-build-info file to give passport for build

* add tab version

* tab about

* fix ui

* cleanup
  • Loading branch information
mitya52 authored Jan 29, 2024
1 parent 3a224dd commit 20e10f3
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ RUN apt-get install cassandra -y
# refact lsp requisites
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
ENV PATH="${PATH}:/root/.cargo/bin"
RUN git clone https://github.com/smallcloudai/refact-lsp.git /tmp/refact-lsp \
&& cd /tmp/refact-lsp \
RUN git clone https://github.com/smallcloudai/refact-lsp.git /tmp/refact-lsp
RUN echo "refact-lsp $(git -C /tmp/refact-lsp rev-parse HEAD)" >> /refact-build-info.txt
RUN cd /tmp/refact-lsp \
&& cargo install --path . \
&& rm -rf /tmp/refact-lsp

ENV INSTALL_OPTIONAL=TRUE
ENV FLASH_ATTENTION_FORCE_BUILD=TRUE
ENV MAX_JOBS=8
COPY . /tmp/app
RUN echo "refact $(git -C /tmp/app rev-parse HEAD)" >> /refact-build-info.txt
RUN pip install ninja
RUN pip install /tmp/app -v --no-build-isolation && rm -rf /tmp/app

Expand Down
1 change: 1 addition & 0 deletions self_hosting_machinery/webgui/selfhost_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self):
{"label": "Server Logs", "tab": "server-logs"},
{"label": "Stats", "tab": "stats"},
{"label": "Credentials", "tab": "settings", "hamburger": True},
{"label": "About", "tab": "about", "hamburger": True},
]
self.add_api_route("/list-plugins", self._list_plugins, methods=["GET"])

Expand Down
2 changes: 2 additions & 0 deletions self_hosting_machinery/webgui/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
</div>
<div class="main-tab-pane" id="license">
</div>
<div class="main-tab-pane" id="about">
</div>
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions self_hosting_machinery/webgui/static/tab-about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="pane">
<h2>Version</h2>
<div class="mt-3 mb-3" id="refact-version"></div>
</div>
41 changes: 41 additions & 0 deletions self_hosting_machinery/webgui/static/tab-about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export function tab_about_version_get() {
fetch("/tab-about-version-get")
.then(function(response) {
return response.json();
})
.then(function(data) {
const tab_version = document.getElementById("refact-version")
var version_table_data = `<tr><th>Package</th><th>Version</th><th>Commit Hash</th></tr>`;
data["version_table"].forEach(function(row) {
version_table_data += `
<tr>
<td><label class="refact-item-name">${row[0]}</label></td>
<td><label class="refact-item-version">${row[1]}</label></td>
<td><label class="refact-item-hash">${row[2]}</label></td>
</tr>`;
});
tab_version.innerHTML = `
<div><table class="table table-stripped align-left">
${version_table_data}
</table></div>`;
});
}


export async function init() {
let req = await fetch('/tab-about.html');
document.querySelector('#about').innerHTML = await req.text();
}


export function tab_switched_here() {
tab_about_version_get();
}


export function tab_switched_away() {
}


export function tab_update_each_couple_of_seconds() {
}
67 changes: 67 additions & 0 deletions self_hosting_machinery/webgui/tab_about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import asyncio
import os.path

from fastapi import APIRouter
from fastapi.responses import JSONResponse

from self_hosting_machinery.webgui.selfhost_webutils import log

from typing import List, Tuple


__all__ = ["TabAboutRouter"]


class TabAboutRouter(APIRouter):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._version_table = None
self.add_api_route("/tab-about-version-get", self._tab_about_version_get, methods=["GET"])

async def _get_pip_module_version(self, module_name: str):
try:
process = await asyncio.create_subprocess_exec(
"pip", "show", module_name,
stdout=asyncio.subprocess.PIPE)
stdout, stderr = await process.communicate()
for line in stdout.decode().splitlines():
if line.startswith("Version:"):
return line.split()[-1]
except Exception as e:
log(f"Error while getting '{module_name}' version: {e}")
return "N/A"

async def _get_lsp_version(self):
try:
process = await asyncio.create_subprocess_exec(
"refact-lsp", "--version",
stdout=asyncio.subprocess.PIPE)
stdout, stderr = await process.communicate()
for line in stdout.decode().splitlines():
return line.split()[-1]
except Exception as e:
log(f"Error while getting 'refact-lsp' version: {e}")
return "N/A"

def _get_build_info(self):
build_info_filename = "/refact-build-info.txt"
build_info = dict()
if os.path.exists(build_info_filename):
with open(build_info_filename, "r") as f:
build_info = dict(line.split() for line in f.readlines())
return build_info

async def _init_version_table(self) -> List[Tuple[str, str, str]]:
build_info = self._get_build_info()
refact_version = await self._get_pip_module_version("refact-self-hosting")
lsp_version = await self._get_lsp_version()
return [
("refact", refact_version, build_info.get("refact", "N/A")),
("refact-lsp", lsp_version, build_info.get("refact-lsp", "N/A")),
]

async def _tab_about_version_get(self):
if not self._version_table:
self._version_table = await self._init_version_table()
return JSONResponse({"version_table": self._version_table})
2 changes: 2 additions & 0 deletions self_hosting_machinery/webgui/webgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from self_hosting_machinery.webgui.tab_loras import TabLorasRouter
from self_hosting_machinery.webgui.selfhost_statistics import TabStatisticsRouter
from self_hosting_machinery.webgui.selfhost_login import LoginRouter
from self_hosting_machinery.webgui.tab_about import TabAboutRouter

from self_hosting_machinery.webgui.selfhost_database import RefactDatabase
from self_hosting_machinery.webgui.selfhost_database import StatisticsService
Expand Down Expand Up @@ -131,6 +132,7 @@ def _routers_list(
TabHostRouter(model_assigner),
TabSettingsRouter(model_assigner),
LspProxy(),
TabAboutRouter(),
StaticRouter(),
]

Expand Down

0 comments on commit 20e10f3

Please sign in to comment.