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

Commit

Permalink
add improvements for the containers plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Feb 24, 2019
1 parent c514017 commit ee5e9b5
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 35 deletions.
2 changes: 1 addition & 1 deletion dockerfiles/theia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RUN adduser --disabled-password -S -u 1001 -G root -h ${HOME} -s /bin/sh theia \
# Download yeoman generator plug-in
&& 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 \
&& 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 \
&& 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 \
&& 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 \
&& for f in "${HOME}" "/etc/passwd" "/etc/group /node_modules /default-theia-plugins /projects"; do\
sudo chgrp -R 0 ${f} && \
sudo chmod -R g+rwX ${f}; \
Expand Down
20 changes: 20 additions & 0 deletions plugins/containers-plugin/src/containers-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export interface IContainer {
url?: string;
}
};
env?: { [key: string]: string; },
volumes?: {
[key: string]: {
path?: string;
};
},
commands?: string[]
}

const MAX_FAILED_ATTEMPTS = 5;
Expand Down Expand Up @@ -50,6 +57,19 @@ export class ContainersService {
status: machine.status,
isDev: devMachines[name] !== undefined
};
if (devMachines[name]) {
container.volumes = devMachines[name].volumes;
container.env = devMachines[name].env;
}
if (workspace!.config!.commands) {
container.commands = [];
workspace!.config!.commands.forEach(command => {
if (command.attributes && command.attributes.machineName && command.attributes.machineName !== name) {
return;
}
container.commands.push(command.name);
});
}
if (machine && machine.servers) {
container.servers = {};
Object.keys(machine.servers).forEach((serverName: string) => {
Expand Down
139 changes: 105 additions & 34 deletions plugins/containers-plugin/src/containers-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,42 +89,113 @@ export class ContainersTreeDataProvider implements theia.TreeDataProvider<ITreeN
tooltip: `open a new terminal for ${container.name}`,
command: { id: 'terminal-in-specific-container:new', arguments: [container.name] }
});
const servers = container.servers;
if (!servers) {
return;
const serverKeys = container.servers ? Object.keys(container.servers) : [];
if (serverKeys.length) {
const endpointsId = this.getRandId();
this.treeNodeItems.push({
id: endpointsId,
parentId: treeItem.id,
name: 'endpoints',
tooltip: 'endpoints',
isExpanded: true
});
serverKeys.forEach((serverName: string) => {
const server = container.servers[serverName];
if (!server) {
return;
}
const treeNodeItem: ITreeNodeItem = {
id: this.getRandId(),
parentId: endpointsId,
name: serverName,
iconPath: 'fa-info-circle medium-blue',
tooltip: server.url ? server.url : 'endpoint'
};
if (server.url && server.url.startsWith('http')) {
treeNodeItem.name = serverName;
treeNodeItem.iconPath = 'fa-share medium-blue';
treeNodeItem.command = { id: 'theia.open', arguments: [server.url] };
treeNodeItem.tooltip = 'open in a new tab ' + treeNodeItem.tooltip;
}
this.treeNodeItems.push(treeNodeItem);
});
}
const serverKeys = Object.keys(servers);
if (!serverKeys.length) {
return;
const envKeys = container.env ? Object.keys(container.env) : [];
if (envKeys.length) {
const envsId = this.getRandId();
this.treeNodeItems.push({
id: envsId,
parentId: treeItem.id,
name: 'env',
tooltip: 'environment variables',
isExpanded: false
});
envKeys.forEach((envName: string) => {
this.treeNodeItems.push({
id: this.getRandId(),
parentId: envsId,
name: `${envName} : ${container.env[envName]}`,
tooltip: `environment variable ${envName}`,
iconPath: 'fa-info-circle medium-blue'
});
});
}
const volumesKeys = container.volumes ? Object.keys(container.volumes) : [];
if (volumesKeys.length) {
const volumesId = this.getRandId();
this.treeNodeItems.push({
id: volumesId,
parentId: treeItem.id,
name: 'volumes',
tooltip: 'volumes',
isExpanded: false
});
volumesKeys.forEach((volumeName: string) => {
const volume: {
[paramRef: string]: string;
} = container.volumes[volumeName];
if (!volume) {
return;
}
const volumeId = this.getRandId();
this.treeNodeItems.push({
id: volumeId,
parentId: volumesId,
name: volumeName,
tooltip: 'volume name',
isExpanded: true
});
Object.keys(volume).forEach((key: string) => {
this.treeNodeItems.push({
id: this.getRandId(),
parentId: volumeId,
name: `${key} : ${volume[key]}`,
tooltip: `volume ${volumeName}`,
iconPath: 'fa-info-circle medium-blue'
});
});
});
}
if (container.commands && container.commands.length) {
const commandsId = this.getRandId();
this.treeNodeItems.push({
id: commandsId,
parentId: treeItem.id,
name: 'commands',
tooltip: 'commands',
isExpanded: false
});
container.commands.forEach((commandName: string) => {
this.treeNodeItems.push({
id: this.getRandId(),
parentId: commandsId,
name: commandName,
tooltip: 'execute the command',
iconPath: 'fa-terminal medium-yellow',
command: { id: 'task:run', arguments: ['che', commandName] }
});
});
}
const endpointsId = this.getRandId();
this.treeNodeItems.push({
id: endpointsId,
parentId: treeItem.id,
name: 'endpoints',
tooltip: 'endpoints',
isExpanded: true
});
serverKeys.forEach((serverName: string) => {
const server = servers[serverName];
if (!server) {
return;
}
const treeNodeItem: ITreeNodeItem = {
id: this.getRandId(),
parentId: endpointsId,
name: serverName,
iconPath: 'fa-info-circle medium-blue',
tooltip: server.url ? server.url : 'endpoint'
};
if (server.url && server.url.startsWith('http')) {
treeNodeItem.name = serverName;
treeNodeItem.iconPath = 'fa-share medium-blue';
treeNodeItem.command = { id: 'theia.open', arguments: [server.url] };
treeNodeItem.tooltip = 'open in a new tab ' + treeNodeItem.tooltip;
}
this.treeNodeItems.push(treeNodeItem);
});
});
if (hasPlugin) {
this.treeNodeItems.push(pluginsDir);
Expand Down

0 comments on commit ee5e9b5

Please sign in to comment.