protected ProtocolMetaData doDeploy(Archive<?> archive) throws DeploymentException { List<String> command = new ArrayList<>(); command.add("gcloud"); if (configuration.isDebug()) { command.add("--verbosity"); command.add("debug"); } command.add("preview"); command.add("app"); command.add("run"); command.add(getAppLocation().getPath()); log.info("GCloud command: " + command); try { DockerContainer.removeAll(); } catch (Exception e) { throw new DeploymentException("Cannot remove all previous Docker containers.", e); } ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); try { process = builder.start(); } catch (IOException e) { throw new IllegalStateException("Error running gcloud!", e); } Thread streamThread = new Thread( new Runnable() { public void run() { try { try (InputStream ps = process.getInputStream()) { int x; while ((x = ps.read()) != -1) { System.out.write(x); } } } catch (IOException ignored) { } } }); streamThread.start(); String host = configuration.getHost(); int port = readPort(); String serverUrl = "http://" + host + ":" + port + "/_ah/health"; try { delayArchiveDeploy( serverUrl, configuration.getStartupTimeout(), 2000L, new GCloudURLChecker()); } catch (Exception e) { throw new DeploymentException("Error delaying archive deployment.", e); } return getProtocolMetaData(host, port, DEFAULT); }
protected File export(Archive<?> archive) throws Exception { if (archive instanceof WebArchive == false) { throw new IllegalArgumentException("Can only handle .war deployments: " + archive); } Node dockerFile = archive.get("Dockerfile"); if (dockerFile == null) { if (configuration.getFrom() == null) { throw new IllegalArgumentException("Missing Docker's FROM value!"); } log.info("Using Docker FROM: " + configuration.getFrom()); String content = "FROM " + configuration.getFrom() + "\n" + "ADD . /app" + "\n"; archive.add(new StringAsset(content), "Dockerfile"); } return super.export(archive); }
public void setup(AppEngineGCloudConfiguration configuration) { log.info("Docker host: " + configuration.getHost()); // test host this.configuration = configuration; }