Home > Blockchain >  container to pipe to an executable and out again
container to pipe to an executable and out again

Time:07-06

I need a Docker image which contains a Linux executable where I can pipe an input file into when running it like this:

docker run --rm -i myContainer < myInputFile > myOutputFile

In my case it is the executable cucumber-json-formatter-linux-386 which converts NDJSON Cucumber messages into a JSON file (to be used e.g. for Xray).

Why Docker?

  • There is also a Windows executable available, but our security software says it contains a virus.
  • So I can’t download it, but to be honest, I also don’t trust it.
  • I need something something OS indepedent, also running in CI, etc.

Why convert?

Cucumber can output JSON directly. But I am using @badeball/cypress-cucumber-preprocessor which only can output NDJSON and needs me to use that binary to convert it into JSON. @badeball wrote “I've refactored my implementation to output messages, because that was significantly easier implementation wise”. So it’s not Cucumber writing those NDJSON messages here.

CodePudding user response:

Assuming you already have installed Docker, create a folder containing the following file called “Dockerfile”:

FROM ubuntu
COPY cucumber-json-formatter-linux-386 /bin/formatter
ENTRYPOINT /bin/formatter

Also copy the binary (cucumber-json-formatter-linux-386) into the same folder.

Then cd into that folder and build the container like this:

docker build -t cucumber-json-formatter .

Now you can run the container like this:

docker run --rm -i cucumber-json-formatter < input.ndjson > output.json
  • The argument --rm removes the container after usage.
  • The argument -i is needed to correctly process the input (not sure why, though).

I tried this on a Windows host, but should work the same on Linux.

CodePudding user response:

Nice to see that you figured out a simple solution by yourself.

As part of the cucumber team, I would like to ask: why do you need the cucumber-json-formatter? I understood that you need it to convert NDJSON messages into the "legacy" JSON format.

What don't you generate the JSON directly from cucumber itself?

I know, at some point we have deprecated the JSON formatter. But it is not the case anymore, you will be able to rely on it in future version, as usual

  • Related