/
RunImage.svelte
1115 lines (990 loc) · 44.4 KB
/
RunImage.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<script lang="ts">
import { runImageInfo } from '../../stores/run-image-store';
import { onMount } from 'svelte';
import type { ContainerCreateOptions, HostConfig } from '../../../../main/src/plugin/api/container-info';
import type { ImageInspectInfo } from '../../../../main/src/plugin/api/image-inspect-info';
import FormPage from '../ui/FormPage.svelte';
import type { ImageInfoUI } from './ImageInfoUI';
import { faFolderOpen, faMinusCircle, faPlay, faPlusCircle, faXmark } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa';
import { router } from 'tinro';
import Route from '../../Route.svelte';
import type { NetworkInspectInfo } from '../../../../main/src/plugin/api/network-info';
import type { ContainerInfoUI } from '../container/ContainerInfoUI';
import { ContainerUtils } from '../container/container-utils';
import { containersInfos } from '../../stores/containers';
import ErrorMessage from '../ui/ErrorMessage.svelte';
import { splitSpacesHandlingDoubleQuotes } from '../string/string';
import { array2String } from '/@/lib/string/string.js';
import Tab from '../ui/Tab.svelte';
import Button from '../ui/Button.svelte';
import Input from '/@/lib/ui/Input.svelte';
interface PortInfo {
port: string;
error: string;
}
let image: ImageInfoUI;
let imageInspectInfo: ImageInspectInfo;
let containerName = '';
let containerNameError = '';
let command = '';
let entrypoint = '';
let containerPortMapping: PortInfo[];
let exposedPorts: string[] = [];
let createError: string | undefined = undefined;
let restartPolicyName = '';
let restartPolicyMaxRetryCount = 1;
let onPortInputTimeout: NodeJS.Timeout;
// initialize with empty array
let environmentVariables: { key: string; value: string }[] = [{ key: '', value: '' }];
let environmentFiles: string[] = [''];
let volumeMounts: { source: string; target: string }[] = [{ source: '', target: '' }];
let hostContainerPortMappings: { hostPort: PortInfo; containerPort: string }[] = [];
let invalidName = false;
let invalidPorts = false;
$: invalidFields = invalidName || invalidPorts;
// auto remove the container on exit
let autoRemove = false;
// privileged moade
let privileged = false;
// read-only moade
let readOnly = false;
// security options
let securityOpts: string[] = [''];
// Kernel capabilities
let capAdds: string[] = [''];
let capDrops: string[] = [''];
// user namespace
let userNamespace: string | undefined = undefined;
// hostname;
let hostname: string | undefined = undefined;
// dns servers
let dnsServers: string[] = [''];
// extra hosts
let extraHosts: { host: string; ip: string }[] = [{ host: '', ip: '' }];
// networking mode
let networkingMode = 'bridge';
// user defined network if user choose a pre-defined network
let networkingModeUserNetwork = '';
// container defined network if user choose a pre-defined container
let networkingModeUserContainer = '';
// tty
let useTty = true;
let useInteractive = true;
let runUser: string | undefined = undefined;
let dataReady = false;
let imageDisplayName = '';
let engineNetworks: NetworkInspectInfo[] = [];
let engineContainers: ContainerInfoUI[] = [];
onMount(async () => {
// grab current value
image = $runImageInfo;
if (!image) {
// go back to image list
router.goto('/images/');
return;
}
containerPortMapping = [];
imageInspectInfo = await window.getImageInspect(image.engineId, image.id);
exposedPorts = Array.from(Object.keys(imageInspectInfo?.Config?.ExposedPorts || {}));
command = array2String(imageInspectInfo.Config?.Cmd || []);
if (imageInspectInfo.Config?.Entrypoint) {
if (typeof imageInspectInfo.Config.Entrypoint === 'string') {
entrypoint = imageInspectInfo.Config.Entrypoint;
} else {
entrypoint = array2String(imageInspectInfo.Config.Entrypoint);
}
} else {
entrypoint = '';
}
// auto-assign ports from available free port
containerPortMapping = new Array<PortInfo>(exposedPorts.length);
await Promise.all(
exposedPorts.map(async (port, index) => {
const localPorts = await getPortsInfo(port);
if (localPorts) {
containerPortMapping[index] = { port: localPorts, error: '' };
}
}),
);
dataReady = true;
if (image.name && image.name.length > 60) {
imageDisplayName = '...' + image.name.substring(image.name.length - 60);
} else {
imageDisplayName = image.name;
}
// grab all networks
const allNetworks = await window.listNetworks();
// keep only the network matching our engine
engineNetworks = allNetworks.filter(network => network.engineId === image.engineId);
if (engineNetworks.length > 0) {
// try to match the bridge network
const bridgeNetwork = engineNetworks.find(network => network.Name === 'bridge');
if (bridgeNetwork) {
networkingModeUserNetwork = bridgeNetwork.Id;
} else {
// fallback to the first network
networkingModeUserNetwork = engineNetworks[0].Id;
}
}
// grab all containers
const allContainers = await window.listContainers();
const containerUtils = new ContainerUtils();
// keep only the containers matching our engine
engineContainers = allContainers
.filter(container => container.engineId === image.engineId)
.map(container => containerUtils.getContainerInfoUI(container));
if (engineContainers.length > 0) {
// do we have a Running container ?
// sort from newest to oldest
const runningContainers = engineContainers
.filter(container => container.state === 'RUNNING')
.sort((a, b) => b.created - a.created);
if (runningContainers.length > 0) {
// use the first running container
networkingModeUserContainer = runningContainers[0].id;
} else {
// fallback to the first container
networkingModeUserContainer = engineContainers[0].id;
}
}
});
async function getPortsInfo(portDescriptor: string): Promise<string | undefined> {
// check if portDescriptor is a range of ports
if (portDescriptor.includes('-')) {
return await getPortRange(portDescriptor);
} else {
const localPort = await getPort(portDescriptor);
if (!localPort) {
return undefined;
}
return `${localPort}`;
}
}
/**
* Select an environment file
*/
async function selectEnvironmentFile(index: number) {
const filePaths = await window.openDialog({ title: 'Select environment file' });
if (filePaths?.length === 1) {
environmentFiles[index] = filePaths[0];
}
}
/**
* return a range of the same length as portDescriptor containing free ports
* undefined if the portDescriptor range is not valid
* e.g 5000:5001 -> 9000:9001
*/
async function getPortRange(portDescriptor: string): Promise<string | undefined> {
const rangeValues = getStartEndRange(portDescriptor);
if (!rangeValues) {
return Promise.resolve(undefined);
}
const rangeSize = rangeValues.endRange + 1 - rangeValues.startRange;
try {
// if free port range fails, return undefined
return await window.getFreePortRange(rangeSize);
} catch (e) {
console.error(e);
return undefined;
}
}
async function getPort(portDescriptor: string): Promise<number | undefined> {
let port: number;
if (portDescriptor.endsWith('/tcp') || portDescriptor.endsWith('/udp')) {
port = parseInt(portDescriptor.substring(0, portDescriptor.length - 4));
} else {
port = parseInt(portDescriptor);
}
// invalid port
if (isNaN(port)) {
return Promise.resolve(undefined);
}
try {
// if getFreePort fails, it returns undefined
return await window.getFreePort(port);
} catch (e) {
console.error(e);
return undefined;
}
}
async function startContainer() {
createError = undefined;
// create ExposedPorts objects
const ExposedPorts: any = {};
const PortBindings: any = {};
try {
exposedPorts.forEach((port, index) => {
if (port.includes('-') || containerPortMapping[index]?.port.includes('-')) {
addPortsFromRange(ExposedPorts, PortBindings, port, containerPortMapping[index].port);
} else {
if (containerPortMapping[index]?.port) {
PortBindings[port] = [{ HostPort: containerPortMapping[index].port }];
}
ExposedPorts[port] = {};
}
});
hostContainerPortMappings
.filter(pair => pair.hostPort.port && pair.containerPort)
.forEach(pair => {
if (pair.containerPort.includes('-') || pair.hostPort.port.includes('-')) {
addPortsFromRange(ExposedPorts, PortBindings, pair.containerPort, pair.hostPort.port);
} else {
PortBindings[pair.containerPort] = [{ HostPort: pair.hostPort.port }];
ExposedPorts[pair.containerPort] = {};
}
});
} catch (e) {
createError = String(e);
console.error('Error while creating container', e);
return;
}
const Env = environmentVariables
// filter variables withouts keys
.filter(env => env.key)
// no value, use empty string
.map(env => `${env.key}=${env.value || ''}`);
// filter empty files
const EnvFiles = environmentFiles.filter(env => env);
const Image = image.tag ? `${image.name}:${image.tag}` : image.id;
const RestartPolicy: { Name: string; MaximumRetryCount?: number } = {
Name: restartPolicyName,
};
// only set MaximumRetryCount if policy is 'on-failure'
if (restartPolicyName === 'on-failure') {
RestartPolicy.MaximumRetryCount = restartPolicyMaxRetryCount;
}
// need both source and target to be set
const Binds = volumeMounts
.filter(volume => volume.source && volume.target)
.map(volume => `${volume.source}:${volume.target}`);
const SecurityOpt = securityOpts.filter(opt => opt);
const CapAdd = capAdds.filter(cap => cap);
const CapDrop = capDrops.filter(cap => cap);
const ExtraHosts = extraHosts.filter(host => host.host && host.ip).map(host => `${host.host}:${host.ip}`);
const Privileged = privileged;
let NetworkMode;
switch (networkingMode) {
case 'bridge':
NetworkMode = 'bridge';
break;
case 'host':
NetworkMode = 'host';
break;
case 'none':
NetworkMode = 'none';
break;
case 'choice-network':
NetworkMode = networkingModeUserNetwork;
break;
case 'choice-container':
NetworkMode = `container:${networkingModeUserContainer}`;
break;
default:
NetworkMode = 'bridge';
}
const ReadonlyRootfs = readOnly;
const Tty = useTty;
const OpenStdin = useInteractive;
const HostConfig: HostConfig = {
Binds,
AutoRemove: autoRemove,
RestartPolicy,
PortBindings,
SecurityOpt,
Privileged,
ReadonlyRootfs,
CapAdd,
CapDrop,
NetworkMode,
};
const Dns = dnsServers.filter(dns => dns);
if (Dns.length > 0) {
HostConfig.Dns = Dns;
}
if (ExtraHosts.length > 0) {
HostConfig.ExtraHosts = ExtraHosts;
}
if (userNamespace) {
HostConfig.UsernsMode = userNamespace;
}
const options: ContainerCreateOptions = {
Image,
Env,
EnvFiles,
name: containerName,
HostConfig,
ExposedPorts,
Tty,
OpenStdin,
};
if (command.trim().length > 0) {
options.Cmd = splitSpacesHandlingDoubleQuotes(command);
}
if (entrypoint.trim().length > 0) {
options.Entrypoint = splitSpacesHandlingDoubleQuotes(entrypoint);
}
if (runUser) {
options.User = runUser;
}
if (hostname) {
options.Hostname = hostname;
}
try {
const data = await window.createAndStartContainer(imageInspectInfo.engineId, options);
// redirect to containers if no tty, else redirect to the container details
if (Tty && OpenStdin) {
router.goto(`/containers/${data.id}/tty`);
} else {
router.goto('/containers');
}
} catch (e) {
createError = String(e);
console.error('Error while creating container', e);
return;
}
}
function addPortsFromRange(
exposedPorts: { [key: string]: unknown },
portBindings: { [key: string]: unknown },
containerRange: string,
hostRange: string,
) {
const containerRangeValues = getStartEndRange(containerRange);
if (!containerRangeValues) {
throw new Error(`range ${containerRange} is not valid. Must be in format <port>-<port> (e.g 8080-8085)`);
}
const startContainerRange = containerRangeValues.startRange;
const endContainerRange = containerRangeValues.endRange;
const hostRangeValues = getStartEndRange(hostRange);
if (!hostRangeValues) {
throw new Error(`range ${hostRange} is not valid. Must be in format <port>-<port> (e.g 8080-8085)`);
}
const startHostRange = hostRangeValues.startRange;
const endHostRange = hostRangeValues.endRange;
// if the two ranges have different size, do not proceed
const containerRangeSize = endContainerRange + 1 - startContainerRange;
const hostRangeSize = endHostRange + 1 - startHostRange;
if (containerRangeSize !== hostRangeSize) {
throw new Error(
`host and container port ranges (${hostRange}:${containerRange}) have different lengths: ${hostRangeSize} vs ${containerRangeSize}`,
);
}
// we add all ports separately - if we have two ranges like 8080-8082 and 9000-9002 we'll end up with a mapping like
// 8080 => HostPort: 9000
// 8081 => HostPort: 9001
// 8082 => HostPort: 9002
for (let i = 0; i < containerRangeSize; i++) {
portBindings[`${startContainerRange + i}`] = [{ HostPort: `${startHostRange + i}` }];
exposedPorts[`${startContainerRange + i}`] = {};
}
}
function getStartEndRange(range: string) {
if (range.endsWith('/tcp') || range.endsWith('/udp')) {
range = range.substring(0, range.length - 4);
}
const rangeValues = range.split('-');
if (rangeValues.length !== 2) {
return undefined;
}
const startRange = parseInt(rangeValues[0]);
const endRange = parseInt(rangeValues[1]);
if (isNaN(startRange) || isNaN(endRange)) {
return undefined;
}
return {
startRange,
endRange,
};
}
function addEnvVariable() {
environmentVariables = [...environmentVariables, { key: '', value: '' }];
}
function deleteEnvVariable(index: number) {
environmentVariables = environmentVariables.filter((_, i) => i !== index);
}
function addEnvFile() {
environmentFiles = [...environmentFiles, ''];
}
function deleteEnvFile(index: number) {
environmentFiles = environmentFiles.filter((_, i) => i !== index);
}
function handleCleanValueEnvFile(
event: MouseEvent & {
currentTarget: EventTarget & HTMLButtonElement;
},
index: number,
) {
environmentFiles[index] = '';
event.preventDefault();
}
function addHostContainerPorts() {
hostContainerPortMappings = [
...hostContainerPortMappings,
{
hostPort: {
port: '',
error: '',
},
containerPort: '',
},
];
}
function deleteHostContainerPorts(index: number) {
hostContainerPortMappings = hostContainerPortMappings.filter((_, i) => i !== index);
}
async function browseFolders(index: number) {
// need to show the dialog to open a folder and then we update the source of the given index
const result = await window.openFolderDialog('Select a directory to mount in the container');
if (!result.canceled && result.filePaths.length === 1) {
volumeMounts[index].source = result.filePaths[0];
}
}
function addVolumeMount() {
volumeMounts = [...volumeMounts, { source: '', target: '' }];
}
function deleteVolumeMount(index: number) {
volumeMounts = volumeMounts.filter((_, i) => i !== index);
}
function deleteSecurityOpt(index: number) {
securityOpts = securityOpts.filter((_, i) => i !== index);
}
function addSecurityOpt() {
securityOpts = [...securityOpts, ''];
}
function addCapAdd() {
capAdds = [...capAdds, ''];
}
function addCapDrop() {
capDrops = [...capDrops, ''];
}
function deleteCapAdd(index: number) {
capAdds = capAdds.filter((_, i) => i !== index);
}
function deleteCappDrop(index: number) {
capDrops = capDrops.filter((_, i) => i !== index);
}
function addDnsServer() {
dnsServers = [...dnsServers, ''];
}
function deleteDnsServer(index: number) {
dnsServers = dnsServers.filter((_, i) => i !== index);
}
function addExtraHost() {
extraHosts = [...extraHosts, { host: '', ip: '' }];
}
function deleteExtraHost(index: number) {
extraHosts = extraHosts.filter((_, i) => i !== index);
}
// called when user change the container's name
function checkContainerName(event: any) {
const containerValue = event.target.value;
// ok, now check if we already have a matching container: same name and same engine ID
const containerAlreadyExists = $containersInfos.find(
container =>
container.engineId === imageInspectInfo.engineId &&
container.Names.some(iteratingContainerName => iteratingContainerName === `/${containerValue}`),
);
if (containerAlreadyExists) {
containerNameError = `The name ${containerValue} already exists. Please choose another name or leave blank to generate a name.`;
invalidName = true;
} else {
containerNameError = '';
invalidName = false;
}
}
function onContainerPortMappingInput(event: Event, index: number) {
onPortInput(event, containerPortMapping[index], () => {
containerPortMapping = containerPortMapping;
assertAllPortAreValid();
});
}
function onHostContainerPortMappingInput(event: Event, index: number) {
onPortInput(event, hostContainerPortMappings[index].hostPort, () => {
hostContainerPortMappings = hostContainerPortMappings;
assertAllPortAreValid();
});
}
function onPortInput(event: Event, portInfo: PortInfo, updateUI: () => void) {
// clear the timeout so if there was an old call to areAllPortsFree pending is deleted. We will create a new one soon
clearTimeout(onPortInputTimeout);
const target = event.currentTarget as HTMLInputElement;
// convert string to number
const _value: number = Number(target.value);
// if number is not valid (NaN or outside the value range), set the error
if (isNaN(_value) || _value < 0 || _value > 65535) {
portInfo.error = 'port should be >= 0 and < 65536';
updateUI();
return;
}
onPortInputTimeout = setTimeout(() => {
isPortFree(_value).then(isFree => {
portInfo.error = isFree;
updateUI();
});
}, 500);
}
function isPortFree(port: number): Promise<string> {
return window
.isFreePort(port)
.then(isFree => {
if (!isFree) {
return `Port ${port} is already in use`;
} else {
return '';
}
})
.catch((_: unknown) => `Port ${port} is already in use`);
}
async function assertAllPortAreValid(): Promise<void> {
const invalidHostPorts = hostContainerPortMappings.filter(pair => pair.hostPort.error);
const invalidContainerPortMapping = containerPortMapping?.filter(port => port.error) || [];
invalidPorts = invalidHostPorts.length > 0 || invalidContainerPortMapping.length > 0;
}
</script>
<Route path="/*">
{#if dataReady}
<FormPage title="Create a container from image {imageDisplayName}:{image.tag}">
<svelte:fragment slot="icon">
<i class="fas fa-play fa-2x" aria-hidden="true"></i>
</svelte:fragment>
<div slot="content" class="p-5 min-w-full h-fit">
<div class="bg-charcoal-600 px-6 py-4 space-y-2 lg:px-8 sm:pb-6 xl:pb-8">
<div class="flex flex-row px-2 border-b border-charcoal-400">
<Tab title="Basic" url="basic" />
<Tab title="Advanced" url="advanced" />
<Tab title="Networking" url="networking" />
<Tab title="Security" url="security" />
</div>
<div>
<Route path="/basic" breadcrumb="Basic" navigationHint="tab">
<div class="h-96 overflow-y-auto pr-4">
<label for="modalContainerName" class="block mb-2 text-sm font-medium text-gray-400"
>Container name:</label>
<Input
on:input="{event => checkContainerName(event)}"
bind:value="{containerName}"
name="modalContainerName"
id="modalContainerName"
placeholder="Leave blank to generate a name"
error="{containerNameError}" />
<label for="modalEntrypoint" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Entrypoint:</label>
<Input bind:value="{entrypoint}" name="modalEntrypoint" id="modalEntrypoint" />
<label for="modalCommand" class="pt-4 block mb-2 text-sm font-medium text-gray-400">Command:</label>
<Input bind:value="{command}" name="modalCommand" id="modalCommand" />
<label for="volumes" class="pt-4 block mb-2 text-sm font-medium text-gray-400">Volumes:</label>
<!-- Display the list of volumes -->
{#each volumeMounts as volumeMount, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<Input bind:value="{volumeMount.source}" placeholder="Path on the host" class="ml-2" />
<button
title="Open dialog to select a directory"
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
on:click="{() => browseFolders(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faFolderOpen}" />
</button>
<Input
bind:value="{volumeMount.target}"
placeholder="Path inside the container"
class="ml-2 w-full" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === volumeMounts.length - 1}"
on:click="{() => deleteVolumeMount(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < volumeMounts.length - 1}"
on:click="{addVolumeMount}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
<!-- add a label for each port-->
<label for="modalContainerName" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Port mapping:</label>
{#each exposedPorts as port, index}
<div class="flex flex-row justify-center items-center w-full">
<span class="text-sm flex-1 inline-block align-middle whitespace-nowrap text-gray-700"
>Local port for {port}:</span>
<Input
bind:value="{containerPortMapping[index].port}"
on:input="{event => onContainerPortMappingInput(event, index)}"
placeholder="Enter value for port {port}"
error="{containerPortMapping[index].error}"
class="ml-2 w-full"
title="{containerPortMapping[index].error}" />
</div>
{/each}
<Button class="pt-3 pb-2" on:click="{addHostContainerPorts}" icon="{faPlusCircle}" type="link">
Add custom port mapping
</Button>
<!-- Display the list of existing hostContainerPortMappings -->
{#each hostContainerPortMappings as hostContainerPortMapping, index}
<div class="flex flex-row justify-center w-full py-1">
<Input
bind:value="{hostContainerPortMapping.hostPort.port}"
on:input="{event => onHostContainerPortMappingInput(event, index)}"
aria-label="host port"
placeholder="Host Port"
error="{hostContainerPortMapping.hostPort.error}"
class="w-full"
title="{hostContainerPortMapping.hostPort.error}" />
<Input
bind:value="{hostContainerPortMapping.containerPort}"
aria-label="container port"
placeholder="Container Port"
class="ml-2 w-full" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
on:click="{() => deleteHostContainerPorts(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
</div>
{/each}
<label for="modalEnvironmentVariables" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Environment variables:</label>
<!-- Display the list of existing environment variables -->
{#each environmentVariables as environmentVariable, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<Input bind:value="{environmentVariable.key}" placeholder="Name" class="w-full" />
<Input
bind:value="{environmentVariable.value}"
placeholder="Value (leave blank for empty)"
class="ml-2 w-full" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === environmentVariables.length - 1}"
on:click="{() => deleteEnvVariable(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < environmentVariables.length - 1}"
on:click="{addEnvVariable}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
</div>
<label for="modalEnvironmentFiles" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Environment files:</label>
<!-- Display the list of existing environment files -->
{#each environmentFiles as environmentFile, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<div class="w-full flex">
<Input
class="grow"
readonly
placeholder="Environment file containing KEY=VALUE items"
bind:value="{environmentFile}"
aria-label="environmentFile.{index}" />
<button
class="relative cursor-pointer right-5"
class:hidden="{!environmentFile}"
aria-label="clear"
on:click="{event => handleCleanValueEnvFile(event, index)}">
<Fa icon="{faXmark}" />
</button>
<Button
on:click="{() => selectEnvironmentFile(index)}"
id="filePath.{index}"
aria-label="button-select-env-file-{index}">Browse ...</Button>
</div>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === environmentFiles.length - 1}"
aria-label="Delete env file at index {index}"
on:click="{() => deleteEnvFile(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < environmentFiles.length - 1}"
aria-label="Add env file after index {index}"
on:click="{addEnvFile}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
</Route>
<Route path="/advanced" breadcrumb="Advanced" navigationHint="tab">
<div class="h-96 overflow-y-auto pr-4">
<!-- Use tty -->
<label for="containerTty" class="block mb-2 text-sm font-medium text-gray-400">Use TTY:</label>
<div class="flex flex-row justify-start items-center align-middle w-full text-gray-700 text-sm">
<input
type="checkbox"
bind:checked="{useTty}"
class="mx-2 outline-none text-sm"
aria-label="Attach a pseudo terminal" />
Attach a pseudo terminal
</div>
<div class="flex flex-row justify-start items-center align-middle w-full text-gray-700 text-sm">
<input
type="checkbox"
bind:checked="{useInteractive}"
class="mx-2 outline-none text-sm"
aria-label="Use interactive" />
Interactive: Keep STDIN open even if not attached
</div>
<!-- Specify user-->
<label for="containerUser" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Specify user to run container as:</label>
<div class="flex flex-row justify-center items-center w-full">
<Input
bind:value="{runUser}"
placeholder="If you specify a username, user must exist in /etc/passwd file (use user id instead)"
class="ml-2" />
</div>
<!-- Autoremove-->
<label for="containerAutoRemove" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Auto removal of container:</label>
<div class="flex flex-row justify-start items-center align-middle w-full text-gray-700 text-sm">
<input type="checkbox" bind:checked="{autoRemove}" class="mx-2 outline-none text-sm" />
Automatically remove the container when the process exits
</div>
<!-- RestartPolicy-->
<label for="containerRestartPolicy" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Restart policy:</label>
<div class="p-0 flex flex-row justify-start items-center align-middle w-full text-gray-700">
<span class="text-sm w-28 inline-block align-middle whitespace-nowrap text-gray-700"
>Policy name:</span>
<select
class="w-full p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
name="restartPolicyName"
bind:value="{restartPolicyName}">
<option value="">No restart</option>
<option value="no">Do not restart automatically</option>
<option value="always">Always restart</option>
<option value="unless-stopped">Restart only if user has not manually stopped</option>
<option value="on-failure">Restart only if exit code is non-zero</option>
</select>
</div>
<div
class="flex flex-row justify-center items-center w-full py-1 {restartPolicyName === 'on-failure'
? 'opacity-100'
: 'opacity-20'}">
<span
class="text-sm w-28 inline-block align-middle whitespace-nowrap text-gray-700"
title="Number of times to retry before giving up.">Retries:</span>
<input
type="number"
min="0"
bind:value="{restartPolicyMaxRetryCount}"
placeholder="Number of times to retry before giving up"
class="w-full p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
disabled="{restartPolicyName !== 'on-failure'}" />
</div>
</div>
</Route>
<Route path="/security" breadcrumb="Security" navigationHint="tab">
<div class="h-96 overflow-y-auto pr-4">
<!-- Privileged-->
<label for="containerPrivileged" class="block mb-2 text-sm font-medium text-gray-400"
>Privileged:</label>
<div class="flex flex-row justify-start items-center align-middle w-full text-gray-700 text-sm">
<input type="checkbox" bind:checked="{privileged}" class="mx-2 outline-none text-sm" />
Turn off security<i class="pl-1 fas fa-exclamation-triangle"></i>
</div>
<!-- Read-Only -->
<label for="containerReadOnly" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Read only:</label>
<div class="flex flex-row justify-start items-center align-middle w-full text-gray-700 text-sm">
<input type="checkbox" bind:checked="{readOnly}" class="mx-2 outline-none text-sm" />
Make containers root filesystem read-only
</div>
<label for="ContainerSecurityOptions" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Security options (security-opt):</label>
<!-- Display the list of existing security options -->
{#each securityOpts as securityOpt, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<Input
bind:value="{securityOpt}"
placeholder="Enter a security option (Ex. seccomp=/path/to/profile.json)"
class="ml-2" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === securityOpts.length - 1}"
on:click="{() => deleteSecurityOpt(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < securityOpts.length - 1}"
on:click="{addSecurityOpt}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
<label for="ContainerSecurityCapabilitiesAdd" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Capabilities:</label>
<label
for="ContainerSecurityCapabilitiesAdd"
class="pl-4 pt-2 block mb-2 text-sm font-medium text-gray-400">Add to the container (CapAdd):</label>
<!-- Display the list of existing capAdd -->
{#each capAdds as capAdd, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<Input bind:value="{capAdd}" placeholder="Enter a kernel capability (Ex. SYS_ADMIN)" class="ml-4" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === capAdds.length - 1}"
on:click="{() => deleteCapAdd(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < capAdds.length - 1}"
on:click="{addCapAdd}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
<label
for="ContainerSecurityCapabilitiesDrop"
class="pl-4 pt-2 block mb-2 text-sm font-medium text-gray-400"
>Drop from the container (CapDrop):</label>
<!-- Display the list of existing capDrop -->
{#each capDrops as capDrop, index}
<div class="flex flex-row justify-center items-center w-full py-1">
<Input
bind:value="{capDrop}"
placeholder="Enter a kernel capability (Ex. SYS_ADMIN)"
class="ml-4" />
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index === capDrops.length - 1}"
on:click="{() => deleteCappDrop(index)}">
<Fa class="h-4 w-4 text-xl" icon="{faMinusCircle}" />
</button>
<button
class="ml-2 p-2 outline-none text-sm bg-charcoal-800 rounded-sm text-gray-700 placeholder-gray-700"
hidden="{index < capDrops.length - 1}"
on:click="{addCapDrop}">
<Fa class="h-4 w-4 text-xl" icon="{faPlusCircle}" />
</button>
</div>
{/each}
<!-- Specify user namespace-->
<label for="containerUserNamespace" class="pt-4 block mb-2 text-sm font-medium text-gray-400"
>Specify user namespace to use:</label>
<div class="flex flex-row justify-center items-center w-full">
<Input bind:value="{userNamespace}" placeholder="Enter a user namespace" class="ml-2 w-full" />
</div>
</div>
</Route>
<Route path="/networking" breadcrumb="Networking" navigationHint="tab">
<div class="h-96 overflow-y-auto pr-4">
<!-- hostname-->
<label for="containerHostname" class="block mb-2 text-sm font-medium text-gray-400"
>Defines container hostname:</label>
<div class="flex flex-row justify-center items-center w-full">
<Input bind:value="{hostname}" placeholder="Must be a valid RFC 1123 hostname" class="ml-2" />