Skip to content

Commit

Permalink
fix some docker only issues
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskiesel committed Apr 11, 2022
1 parent 73d346e commit 0593950
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ docker run -it --rm \
- The `<input-directory>` line can be omitted to not set `--input` or when the config is set by `--input "{...}"` in the `<parameters>`
- `<parameters>` are additional options; see `docker run -it --rm ghcr.io/webis-de/scriptor:latest --help`

**Chaining**
[Chaining](#chaining) can also be used without NodeJS. However, the Docker container does exit after a single run (by design). Use the same command to continue the chain.

3 changes: 2 additions & 1 deletion bin/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const log = require('../lib/log.js');

const dockerEntrypoint = true;
const options = cli.parse(dockerEntrypoint);
log.info({ options: options }, "entrypoint");

try {
const scriptDirectory = cli.getScriptDirectory(options);
const inputDirectory = cli.getInputDirectory(options, dockerEntrypoint);
const outputDirectory = cli.getOutputDirectory(options);
const inputDirectory = cli.getInputDirectory(options, dockerEntrypoint);
const runOptions = cli.getRunOptions(options);

scripts
Expand Down
26 changes: 14 additions & 12 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Static command line interface functions

const chmodr = require('chmodr');
const commander = require('commander');
const fs = require("fs-extra");
const os = require("os");
Expand Down Expand Up @@ -361,20 +362,21 @@ const getOutputDirectory = function(options) {
outputDirectory = chain.getChainOutputDirectory(chainName, outputDirectory);
}

if (options.overwriteOutput) {
fs.rmSync(outputDirectory, { recursive: true, force: true });
fs.mkdirSync(outputDirectory, { recursive: true });
} else {
fs.mkdirSync(outputDirectory, { recursive: true });
if (!fs.statSync(outputDirectory).isDirectory()) {
throw new Error(
"output directory '" + outputDirectory + "' is not a directory.");
}
if (fs.readdirSync(outputDirectory).length > 1) { // may contain log file
throw new Error(
"output directory '" + outputDirectory + "' is not empty.");
if (options.overwriteOutput && fs.existsSync(outputDirectory)) {
chmodr.sync(outputDirectory, 0o666);
for (const child of fs.readdirSync(outputDirectory)) {
fs.rmSync(path.join(outputDirectory, child), { recursive: true, force: true });
}
}
fs.mkdirSync(outputDirectory, { recursive: true });
if (!fs.statSync(outputDirectory).isDirectory()) {
throw new Error(
"output directory '" + outputDirectory + "' is not a directory.");
}
if (fs.readdirSync(outputDirectory).length > 1) { // may contain log file
throw new Error(
"output directory '" + outputDirectory + "' is not empty.");
}
return outputDirectory;
};
module.exports.getOutputDirectory = getOutputDirectory;
Expand Down

0 comments on commit 0593950

Please sign in to comment.