Skip to content

Commit

Permalink
build: add dev:docker to gulp
Browse files Browse the repository at this point in the history
  • Loading branch information
apowers313 committed Oct 16, 2021
1 parent 0742692 commit a072e51
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
49 changes: 34 additions & 15 deletions assets/plop/plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ module.exports = function(plop) {
return archiveExperiment({push: true}, false);
},
});

plop.setGenerator("dev-docker", {
descrption: "launches docker for development",
prompts: [],
actions: function() {
let actions = [];

buildDocker(actions, `nhai-dev-image-${date.compactDate}`);
runDocker(actions, `nhai-dev-image-${date.compactDate}`, `nhai-dev-container-${date.compactDate}${date.timestamp}`);

return actions;
},
});
};

function createExperiment(answers) {
Expand Down Expand Up @@ -108,17 +121,10 @@ function createExperiment(answers) {
});

// build docker image
actions.push(async() => {
console.log("running build...");
await spawnAsync(`docker build --build-arg JUPYTER_FILE=./${newJupyterFile} --tag ${expConf.dockerImage} .`);
fs.rmSync(`./${newJupyterFile}`);
});
buildDocker(actions, expConf.dockerImage, newJupyterFile, true);

// run docker image
actions.push(async() => {
console.log("running image...");
return spawnAsync(`docker run -p 6379:6379 -p 8080:8080 -p 8888:8888 -it --name ${expConf.dockerContainer} ${expConf.dockerImage}`);
});
runDocker(actions, expConf.dockerImage, expConf.dockerContainer);

return actions;
}
Expand Down Expand Up @@ -164,11 +170,29 @@ function archiveExperiment(answers, deactivate = true) {
return actions;
}

function buildDocker(actions, imageName, jupyterFile = "test/integration/integration-test.ipynb", delJup = false) {
actions.push(async() => {
console.log("running build...");
await spawnAsync(`docker build --build-arg JUPYTER_FILE=./${jupyterFile} --tag ${imageName} .`);
if (delJup) {
fs.rmSync(`./${jupyterFile}`);
}
});
}

function runDocker(actions, imageName, containerName) {
actions.push(async() => {
console.log("running image...");
return spawnAsync(`docker run -p 6379:6379 -p 8080:8080 -p 8888:8888 -it --name ${containerName} ${imageName}`);
});
}

function saveConf() {
fs.writeFileSync(expConfFile, JSON.stringify(expConf, null, 4), {encoding: "utf8"});
}

function spawnAsync(str) {
console.log("Running command:", str);
let args = str.split(" ");
let cmd = args.shift();

Expand All @@ -180,12 +204,6 @@ function spawnAsync(str) {
stdio: "inherit",
};

// // XXX TODO -- this is for debugging only
// args.unshift(cmd);
// cmd = "echo";
console.log("CMD:", cmd);
console.log("ARGS:", args);

return new Promise((resolve, reject) => {
spawn(cmd, args, opts).on("close", (code) => {
if (code === 0) {
Expand Down Expand Up @@ -214,6 +232,7 @@ function getDate() {

d.dashDate = `${d.year}-${d.month}-${d.day}`;
d.compactDate = `${d.year}${d.month}${d.day}`;
d.timestamp = `${d.hour}${d.minute}${d.second}`;

return d;
}
Expand Down
8 changes: 8 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ async function integration(testReporter = "spec") {
}));
}

/* ************
* DEV DOCKER
**************/
async function devDocker() {
return doPlop("dev-docker");
}

module.exports = {
audit,
test,
Expand All @@ -216,6 +223,7 @@ module.exports = {
"dev:coverage": watchCoverage,
"dev:docs": watchDocs,
"dev:main": watchMain,
"dev:docker": devDocker,
experiment,
"exp": experiment,
"exp:run": experiment,
Expand Down

0 comments on commit a072e51

Please sign in to comment.