frontend.svelte
· 6.2 KiB · Svelte
Sin formato
<script lang="ts">
import ButtonReact from "$lib/components/ButtonReact.svelte";
import GreyText from "$lib/components/GreyText.svelte";
import InputNumber from "$lib/components/InputNumber.svelte";
import InputSm from "$lib/components/InputSm.svelte";
import MultiInput from "$lib/components/MultiInput.svelte";
import KvMultiInput from "$lib/components/KVMultiInput.svelte";
import Select from "$lib/components/Select.svelte";
import DeployWebhook from "./DeployWebhook.svelte";
import type { Data } from "./dpsettings";
import Section from "$lib/components/Section.svelte";
const getDeploySourceTypes = async () => {
let res = await fetch(`/api/deploy/getDeploySourceTypes`, {
method: "POST",
});
if(!res.ok) {
let error = await res.text()
throw new Error(error)
}
return await res.json() as string[]
}
const parseSrc = (srcs: string[]): [string, string][] => {
return srcs?.map(src => [src, src])
}
interface Preset {
[key: string]: {
buildCmds: string[],
env: [string, string][],
allowDirty: boolean,
configFiles: string[],
}
}
const presets: Preset = {
"NPM": {
buildCmds: [
"npm install",
"npm run build",
],
env: [],
allowDirty: true,
configFiles: []
},
"Yarn": {
buildCmds: [
"yarn install",
"yarn install --dev",
"yarn run build"
],
env: [],
allowDirty: true,
configFiles: []
},
"Go": {
buildCmds: [
"go build -v"
],
env: [
["CGO_ENABLED", "0"],
],
allowDirty: false,
configFiles: [
"config.yaml",
"secrets.yaml"
]
},
"Rust": {
buildCmds: [
"/root/.cargo/bin/cargo build --release",
"systemctl stop $NAME",
"rm -vf $NAME",
"mv -vf target/release/$NAME .",
"systemctl start $NAME",
],
env: [
["RUSTFLAGS", "-C target-cpu=native -C link-arg=-fuse-ld=lld"]
],
allowDirty: true,
configFiles: [
"config.yaml"
]
}
}
export let id: string
export let data: Data;
</script>
<InputSm
id="id"
label="Deployment ID"
placeholder="infinity-next-deploy"
bind:value={id}
minlength={1}
/>
<h2 class="text-xl font-semibold">IP Whitelist</h2>
<GreyText>
If this has more than one IP, then only IPs in this list will be able to use this API
</GreyText>
<MultiInput
id="allowed-ips"
label="Allowed IP whitelist"
title="IP Whitelist"
placeholder="X.X.X.X"
bind:values={data.allowedIps}
minlength={1}
/>
<h2 class="text-xl font-semibold">Deploy Source</h2>
<div>
{#await getDeploySourceTypes()}
<h2 class="text-xl">Loading deploy source list</h2>
{:then srcs}
<Select
name="Source Type"
placeholder="Choose source type"
bind:value={data.type}
options={
new Map([
...parseSrc(srcs)
])
}
/>
<InputSm
id="url"
label="URL"
placeholder="https://..."
bind:value={data.url}
minlength={1}
/>
<InputSm
id="token"
label="Token"
placeholder="Any API token you need to access the source"
bind:value={data.token}
minlength={1}
/>
<InputSm
id="ref"
label="Reference"
placeholder="refs/head/master"
bind:value={data.ref}
minlength={1}
/>
{:catch err}
<h2 class="text-red-500">{err}</h2>
{/await}
</div>
<Select
name="broken"
placeholder="Is the service broken/disabled?"
bind:value={data.brokenValue}
options={new Map([
["Yes, it is", "0"],
["No, its not", "1"],
])}
/>
<InputSm
id="output-path"
label="Output Path"
placeholder="/var/www/html etc."
bind:value={data.outputPath}
minlength={1}
/>
<h3 class="font-semibold">Presets</h3>
<div>
{#each Object.entries(presets) as [name, preset]}
<ButtonReact
onclick={() => {
data.commands = preset?.buildCmds
if(preset?.env && preset?.env.length > 0) {
data.env = preset?.env
}
if(preset?.configFiles && preset?.configFiles.length > 0) {
data.configFiles = preset?.configFiles
}
}}
>
{name}
</ButtonReact>
<span class="ml-2"></span>
{/each}
</div>
<div class="mb-1"></div>
<MultiInput
id="commands"
label="Build Commands"
title="Command"
placeholder="npm install..."
bind:values={data.commands}
minlength={1}
/>
<InputNumber
id="timeout"
label="Timeout"
placeholder="1234"
bind:value={data.timeout}
/>
<KvMultiInput
id="git-env"
label="Environment Variables"
title="Key"
placeholder="KEY"
bind:values={data.env}
minlength={1}
/>
<MultiInput
id="config-files"
label="Config files to preserve"
title="Config files"
placeholder="npm install"
bind:values={data.configFiles}
minlength={1}
/>
<div class="mb-1"></div>
<h3 class="text-xl font-semibold">Webhooks</h3>
{#each data.webhooks as webh}
<Section title={webh?.id || "Not Specified"}>
<DeployWebhook
id={webh?.id}
bind:webhook={webh}
/>
</Section>
{/each}
<ButtonReact onclick={() => {
data.webhooks.push({
id: "git",
token: "",
type: ""
})
data.webhooks = data.webhooks
}}>
New Webhook
</ButtonReact>
<h3 class="text-xl font-semibold">Misc.</h3>
<!-- <ButtonReact onclick={() => createGit()}>Create/Update</ButtonReact> -->
1 | <script lang="ts"> |
2 | import ButtonReact from "$lib/components/ButtonReact.svelte"; |
3 | import GreyText from "$lib/components/GreyText.svelte"; |
4 | import InputNumber from "$lib/components/InputNumber.svelte"; |
5 | import InputSm from "$lib/components/InputSm.svelte"; |
6 | import MultiInput from "$lib/components/MultiInput.svelte"; |
7 | import KvMultiInput from "$lib/components/KVMultiInput.svelte"; |
8 | import Select from "$lib/components/Select.svelte"; |
9 | import DeployWebhook from "./DeployWebhook.svelte"; |
10 | import type { Data } from "./dpsettings"; |
11 | import Section from "$lib/components/Section.svelte"; |
12 | |
13 | const getDeploySourceTypes = async () => { |
14 | let res = await fetch(`/api/deploy/getDeploySourceTypes`, { |
15 | method: "POST", |
16 | }); |
17 | |
18 | if(!res.ok) { |
19 | let error = await res.text() |
20 | |
21 | throw new Error(error) |
22 | } |
23 | |
24 | return await res.json() as string[] |
25 | } |
26 | |
27 | const parseSrc = (srcs: string[]): [string, string][] => { |
28 | return srcs?.map(src => [src, src]) |
29 | } |
30 | |
31 | interface Preset { |
32 | [key: string]: { |
33 | buildCmds: string[], |
34 | env: [string, string][], |
35 | allowDirty: boolean, |
36 | configFiles: string[], |
37 | } |
38 | } |
39 | |
40 | const presets: Preset = { |
41 | "NPM": { |
42 | buildCmds: [ |
43 | "npm install", |
44 | "npm run build", |
45 | ], |
46 | env: [], |
47 | allowDirty: true, |
48 | configFiles: [] |
49 | }, |
50 | "Yarn": { |
51 | buildCmds: [ |
52 | "yarn install", |
53 | "yarn install --dev", |
54 | "yarn run build" |
55 | ], |
56 | env: [], |
57 | allowDirty: true, |
58 | configFiles: [] |
59 | }, |
60 | "Go": { |
61 | buildCmds: [ |
62 | "go build -v" |
63 | ], |
64 | env: [ |
65 | ["CGO_ENABLED", "0"], |
66 | ], |
67 | allowDirty: false, |
68 | configFiles: [ |
69 | "config.yaml", |
70 | "secrets.yaml" |
71 | ] |
72 | }, |
73 | "Rust": { |
74 | buildCmds: [ |
75 | "/root/.cargo/bin/cargo build --release", |
76 | "systemctl stop $NAME", |
77 | "rm -vf $NAME", |
78 | "mv -vf target/release/$NAME .", |
79 | "systemctl start $NAME", |
80 | ], |
81 | env: [ |
82 | ["RUSTFLAGS", "-C target-cpu=native -C link-arg=-fuse-ld=lld"] |
83 | ], |
84 | allowDirty: true, |
85 | configFiles: [ |
86 | "config.yaml" |
87 | ] |
88 | } |
89 | } |
90 | |
91 | export let id: string |
92 | export let data: Data; |
93 | </script> |
94 | |
95 | <InputSm |
96 | id="id" |
97 | label="Deployment ID" |
98 | placeholder="infinity-next-deploy" |
99 | bind:value={id} |
100 | minlength={1} |
101 | /> |
102 | |
103 | <h2 class="text-xl font-semibold">IP Whitelist</h2> |
104 | |
105 | <GreyText> |
106 | If this has more than one IP, then only IPs in this list will be able to use this API |
107 | </GreyText> |
108 | |
109 | <MultiInput |
110 | id="allowed-ips" |
111 | label="Allowed IP whitelist" |
112 | title="IP Whitelist" |
113 | placeholder="X.X.X.X" |
114 | bind:values={data.allowedIps} |
115 | minlength={1} |
116 | /> |
117 | |
118 | <h2 class="text-xl font-semibold">Deploy Source</h2> |
119 | |
120 | <div> |
121 | {#await getDeploySourceTypes()} |
122 | <h2 class="text-xl">Loading deploy source list</h2> |
123 | {:then srcs} |
124 | <Select |
125 | name="Source Type" |
126 | placeholder="Choose source type" |
127 | bind:value={data.type} |
128 | options={ |
129 | new Map([ |
130 | ...parseSrc(srcs) |
131 | ]) |
132 | } |
133 | /> |
134 | <InputSm |
135 | id="url" |
136 | label="URL" |
137 | placeholder="https://..." |
138 | bind:value={data.url} |
139 | minlength={1} |
140 | /> |
141 | <InputSm |
142 | id="token" |
143 | label="Token" |
144 | placeholder="Any API token you need to access the source" |
145 | bind:value={data.token} |
146 | minlength={1} |
147 | /> |
148 | <InputSm |
149 | id="ref" |
150 | label="Reference" |
151 | placeholder="refs/head/master" |
152 | bind:value={data.ref} |
153 | minlength={1} |
154 | /> |
155 | {:catch err} |
156 | <h2 class="text-red-500">{err}</h2> |
157 | {/await} |
158 | </div> |
159 | |
160 | <Select |
161 | name="broken" |
162 | placeholder="Is the service broken/disabled?" |
163 | bind:value={data.brokenValue} |
164 | options={new Map([ |
165 | ["Yes, it is", "0"], |
166 | ["No, its not", "1"], |
167 | ])} |
168 | /> |
169 | |
170 | <InputSm |
171 | id="output-path" |
172 | label="Output Path" |
173 | placeholder="/var/www/html etc." |
174 | bind:value={data.outputPath} |
175 | minlength={1} |
176 | /> |
177 | |
178 | <h3 class="font-semibold">Presets</h3> |
179 | |
180 | <div> |
181 | {#each Object.entries(presets) as [name, preset]} |
182 | <ButtonReact |
183 | onclick={() => { |
184 | data.commands = preset?.buildCmds |
185 | |
186 | if(preset?.env && preset?.env.length > 0) { |
187 | data.env = preset?.env |
188 | } |
189 | |
190 | if(preset?.configFiles && preset?.configFiles.length > 0) { |
191 | data.configFiles = preset?.configFiles |
192 | } |
193 | }} |
194 | > |
195 | {name} |
196 | </ButtonReact> |
197 | <span class="ml-2"></span> |
198 | {/each} |
199 | </div> |
200 | |
201 | <div class="mb-1"></div> |
202 | |
203 | <MultiInput |
204 | id="commands" |
205 | label="Build Commands" |
206 | title="Command" |
207 | placeholder="npm install..." |
208 | bind:values={data.commands} |
209 | minlength={1} |
210 | /> |
211 | |
212 | <InputNumber |
213 | id="timeout" |
214 | label="Timeout" |
215 | placeholder="1234" |
216 | bind:value={data.timeout} |
217 | /> |
218 | |
219 | <KvMultiInput |
220 | id="git-env" |
221 | label="Environment Variables" |
222 | title="Key" |
223 | placeholder="KEY" |
224 | bind:values={data.env} |
225 | minlength={1} |
226 | /> |
227 | |
228 | <MultiInput |
229 | id="config-files" |
230 | label="Config files to preserve" |
231 | title="Config files" |
232 | placeholder="npm install" |
233 | bind:values={data.configFiles} |
234 | minlength={1} |
235 | /> |
236 | |
237 | <div class="mb-1"></div> |
238 | |
239 | <h3 class="text-xl font-semibold">Webhooks</h3> |
240 | |
241 | {#each data.webhooks as webh} |
242 | <Section title={webh?.id || "Not Specified"}> |
243 | <DeployWebhook |
244 | id={webh?.id} |
245 | bind:webhook={webh} |
246 | /> |
247 | </Section> |
248 | {/each} |
249 | <ButtonReact onclick={() => { |
250 | data.webhooks.push({ |
251 | id: "git", |
252 | token: "", |
253 | type: "" |
254 | }) |
255 | data.webhooks = data.webhooks |
256 | }}> |
257 | New Webhook |
258 | </ButtonReact> |
259 | |
260 | <h3 class="text-xl font-semibold">Misc.</h3> |
261 | |
262 | <!-- <ButtonReact onclick={() => createGit()}>Create/Update</ButtonReact> --> |