Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8517049

Browse files
authored
Merge pull request #127 from mnottale/intellij-plugin
intellij plugin.
2 parents afb263f + e2066d0 commit 8517049

File tree

13 files changed

+808
-0
lines changed

13 files changed

+808
-0
lines changed

plugins/intellij/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Docker Application plugin for intellij IDEA
2+
3+
This directory contains the sources of a Docker Application plugin for Intellij IDEA.
4+
5+
The plugin creates a new top-level `Docker` menu populated with commands to manipulate Docker applications.
6+
7+
# Building the plugin
8+
9+
Simply run `gradle build` in the plugins/intellij directory. This will create a jar with the plugin binary in the `build/lib` directory.
10+
11+
# Installing the plugin
12+
13+
Follow instructions here: https://www.jetbrains.com/help/idea/installing-plugin-from-disk.html
14+
15+
# Using the plugin
16+
17+
The plugin exposes the following commands in a top-level `Docker` menu:
18+
19+
## New application
20+
21+
This command displays a dialog that can be used to initialize a new Docker Application.
22+
23+
It gives you the option to chose the name, description and maintainers of the application, as well as whether to use single-file mode or not.
24+
25+
26+
## Select application
27+
28+
By default all operations will look for a single Docker Application at the root of the project directory. If your application is located elswhere, or if you have multiple applications, you can use the `select application` menu to select which application will be used.
29+
30+
## Render
31+
32+
`Render` simply renders the application in a popup window.
33+
34+
## Settings
35+
36+
`Settings` pops-up a dialog that can be used to configure deployment parameters, such as which orchestrator to use, the stack name and namespace, and settings overrides.
37+
38+
## Deploy
39+
40+
`Deploy` deploys your application to a cluster. Progress or eventual errors are displayed in the event log.
41+

plugins/intellij/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id 'java'
3+
id 'org.jetbrains.intellij' version '0.3.1'
4+
}
5+
6+
group 'com.docker'
7+
version '1.0-SNAPSHOT'
8+
9+
sourceCompatibility = 1.8
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
testCompile group: 'junit', name: 'junit', version: '4.12'
17+
}
18+
19+
intellij {
20+
version '2018.1.3'
21+
}
22+
patchPluginXml {
23+
changeNotes """
24+
Add change notes here.<br>
25+
<em>most HTML tags may be used</em>"""
26+
}

plugins/intellij/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'dockerapp-plugin'
2+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import com.intellij.notification.Notification;
2+
import com.intellij.notification.Notifications;
3+
import com.intellij.notification.NotificationType;
4+
import com.intellij.openapi.actionSystem.*;
5+
import com.intellij.openapi.diagnostic.FrequentEventDetector;
6+
import com.intellij.openapi.diagnostic.Logger;
7+
import com.intellij.openapi.project.Project;
8+
import com.intellij.openapi.ui.Messages;
9+
import com.intellij.ide.util.PropertiesComponent;
10+
import org.apache.log4j.Level;
11+
12+
import java.io.BufferedReader;
13+
import java.io.File;
14+
import java.io.InputStreamReader;
15+
import java.util.Scanner;
16+
17+
18+
public class DeployApp extends AnAction {
19+
public DeployApp() {
20+
super("DeployApp");
21+
}
22+
23+
public void actionPerformed(AnActionEvent event) {
24+
Project project = event.getProject();
25+
PropertiesComponent pc = PropertiesComponent.getInstance(project);
26+
String appPath = pc.getValue("docker_app_path");
27+
try {
28+
String orchestrator = "swarm";
29+
if (pc.getValue("docker_app_orchestrator").equals("kubernetes"))
30+
orchestrator = "kubernetes";
31+
String rawSettings = pc.getValue("docker_app_overrides");
32+
String settings = "";
33+
if (!rawSettings.isEmpty()) {
34+
String[] split = rawSettings.split("\n");
35+
for (String l: split) {
36+
settings += " -s " + l;
37+
}
38+
}
39+
String kubeconfig = pc.getValue("docker_app_kubeconfig");
40+
if (!kubeconfig.isEmpty()) {
41+
kubeconfig = " --kubeconfig " + kubeconfig;
42+
}
43+
String namespace = pc.getValue("docker_app_namespace");
44+
if (!namespace.isEmpty()) {
45+
namespace = " --namespace " + namespace;
46+
}
47+
String name = pc.getValue("docker_app_name");
48+
if (!name.isEmpty()) {
49+
name = " --name " + name;
50+
}
51+
String cmd = "docker-app deploy " + appPath
52+
+ " --orchestrator="+orchestrator
53+
+ kubeconfig
54+
+ namespace
55+
+ name
56+
+ settings;
57+
Process p = Runtime.getRuntime().exec(cmd,null, new File(project.getBasePath()));
58+
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
59+
String line;
60+
while ((line = input.readLine()) != null) {
61+
Notification n = new Notification("docker-app", "deploy", line, NotificationType.INFORMATION);
62+
Notifications.Bus.notify(n);
63+
}
64+
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
65+
while ((line = error.readLine()) != null) {
66+
Notification n = new Notification("docker-app", "deploy", line, NotificationType.ERROR);
67+
Notifications.Bus.notify(n);
68+
}
69+
} catch (Exception e) {
70+
Messages.showMessageDialog(project, "docker-app invocation failed with " + e.toString(), "Render Failure", Messages.getInformationIcon());
71+
e.printStackTrace();
72+
}
73+
74+
}
75+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import com.intellij.notification.Notification;
2+
import com.intellij.notification.Notifications;
3+
import com.intellij.notification.NotificationType;
4+
import com.intellij.openapi.actionSystem.*;
5+
import com.intellij.openapi.project.Project;
6+
import com.intellij.openapi.ui.Messages;
7+
import com.intellij.ide.util.PropertiesComponent;
8+
import java.util.Vector;
9+
import java.util.Arrays;
10+
import java.io.BufferedReader;
11+
import java.io.File;
12+
import java.io.InputStreamReader;
13+
14+
15+
public class InitApp extends AnAction {
16+
public InitApp() {
17+
super("InitApp");
18+
}
19+
public void actionPerformed(AnActionEvent event) {
20+
Project project = event.getProject();
21+
InitDialog id = new InitDialog();
22+
id.pack();
23+
id.setVisible(true);
24+
if (!id.wasValidated()) {
25+
return;
26+
}
27+
InitDialog.Result r = id.result();
28+
Vector<String> cmd = new Vector<String>();
29+
cmd.add("docker-app");
30+
cmd.add("init");
31+
cmd.add(r.name);
32+
if (r.singleFile) {
33+
cmd.add("-s");
34+
}
35+
if (!r.description.isEmpty()) {
36+
cmd.add("-d");
37+
cmd.add(r.description);
38+
}
39+
if (!r.maintainers.isEmpty()) {
40+
String[] mts = r.maintainers.split("\n");
41+
for (String m: mts) {
42+
if (!m.isEmpty()) {
43+
cmd.add("-m");
44+
cmd.add(m);
45+
}
46+
}
47+
}
48+
Notification no = new Notification("docker-app", "init", cmd.toString(), NotificationType.INFORMATION);
49+
Notifications.Bus.notify(no);
50+
try {
51+
String[] scmd = Arrays.copyOf(cmd.toArray(), cmd.size(), String[].class);
52+
Process p = Runtime.getRuntime().exec(scmd, null, new File(project.getBasePath()));
53+
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
54+
String line;
55+
while ((line = input.readLine()) != null) {
56+
Notification n = new Notification("docker-app", "init", line, NotificationType.INFORMATION);
57+
Notifications.Bus.notify(n);
58+
}
59+
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
60+
while ((line = error.readLine()) != null) {
61+
Notification n = new Notification("docker-app", "init", line, NotificationType.ERROR);
62+
Notifications.Bus.notify(n);
63+
}
64+
p.wait();
65+
String msg = "Application successfuly created.";
66+
if (p.exitValue()!=0) {
67+
msg = "Application creation failed, check event log for more informations.";
68+
}
69+
Messages.showMessageDialog(project, msg, "Application creation result", Messages.getInformationIcon());
70+
71+
} catch (Exception e) {
72+
Messages.showMessageDialog(project, "docker-app invocation failed with " + e.toString(), "Render Failure", Messages.getInformationIcon());
73+
e.printStackTrace();
74+
}
75+
}
76+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="InitDialog">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="54" width="452" height="251"/>
7+
</constraints>
8+
<properties/>
9+
<border type="none"/>
10+
<children>
11+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
12+
<margin top="0" left="0" bottom="0" right="0"/>
13+
<constraints>
14+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
15+
</constraints>
16+
<properties/>
17+
<border type="none"/>
18+
<children>
19+
<hspacer id="98af6">
20+
<constraints>
21+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
22+
</constraints>
23+
</hspacer>
24+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
25+
<margin top="0" left="0" bottom="0" right="0"/>
26+
<constraints>
27+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
28+
</constraints>
29+
<properties/>
30+
<border type="none"/>
31+
<children>
32+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
33+
<constraints>
34+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
35+
</constraints>
36+
<properties>
37+
<text value="OK"/>
38+
</properties>
39+
</component>
40+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
41+
<constraints>
42+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
43+
</constraints>
44+
<properties>
45+
<text value="Cancel"/>
46+
</properties>
47+
</component>
48+
</children>
49+
</grid>
50+
</children>
51+
</grid>
52+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
53+
<margin top="0" left="0" bottom="0" right="0"/>
54+
<constraints>
55+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
56+
</constraints>
57+
<properties/>
58+
<border type="none"/>
59+
<children>
60+
<component id="153fb" class="javax.swing.JLabel">
61+
<constraints>
62+
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
63+
</constraints>
64+
<properties>
65+
<text value="Name"/>
66+
</properties>
67+
</component>
68+
<component id="953aa" class="javax.swing.JTextField" binding="tName">
69+
<constraints>
70+
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
71+
<preferred-size width="150" height="-1"/>
72+
</grid>
73+
</constraints>
74+
<properties/>
75+
</component>
76+
<component id="9f991" class="javax.swing.JLabel">
77+
<constraints>
78+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
79+
</constraints>
80+
<properties>
81+
<text value="Description"/>
82+
</properties>
83+
</component>
84+
<component id="9f455" class="javax.swing.JTextField" binding="tDescription">
85+
<constraints>
86+
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
87+
<preferred-size width="150" height="-1"/>
88+
</grid>
89+
</constraints>
90+
<properties/>
91+
</component>
92+
<component id="525df" class="javax.swing.JLabel">
93+
<constraints>
94+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
95+
</constraints>
96+
<properties>
97+
<text value="Maintainers"/>
98+
</properties>
99+
</component>
100+
<component id="c5844" class="javax.swing.JTextArea" binding="tMaintainers">
101+
<constraints>
102+
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
103+
<preferred-size width="150" height="50"/>
104+
</grid>
105+
</constraints>
106+
<properties>
107+
<toolTipText value="List of maintainers, in format 'name:email'"/>
108+
</properties>
109+
</component>
110+
<component id="47d49" class="javax.swing.JCheckBox" binding="cSingleFile">
111+
<constraints>
112+
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
113+
</constraints>
114+
<properties>
115+
<text value="single file"/>
116+
</properties>
117+
</component>
118+
</children>
119+
</grid>
120+
</children>
121+
</grid>
122+
</form>

0 commit comments

Comments
 (0)