Screenshotter: Obey --katex/selenium-ip options under --container. (#566)

Some Docker configs, such as Docker for Mac, need explicit --katex-ip
and --selenium-ip options. Obey those options.
This commit is contained in:
Eddie Kohler
2016-11-22 05:23:32 -05:00
committed by Martin von Gagern
parent 22957d40f6
commit 7b5580b1fa

View File

@@ -50,7 +50,6 @@ var opts = require("nomnom")
}) })
.option("katexIP", { .option("katexIP", {
full: "katex-ip", full: "katex-ip",
"default": "localhost",
help: "Full URL of the KaTeX development server", help: "Full URL of the KaTeX development server",
}) })
.option("katexPort", { .option("katexPort", {
@@ -116,29 +115,33 @@ function cmd() {
function guessDockerIPs() { function guessDockerIPs() {
if (process.env.DOCKER_MACHINE_NAME) { if (process.env.DOCKER_MACHINE_NAME) {
var machine = process.env.DOCKER_MACHINE_NAME; var machine = process.env.DOCKER_MACHINE_NAME;
seleniumIP = cmd("docker-machine", "ip", machine); seleniumIP = seleniumIP || cmd("docker-machine", "ip", machine);
katexIP = cmd("docker-machine", "ssh", machine, katexIP = katexIP || cmd("docker-machine", "ssh", machine,
"echo ${SSH_CONNECTION%% *}"); "echo ${SSH_CONNECTION%% *}");
return; return;
} }
try { try {
// When using boot2docker, seleniumIP and katexIP are distinct. // When using boot2docker, seleniumIP and katexIP are distinct.
seleniumIP = cmd("boot2docker", "ip"); seleniumIP = seleniumIP || cmd("boot2docker", "ip");
var config = cmd("boot2docker", "config"); var config = cmd("boot2docker", "config");
config = (/^HostIP = "(.*)"$/m).exec(config); config = (/^HostIP = "(.*)"$/m).exec(config);
if (!config) { if (!config) {
console.error("Failed to find HostIP"); console.error("Failed to find HostIP");
process.exit(2); process.exit(2);
} }
katexIP = config[1]; katexIP = katexIP || config[1];
} catch (e) { } catch (e) {
seleniumIP = katexIP = cmd("docker", "inspect", var ip = cmd("docker", "inspect",
"-f", "{{.NetworkSettings.Gateway}}", opts.container); "-f", "{{.NetworkSettings.Gateway}}", opts.container);
seleniumIP = seleniumIP || ip;
katexIP = katexIP || ip;
} }
} }
if (!seleniumURL && opts.container) { if (!seleniumURL && opts.container) {
guessDockerIPs(); if (!seleniumIP || !katexIP) {
guessDockerIPs();
}
seleniumPort = cmd("docker", "port", opts.container, seleniumPort); seleniumPort = cmd("docker", "port", opts.container, seleniumPort);
seleniumPort = seleniumPort.replace(/^.*:/, ""); seleniumPort = seleniumPort.replace(/^.*:/, "");
} }
@@ -189,6 +192,9 @@ function startServer() {
// Wait for container to become ready // Wait for container to become ready
function tryConnect() { function tryConnect() {
if (!katexIP) {
katexIP = "localhost";
}
if (!katexURL) { if (!katexURL) {
katexURL = "http://" + katexIP + ":" + katexPort + "/"; katexURL = "http://" + katexIP + ":" + katexPort + "/";
console.log("KaTeX URL is " + katexURL); console.log("KaTeX URL is " + katexURL);