Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit ee5e9b5

Browse files
committed
add improvements for the containers plugin
Signed-off-by: Oleksii Orel <[email protected]>
1 parent c514017 commit ee5e9b5

File tree

3 files changed

+126
-35
lines changed

3 files changed

+126
-35
lines changed

dockerfiles/theia/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ RUN adduser --disabled-password -S -u 1001 -G root -h ${HOME} -s /bin/sh theia \
113113
# Download yeoman generator plug-in
114114
&& curl -L -o /default-theia-plugins/theia_yeoman_plugin.theia https://github.com/eclipse/theia-yeoman-plugin/releases/download/untagged-04f28ee329e479cc465b/theia_yeoman_plugin.theia \
115115
&& curl -L -o /default-theia-plugins/eclipse_che_theia_factory_plugin.theia https://github.com/eclipse/che-theia/releases/download/0.0.1/eclipse_che_theia_factory_plugin.theia \
116-
&& curl -L -o /default-theia-plugins/eclipse_che_theia_containers_plugin.theia https://github.com/eclipse/che-theia/releases/download/0.0.1/eclipse_che_theia_containers_plugin.theia \
116+
&& curl -L -o /default-theia-plugins/eclipse_che_theia_containers_plugin.theia https://github.com/eclipse/che-theia/releases/download/0.0.2/eclipse_che_theia_containers_plugin.theia \
117117
&& for f in "${HOME}" "/etc/passwd" "/etc/group /node_modules /default-theia-plugins /projects"; do\
118118
sudo chgrp -R 0 ${f} && \
119119
sudo chmod -R g+rwX ${f}; \

plugins/containers-plugin/src/containers-service.ts

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ export interface IContainer {
1919
url?: string;
2020
}
2121
};
22+
env?: { [key: string]: string; },
23+
volumes?: {
24+
[key: string]: {
25+
path?: string;
26+
};
27+
},
28+
commands?: string[]
2229
}
2330

2431
const MAX_FAILED_ATTEMPTS = 5;
@@ -50,6 +57,19 @@ export class ContainersService {
5057
status: machine.status,
5158
isDev: devMachines[name] !== undefined
5259
};
60+
if (devMachines[name]) {
61+
container.volumes = devMachines[name].volumes;
62+
container.env = devMachines[name].env;
63+
}
64+
if (workspace!.config!.commands) {
65+
container.commands = [];
66+
workspace!.config!.commands.forEach(command => {
67+
if (command.attributes && command.attributes.machineName && command.attributes.machineName !== name) {
68+
return;
69+
}
70+
container.commands.push(command.name);
71+
});
72+
}
5373
if (machine && machine.servers) {
5474
container.servers = {};
5575
Object.keys(machine.servers).forEach((serverName: string) => {

plugins/containers-plugin/src/containers-tree-data-provider.ts

+105-34
Original file line numberDiff line numberDiff line change
@@ -89,42 +89,113 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
8989
tooltip: `open a new terminal for ${container.name}`,
9090
command: { id: 'terminal-in-specific-container:new', arguments: [container.name] }
9191
});
92-
const servers = container.servers;
93-
if (!servers) {
94-
return;
92+
const serverKeys = container.servers ? Object.keys(container.servers) : [];
93+
if (serverKeys.length) {
94+
const endpointsId = this.getRandId();
95+
this.treeNodeItems.push({
96+
id: endpointsId,
97+
parentId: treeItem.id,
98+
name: 'endpoints',
99+
tooltip: 'endpoints',
100+
isExpanded: true
101+
});
102+
serverKeys.forEach((serverName: string) => {
103+
const server = container.servers[serverName];
104+
if (!server) {
105+
return;
106+
}
107+
const treeNodeItem: ITreeNodeItem = {
108+
id: this.getRandId(),
109+
parentId: endpointsId,
110+
name: serverName,
111+
iconPath: 'fa-info-circle medium-blue',
112+
tooltip: server.url ? server.url : 'endpoint'
113+
};
114+
if (server.url && server.url.startsWith('http')) {
115+
treeNodeItem.name = serverName;
116+
treeNodeItem.iconPath = 'fa-share medium-blue';
117+
treeNodeItem.command = { id: 'theia.open', arguments: [server.url] };
118+
treeNodeItem.tooltip = 'open in a new tab ' + treeNodeItem.tooltip;
119+
}
120+
this.treeNodeItems.push(treeNodeItem);
121+
});
95122
}
96-
const serverKeys = Object.keys(servers);
97-
if (!serverKeys.length) {
98-
return;
123+
const envKeys = container.env ? Object.keys(container.env) : [];
124+
if (envKeys.length) {
125+
const envsId = this.getRandId();
126+
this.treeNodeItems.push({
127+
id: envsId,
128+
parentId: treeItem.id,
129+
name: 'env',
130+
tooltip: 'environment variables',
131+
isExpanded: false
132+
});
133+
envKeys.forEach((envName: string) => {
134+
this.treeNodeItems.push({
135+
id: this.getRandId(),
136+
parentId: envsId,
137+
name: `${envName} : ${container.env[envName]}`,
138+
tooltip: `environment variable ${envName}`,
139+
iconPath: 'fa-info-circle medium-blue'
140+
});
141+
});
142+
}
143+
const volumesKeys = container.volumes ? Object.keys(container.volumes) : [];
144+
if (volumesKeys.length) {
145+
const volumesId = this.getRandId();
146+
this.treeNodeItems.push({
147+
id: volumesId,
148+
parentId: treeItem.id,
149+
name: 'volumes',
150+
tooltip: 'volumes',
151+
isExpanded: false
152+
});
153+
volumesKeys.forEach((volumeName: string) => {
154+
const volume: {
155+
[paramRef: string]: string;
156+
} = container.volumes[volumeName];
157+
if (!volume) {
158+
return;
159+
}
160+
const volumeId = this.getRandId();
161+
this.treeNodeItems.push({
162+
id: volumeId,
163+
parentId: volumesId,
164+
name: volumeName,
165+
tooltip: 'volume name',
166+
isExpanded: true
167+
});
168+
Object.keys(volume).forEach((key: string) => {
169+
this.treeNodeItems.push({
170+
id: this.getRandId(),
171+
parentId: volumeId,
172+
name: `${key} : ${volume[key]}`,
173+
tooltip: `volume ${volumeName}`,
174+
iconPath: 'fa-info-circle medium-blue'
175+
});
176+
});
177+
});
178+
}
179+
if (container.commands && container.commands.length) {
180+
const commandsId = this.getRandId();
181+
this.treeNodeItems.push({
182+
id: commandsId,
183+
parentId: treeItem.id,
184+
name: 'commands',
185+
tooltip: 'commands',
186+
isExpanded: false
187+
});
188+
container.commands.forEach((commandName: string) => {
189+
this.treeNodeItems.push({
190+
id: this.getRandId(),
191+
parentId: commandsId,
192+
name: commandName,
193+
tooltip: 'execute the command',
194+
iconPath: 'fa-terminal medium-yellow',
195+
command: { id: 'task:run', arguments: ['che', commandName] }
196+
});
197+
});
99198
}
100-
const endpointsId = this.getRandId();
101-
this.treeNodeItems.push({
102-
id: endpointsId,
103-
parentId: treeItem.id,
104-
name: 'endpoints',
105-
tooltip: 'endpoints',
106-
isExpanded: true
107-
});
108-
serverKeys.forEach((serverName: string) => {
109-
const server = servers[serverName];
110-
if (!server) {
111-
return;
112-
}
113-
const treeNodeItem: ITreeNodeItem = {
114-
id: this.getRandId(),
115-
parentId: endpointsId,
116-
name: serverName,
117-
iconPath: 'fa-info-circle medium-blue',
118-
tooltip: server.url ? server.url : 'endpoint'
119-
};
120-
if (server.url && server.url.startsWith('http')) {
121-
treeNodeItem.name = serverName;
122-
treeNodeItem.iconPath = 'fa-share medium-blue';
123-
treeNodeItem.command = { id: 'theia.open', arguments: [server.url] };
124-
treeNodeItem.tooltip = 'open in a new tab ' + treeNodeItem.tooltip;
125-
}
126-
this.treeNodeItems.push(treeNodeItem);
127-
});
128199
});
129200
if (hasPlugin) {
130201
this.treeNodeItems.push(pluginsDir);

0 commit comments

Comments
 (0)