Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Output key/value Dockerfile commands like ENV correctly #12

Merged
merged 2 commits into from Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/index.ts
Expand Up @@ -102,6 +102,11 @@ const argsToString = (

if (_.isArray(args)) {
return '["' + (args as string[]).join('","') + '"]';
} else if (_.isObject(args)) {
return _.map(args, (value, key) => {
let escapedValue = JSON.stringify(value);
return `${key}=${escapedValue}`
}).join(' ');
} else {
return args as string;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.ts
Expand Up @@ -52,12 +52,16 @@ describe('Transpose a Dockerfile', () => {
const dockerfile = `
FROM ubuntu
COPY my-file my-container-file
ENV myvar multi word value with a "
LABEL version=1.0
RUN apt-get install something
RUN ["ls", "-al"]
`

const expectedOutput = `FROM ubuntu
COPY ["my-file","my-container-file"]
ENV myvar="multi word value with a \\""
LABEL version="1.0"
COPY ["${opts.hostQemuPath}","${opts.containerQemuPath}"]
RUN ["${opts.containerQemuPath}","-execve","/bin/sh","-c","apt-get install something"]
RUN ["${opts.containerQemuPath}","-execve","/bin/sh","-c","ls -al"]
Expand Down