|
| 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 | + if (appPath == null || appPath.equals("")) { |
| 28 | + appPath = ""; // project.getBasePath(); |
| 29 | + } |
| 30 | + try { |
| 31 | + String orchestrator = "swarm"; |
| 32 | + if (pc.getValue("docker_app_orchestrator").equals("kubernetes")) |
| 33 | + orchestrator = "kubernetes"; |
| 34 | + String rawSettings = pc.getValue("docker_app_overrides"); |
| 35 | + String settings = ""; |
| 36 | + if (!rawSettings.isEmpty()) { |
| 37 | + String[] split = rawSettings.split("\n"); |
| 38 | + for (String l: split) { |
| 39 | + settings += " -s " + l; |
| 40 | + } |
| 41 | + } |
| 42 | + String kubeconfig = pc.getValue("docker_app_kubeconfig"); |
| 43 | + if (!kubeconfig.isEmpty()) { |
| 44 | + kubeconfig = " --kubeconfig " + kubeconfig; |
| 45 | + } |
| 46 | + String namespace = pc.getValue("docker_app_namespace"); |
| 47 | + if (!namespace.isEmpty()) { |
| 48 | + namespace = " --namespace " + namespace; |
| 49 | + } |
| 50 | + String name = pc.getValue("docker_app_name"); |
| 51 | + if (!name.isEmpty()) { |
| 52 | + name = " --name " + name; |
| 53 | + } |
| 54 | + String cmd = "docker-app deploy " + appPath |
| 55 | + + " --orchestrator="+orchestrator |
| 56 | + + kubeconfig |
| 57 | + + namespace |
| 58 | + + name |
| 59 | + + settings; |
| 60 | + Process p = Runtime.getRuntime().exec(cmd,null, new File(project.getBasePath())); |
| 61 | + /*Logger l = Logger.getInstance("docker-app"); |
| 62 | + l.setLevel(Level.INFO); |
| 63 | + l.info("Running deploy command: " + cmd);*/ |
| 64 | + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); |
| 65 | + String line; |
| 66 | + while ((line = input.readLine()) != null) { |
| 67 | + Notification n = new Notification("docker-app", "deploy", line, NotificationType.INFORMATION); |
| 68 | + Notifications.Bus.notify(n); |
| 69 | + //l.info(line); |
| 70 | + } |
| 71 | + BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream())); |
| 72 | + while ((line = error.readLine()) != null) { |
| 73 | + Notification n = new Notification("docker-app", "deploy", line, NotificationType.ERROR); |
| 74 | + Notifications.Bus.notify(n); |
| 75 | + //l.warn(line); |
| 76 | + } |
| 77 | + } catch (Exception e) { |
| 78 | + Messages.showMessageDialog(project, "docker-app invocation failed with " + e.toString(), "Render Failure", Messages.getInformationIcon()); |
| 79 | + e.printStackTrace(); |
| 80 | + } |
| 81 | + |
| 82 | + } |
| 83 | +} |
0 commit comments