feat(caprover): display application logs for apps with pending updates
This commit is contained in:
@@ -21,12 +21,23 @@ const UpdateForm = (application: Application, latestVersions: string[]) => {
|
||||
</form>`;
|
||||
};
|
||||
|
||||
const PendingUpdates = (pendingUpdates: UpdateDefinition[]) => {
|
||||
const FreeUpdateForm = (application: Application) => {
|
||||
return html`<form method="POST">
|
||||
<input type="hidden" name="appName" value="${application.name}" />
|
||||
<label for="version">
|
||||
Manual version
|
||||
<input name="version" placeholder="hello-world:latest" type="text" />
|
||||
</label>
|
||||
<button type="submit">Update</button>
|
||||
</form>`;
|
||||
};
|
||||
|
||||
const PendingUpdates = (pendingUpdates: UpdateDefinition[], logs: string) => {
|
||||
if (pendingUpdates.length === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return html`<div>
|
||||
return html`<section>
|
||||
<h2>Pending updates</h2>
|
||||
<ul>
|
||||
${pendingUpdates
|
||||
@@ -35,39 +46,52 @@ const PendingUpdates = (pendingUpdates: UpdateDefinition[]) => {
|
||||
})
|
||||
.join("")}
|
||||
</ul>
|
||||
</div>`;
|
||||
|
||||
<pre>${logs}</pre>
|
||||
<button
|
||||
id="refresh"
|
||||
onclick="window.location.replace('#refresh'); window.location.reload();"
|
||||
>
|
||||
Refresh
|
||||
</button>
|
||||
</section>`;
|
||||
};
|
||||
|
||||
const Page = (
|
||||
application: Application,
|
||||
latestVersions: string[],
|
||||
pendingUpdates: UpdateDefinition[]
|
||||
pendingUpdates: UpdateDefinition[],
|
||||
logs: string
|
||||
) => {
|
||||
return html`<div>
|
||||
<h1>Updating ${application.name}</h1>
|
||||
|
||||
${PendingUpdates(pendingUpdates)}
|
||||
${PendingUpdates(pendingUpdates, logs)}
|
||||
|
||||
<dl>
|
||||
<dt>Last deployment</dt>
|
||||
<dd>${application.lastDeployedAt.toLocaleString("fr-FR")}</dd>
|
||||
<section>
|
||||
<dl>
|
||||
<dt>Last deployment</dt>
|
||||
<dd>${application.lastDeployedAt.toLocaleString("fr-FR")}</dd>
|
||||
|
||||
<dt>Current version</dt>
|
||||
<dd>
|
||||
${application.dockerImage
|
||||
? `<img height="32" width="32" src="https://cdn.simpleicons.org/docker" alt="Docker hub"/> <a href="${application.dockerImage.hubUrl}/tags">
|
||||
<dt>Current version</dt>
|
||||
<dd>
|
||||
${application.dockerImage
|
||||
? `<img height="32" width="32" src="https://cdn.simpleicons.org/docker" alt="Docker hub"/> <a href="${application.dockerImage.hubUrl}/tags">
|
||||
${application.dockerImage.name}:${application.dockerImage.tag}
|
||||
</a>`
|
||||
: `<code>${application.imageName}</code>… check yourself!`}
|
||||
</dd>
|
||||
: `<code>${application.imageName}</code>… check yourself!`}
|
||||
</dd>
|
||||
|
||||
<dt>Latest versions</dt>
|
||||
<dd>
|
||||
${latestVersions.length === 0
|
||||
? "No version found"
|
||||
: UpdateForm(application, latestVersions)}
|
||||
</dd>
|
||||
</dl>
|
||||
<dt>Latest versions</dt>
|
||||
<dd>
|
||||
${latestVersions.length === 0
|
||||
? "No version found"
|
||||
: UpdateForm(application, latestVersions)}
|
||||
</dd>
|
||||
<dt>Manual update</dt>
|
||||
<dd>${FreeUpdateForm(application)}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
</div>`;
|
||||
};
|
||||
|
||||
@@ -108,9 +132,13 @@ export default async (
|
||||
);
|
||||
|
||||
const pendingUpdates = queries.pendingApplicationUpdates(appToUpdate.name);
|
||||
let logs = "";
|
||||
if (pendingUpdates.length > 0) {
|
||||
logs = await caprover.getLogs(appToUpdate.name);
|
||||
}
|
||||
|
||||
return new Response(
|
||||
Layout(Page(appToUpdate, latestVersions, pendingUpdates)),
|
||||
Layout(Page(appToUpdate, latestVersions, pendingUpdates, logs)),
|
||||
{
|
||||
headers: { "Content-Type": "text/html" },
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user