feat: initial mini simple event sourcing for pending application updates
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import AppQueries from "../domain/AppQueries";
|
||||
import { UpdateDefinition } from "../domain/projections/ApplicationUpdates";
|
||||
import Caprover, { Application } from "../services/Caprover";
|
||||
import DockerHub from "../services/DockerHub";
|
||||
import Layout, { html } from "../ui/Layout";
|
||||
@@ -19,10 +21,33 @@ const UpdateForm = (application: Application, latestVersions: string[]) => {
|
||||
</form>`;
|
||||
};
|
||||
|
||||
const Page = (application: Application, latestVersions: string[]) => {
|
||||
const PendingUpdates = (pendingUpdates: UpdateDefinition[]) => {
|
||||
if (pendingUpdates.length === 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return html`<div>
|
||||
<h2>Pending updates</h2>
|
||||
<ul>
|
||||
${pendingUpdates
|
||||
.map((update) => {
|
||||
return html`<li>${update.newVersion}</li>`;
|
||||
})
|
||||
.join("")}
|
||||
</ul>
|
||||
</div>`;
|
||||
};
|
||||
|
||||
const Page = (
|
||||
application: Application,
|
||||
latestVersions: string[],
|
||||
pendingUpdates: UpdateDefinition[]
|
||||
) => {
|
||||
return html`<div>
|
||||
<h1>Updating ${application.name}</h1>
|
||||
|
||||
${PendingUpdates(pendingUpdates)}
|
||||
|
||||
<dl>
|
||||
<dt>Last deployment</dt>
|
||||
<dd>${application.lastDeployedAt.toLocaleString("fr-FR")}</dd>
|
||||
@@ -49,12 +74,15 @@ const Page = (application: Application, latestVersions: string[]) => {
|
||||
export default async (
|
||||
req: Request,
|
||||
caprover: Caprover,
|
||||
dockerHub: DockerHub
|
||||
dockerHub: DockerHub,
|
||||
queries: AppQueries
|
||||
): Promise<Response> => {
|
||||
if (req.method === "POST") {
|
||||
const body = await req.formData();
|
||||
console.log("TODO Implement application update", [...body.entries()]);
|
||||
throw new Error("Not implemented");
|
||||
caprover.updateApplication(
|
||||
body.get("appName") as string,
|
||||
body.get("version") as string
|
||||
);
|
||||
}
|
||||
|
||||
const applications = await caprover.getApps();
|
||||
@@ -76,7 +104,12 @@ export default async (
|
||||
appToUpdate.dockerImage!.name
|
||||
);
|
||||
|
||||
return new Response(Layout(Page(appToUpdate, latestVersions)), {
|
||||
headers: { "Content-Type": "text/html" },
|
||||
});
|
||||
const pendingUpdates = queries.pendingApplicationUpdates(appToUpdate.name);
|
||||
|
||||
return new Response(
|
||||
Layout(Page(appToUpdate, latestVersions, pendingUpdates)),
|
||||
{
|
||||
headers: { "Content-Type": "text/html" },
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user