Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag-version-prefix=""
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ node_js:
- 5
- 6
- 6.5.0
- 8
- 10
script: "npm run-script test-w-coverage"
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
# Dockerfilejs
#### A simple Dockerfile generator. [Try it now!](https://tonicdev.com/npm/dockerfilejs)
```javascript
var Dockerfile = require("dockerfilejs").Dockerfile

var file = new Dockerfile()
var Dockerfile = require("dockerfilejs").Dockerfile;
var file = new Dockerfile();

file.comment('The above code example yields this file!')
.env({DEBUG:'express:* node index.js'})
.expose(8080)
.separator('\n')
.from({ image : 'node', tag : '4-onbuild'})
.comment('FROM gets bumped under initial comments')
.render()
.env({DEBUG:'express:* node index.js'})
.expose(8080)
.separator('\n')
.from({ image : 'node', tag : 'latest'})
.comment('FROM gets bumped under initial comments')
.render();
```

```Dockerfile
# The above code example yields this file!
FROM node:4-onbuild
FROM node:latest
ENV DEBUG="express:* node index.js"
EXPOSE [ 8080 ]
EXPOSE 8080
# FROM gets bumped under initial comments
```

Expand All @@ -33,7 +32,7 @@ file.env({
at : {
all: 'really!'
}
}}).render()
}}).render();
/*
ENV complex.objects="are not" \
complex.a=problem \
Expand All @@ -43,30 +42,33 @@ ENV complex.objects="are not" \

#### Made a mistake? Get rid of it!
```javascript
file.copy('~/.ssh/*', '/tmp')
file.copy('~/.ssh/*', '/tmp');
// oops!
file.steps().pop()
file.steps().pop();
```

#### Advanced examples
```javascript
file.label({ complex: { objects: 'allowed' } })
file.separator('\n')
// Will set the separator of each step for the entire file.render() output

file.label({ complex: { objects: 'allowed' } });
// LABEL complex.objects="allowed"

file.expose([8080, '8081', { number:443, protocol:'tcp' }])
// EXPOSE [ 8080, 8081, 443/tcp ]
file.expose([8080, '8081', { number: 443, protocol: 'tcp' }]);
// EXPOSE 8080 8081 443/tcp

file.run({command: ['touch /file.txt', ['echo', 'hello world', '>>', '/file.txt']]})
file.run({ command: ['touch /file.txt', ['echo', 'hello world', '>>', '/file.txt'] ] });
// RUN touch /file.txt \
// && echo "hello world" >> /file.txt

file.copy({ src : ['/id_rsa', '/id_rsa.pub'], dest: '/root/.ssh/' }, true)
file.copy({ src : ['/id_rsa', '/id_rsa.pub'], dest: '/root/.ssh/' }, true);
// ONBUILD COPY ["/id_rsa", "/id_rsa.pub", "/root/.ssh"]

file.cmd({executable: '/bin/bash', params: ['-c', 'hello world'] })
file.cmd({ executable: '/bin/bash', params: ['-c', 'hello world'] });
// CMD ["/bin/bash", "-c", "hello world"]

file.cmd({command:'/bin/bash', params: ['-c', 'hello world'] })
file.cmd({ command:'/bin/bash', params: ['-c', 'hello world'] })
// CMD /bin/bash -c "hello world"

file.healthCheck({
Expand All @@ -77,9 +79,9 @@ file.healthCheck({
// HEALTHCHECK --retries=4 --timeout=30s \
// CMD wget example.com

file.from({image: 'node', registry:'docker.io', tag:'4-onbuild'})
// FROM docker.io/node:4-onbuild
file.user('root');
// USER root

file.separator('\n')
// Will set the separator of each step for the entire file.render() output
file.from({ image: 'node', registry: 'docker.io', tag: '10-alpine' })
// FROM docker.io/node:10-alpine
```
File renamed without changes.
34 changes: 17 additions & 17 deletions lib/instruction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const errors = require('./instruction_error.js')
const errors = require('./instruction-error.js')

function boxAndFilter(arrayOrString) {
if(!Array.isArray(arrayOrString))
Expand All @@ -19,7 +19,7 @@ function onBuild(instruction) {
* FROM <image>:<tag>
* FROM <image>@<digest>
*
* Parameters:
* Parameters:
* image, (optional) tag, digest, registry
*
* Not standard:
Expand Down Expand Up @@ -81,7 +81,7 @@ function mapToQuote(string) {
* Input string: returns trimmed string
* Input array of strings: returns a array of trimmed strings
*
* Note: Strings with WS in an array will be encapsulated by quotes
* Note: Strings with WS in an array will be encapsulated by quotes
*/
function mapCommandParams(command) {
if(Array.isArray(command)) {
Expand All @@ -93,7 +93,7 @@ function mapCommandParams(command) {
/**
* Case:
* RUN <command>
* Parameters:
* Parameters:
* command (alias: commands)
*
* Expect string of well-formed command or an array of strings of
Expand Down Expand Up @@ -142,9 +142,9 @@ function run(run) {
*
* Parameters:
* params and or (executable or command)
*
*
* Params may be empty if and only if executable or command is provided
*
*
* Solely providing the params property will yield the second case.
* Providing the executable or command property will yield the first or third cases respectively.
* Providing command and executable will throw an error
Expand Down Expand Up @@ -190,7 +190,7 @@ function cmd(cmd) {
/**
* Case:
* ENTRYPOINT ["executable", "param1", "param2"]
*
*
* Docs:
* https://docs.docker.com/engine/reference/builder/#/entrypoint
*
Expand All @@ -212,7 +212,7 @@ function entryPoint(entrypoint) {
return instruction
}

/**
/**
* Flattens objects into an array of arrays, returns null if object has no OwnProperties.
*/
function flattenLabels(o, namespace) {
Expand Down Expand Up @@ -241,7 +241,7 @@ function mapLabel(label) {
/**
* Case:
* LABEL multi.label1="value1" multi.label2="value2" other="value3"
*
*
*
*/
function label(labels, onbuild) {
Expand All @@ -260,7 +260,7 @@ function label(labels, onbuild) {
/**
* Case:
* EXPOSE <port> [<port>...]
*
*
* Expects an array of ports as numbers, strings, or an object of {number: <num or str>, protocol: <string> }
* If a port object is provided and the protocol field is blank it will be omitted.
*
Expand All @@ -272,7 +272,7 @@ function label(labels, onbuild) {
* ]
* }
* instructions.expose(config.ports)
*
*
* A "port object" may also specify from and to for a range of exposed ports, though
* simply supplying '8080-8086' will do the same.
*
Expand Down Expand Up @@ -301,7 +301,7 @@ function expose(expose, onbuild) {
})

if(expose.length) {
instruction = `EXPOSE [ ${expose.join(', ')} ]`
instruction = `EXPOSE ${expose.join(' ')}`
} else {
throw new errors.InstructionError(
'expose',
Expand All @@ -315,7 +315,7 @@ function expose(expose, onbuild) {
/**
* ENV <key> <value>
* ENV <key>=<value> ...
*
*
* Parameters:
* 1) Any object with terminal property-values of string, or number type.
*/
Expand All @@ -340,7 +340,7 @@ function copyInternal(command, src, dest, onbuild) {

if(src.length == 0) {
throw new errors.EmptyArrayError(command, 'src')
}
}

if(dest && dest.length) {
instruction = `${command} [${src.map(enQuote).join(', ')}, "${dest}"]`
Expand Down Expand Up @@ -423,7 +423,7 @@ function healthCheck(healthCheck) {
if(keys.length) {
options = keys.map(k => {
return `--${k}=${options[k]}`
}).reduce((a,b) => a+' '+b)
}).reduce((a,b) => a+' '+b)
}
}

Expand Down Expand Up @@ -452,7 +452,7 @@ function comment() {
var args = []
for(var i = 0; i < arguments.length; ++i)
args.push(arguments[i])
return '# ' + args.map(arg => arg ? arg.toString() : arg).join(' ')
return '# ' + args.map(arg => arg ? arg.toString() : arg).join(' ')
}

module.exports.from = from
Expand All @@ -471,4 +471,4 @@ module.exports.stopSignal = stopSignal
module.exports.volume = volume
module.exports.healthCheck = healthCheck
module.exports.shell = shell
module.exports.comment = comment
module.exports.comment = comment
Loading