-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-7.js
More file actions
104 lines (96 loc) · 2.48 KB
/
task-7.js
File metadata and controls
104 lines (96 loc) · 2.48 KB
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
const registry = new Container({
position: {
x: 500,
y: 100,
},
width: 200,
height: 100,
label: "Registry (https://hub.docker.com)"
});
const host = new Container({
position: {
x: 50,
y: 250,
},
width: 500,
height: 300,
label: "Host"
});
const images = new Container({
position: {
x: 340,
y: 340,
},
width: 200,
height: 200,
label: "Images"
});
const containers = new Container({
position: {
x: 110,
y: 340,
},
width: 200,
height: 200,
label: "Containers"
});
const ubuntuImage = new DockerImage({
position: {x: 550, y: 120},
imageSrc: "./img/ubuntu-logo.png",
scale: 60,
name: "ubuntu",
animations: {
pull : {movement:[['x', -150], ['y', 250]]},
run: {
timeout: 1000,
movement: [['x', -200, 2000]]
}
}
});
async function taskInputHandle() {
if (input.command === 'rm') {
const foundContainer = containersArr.find((container) => container.id.substring(0, 11) === input.name);
term.write(input.name);
foundContainer.setStatus('removed');
setConsoleToNewLine();
}
if (input.command === 'images') {
term.write(dockerImages());
setConsoleToNewLine();
}
if (input.command === 'ps') {
term.write(dockerContainers());
setConsoleToNewLine();
}
if (input.command === 'container' && input.name === 'prune') {
if (isWaitingForResponse) {
for (const dockerImage of containersArr.filter((container)=> container.status === 'exited')) {
term.write("\r\n");
term.write(dockerImage.id);
dockerImage.setStatus('removed');
}
isWaitingForResponse = false
setConsoleToNewLine();
} else {
isWaitingForResponse = true
term.write("WARNING! This will remove all stopped containers.\r\n" +
"Are you sure you want to continue? [y/N]");
}
}
if (input.command === 'run') {
const img = imagesArr.find((image)=> image.name === input.name)
if (img) {
await img.runImage()
} else {
setConsoleToNewLine()
}
}
if (input.command === 'pull') {
const img = imagesArr.find((image)=> image.name === input.name)
if (img) {
img.pull()
} else {
setConsoleToNewLine()
}
}
}