From 56b52ade1e6b9767e4375315e62e7cde212ca9de Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 21 Apr 2023 11:10:00 +0100 Subject: [PATCH] Services --- src/Types.ts | 24 +++- src/lib/ServiceStats.svelte | 129 +++++++++++++++++++ src/routes/[slug]/+page.server.ts | 5 +- src/routes/[slug]/+page.svelte | 200 +++++++++++++++++------------- 4 files changed, 265 insertions(+), 93 deletions(-) create mode 100644 src/lib/ServiceStats.svelte diff --git a/src/Types.ts b/src/Types.ts index d3ccb87..7e457db 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -12,11 +12,15 @@ export interface Template { command?: string; interactive?: boolean; logo: string; - image: string; + image?: string; restart_policy?: 'always' | 'unless-stopped' | 'on-failure' | 'no'; ports?: string[]; volumes?: Volume[]; - environment?: Environment[]; + env?: Environment[]; + repository?: { + stackfile: string; + url: string; + }; } export interface Volume { @@ -27,4 +31,20 @@ export interface Volume { export interface Environment { name: string; label?: string; + set?: string; } + +export interface Service { + name: string; + image?: string; + entrypoint?: string; + restart_policy?: 'always' | 'unless-stopped' | 'on-failure' | 'no'; + volumes?: Volume[]; + command?: string; + ports?: string[]; + build?: string; + interactive?: boolean; + environment?: Environment[]; +} + +export interface TemplateOrService extends Template, Service {} diff --git a/src/lib/ServiceStats.svelte b/src/lib/ServiceStats.svelte new file mode 100644 index 0000000..1944dae --- /dev/null +++ b/src/lib/ServiceStats.svelte @@ -0,0 +1,129 @@ + + + +
+ {#if template.type} +
+ Type + {#if template.type === 1} + Container + {:else if template.type === 2} + Swarm + {:else if template.type === 3} + Kubernetes + {:else} + Unknown + {/if} +
+ {/if} + {#if template.platform} +
+ Platform + {template.platform} +
+ {/if} + {#if template.image} +
+ Image + {template.image} +
+ {/if} + {#if template.command} +
+ Command + {template.command} +
+ {/if} + {#if typeof template.interactive === 'boolean'} +
+ Interactive + {template.interactive ? 'Yes' : 'No'} +
+ {/if} + {#if template.ports} +
+ Ports +

+ {#each template.ports as port}{port}{/each} +

+
+ {/if} + {#if template.volumes} +
+ Volumes +

+ {#each template.volumes as volume}{volume.container || volume}{/each} +

+
+ {/if} + {#if template.restart_policy} +
+ Restart Policy + {template.restart_policy} +
+ {/if} + {#if template.repository} +
+ Sourced + Repo +
+ {/if} + {#if template.entrypoint} +
+ Entrypoint + {template.entrypoint} +
+ {/if} + {#if template.build} +
+ Build + {template.build} +
+ {/if} + {#if template.env} +
+ Env Vars +

+ {#each template.env as env}{env.name}={env.set || env.value || env.default}{/each} +

+
+ {/if} +
+ + diff --git a/src/routes/[slug]/+page.server.ts b/src/routes/[slug]/+page.server.ts index 1679860..c772f88 100644 --- a/src/routes/[slug]/+page.server.ts +++ b/src/routes/[slug]/+page.server.ts @@ -10,10 +10,9 @@ export const load = async () => { } } else { const data = await fetch(templatesUrl).then((res) => res.json()); - templates.set(data.templates); - + templates.set(data.templates); return { templates: data.templates, } } -}; \ No newline at end of file +}; diff --git a/src/routes/[slug]/+page.svelte b/src/routes/[slug]/+page.svelte index cd61842..346bc5a 100644 --- a/src/routes/[slug]/+page.svelte +++ b/src/routes/[slug]/+page.svelte @@ -1,8 +1,11 @@
@@ -26,74 +93,38 @@ {#if template}
-

{template.title}{template.title}

- {#if template.categories} +

+ {#if template.logo} {/if} + {template.title} +

+ {#if template.categories || template.category }

- {#each (template.categories) as tag} + {#each (template.categories || template.category || []) as tag} {tag} {/each}

{/if}

{template.description}

-
- {#if template.type} -
- Type - {#if template.type === 1} - Container - {:else if template.type === 2} - Swarm - {:else if template.type === 3} - Kubernetes - {:else} - Unknown - {/if} -
- {/if} - {#if template.platform} -
- Platform - {template.platform} -
- {/if} - {#if template.image} -
- Image - {template.image} -
- {/if} - {#if template.command} -
- Command - {template.command} -
- {/if} - {#if typeof template.interactive === 'boolean'} -
- Interactive - {template.interactive ? 'Yes' : 'No'} -
- {/if} - {#if template.ports} -
- Ports -

- {#each template.ports as port}{port}{/each} -

-
- {/if} - {#if template.volumes} -
- Volumes -

- {#each template.volumes as volume}{volume.container}{/each} -

-
- {/if} -
+
+ + {#await services then returnedServices} + {#if returnedServices && returnedServices.length > 0} +
+

Services

+
+ {#each returnedServices as service} +
+

{service.name}

+ +
+ {/each} +
+
+ {/if} + {/await} {:else} {/if} @@ -156,6 +187,7 @@ gap: 1rem; } img { + border-radius: 6px; width: 64px; max-height: 64px; } @@ -183,34 +215,26 @@ p.description { max-width: 60%; } - .stats { - min-width: 15rem; - border: 2px solid var(--background); - border-radius: 6px; - .row { - display: flex; - justify-content: space-between; - align-items: center; - flex-wrap: wrap; - padding: 0.5rem; - gap: 0.5rem; - &:not(:last-child) { - border-bottom: 2px dotted var(--background); - } - span { - font-style: italic; - } - p { - margin: 0; - display: flex; - flex-direction: column; - } - .lbl { - font-weight: 400; - font-style: normal; - min-width: 5rem; - } + } + + .service-section { + background: var(--card); + border-radius: 6px; + margin: 1rem; + padding: 1rem; + h2 { + margin: 0; + font-size: 2rem; + } + .service-list { + display: flex; + gap: 1rem; + // justify-content: space-between; + flex-wrap: wrap; + h3 { + margin: 0.5rem 0; + font-weight: 400; } } } - \ No newline at end of file +