Giter Site home page Giter Site logo

rcjsuen / dockerfile-utils Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 5.0 1.18 MB

A library and command line interface for formatting and linting Dockerfiles.

License: MIT License

JavaScript 2.33% TypeScript 97.60% Dockerfile 0.08%
docker dockerfile-utilities moby dockerfile dockerfiles linter lint linting validation validator formatter formatting

dockerfile-utils's Introduction

Dockerfile Utilities

Node.js Builds Coverage Status Build Dependencies License: MIT

This is a collection of utilities for working with Dockerfiles powered by Node.js written in TypeScript. To install and run these utilities, you will need to have Node.js or Docker installed on your computer.

Supported features:

  • formatting
  • linting

Development Instructions

If you wish to build and compile this project, you must first install Node.js if you have not already done so. After you have installed Node.js and cloned the repository with Git, you may now proceed to build and compile the project with the following commands:

npm install
npm run build
npm test

If you are planning to change the code, use npm run watch to get the TypeScript files transpiled on-the-fly as they are modified.

Installation Instructions

To add this library as a dependency to your project, please add dockerfile-utils as a dependency in your project's package.json file.

Running the CLI with Node.js

To install and use the dockerfile-utils command line interface, please install the dockerfile-utils npm module. The -g flag will install the NPM module globally onto your computer.

npm install -g dockerfile-utils

After the installation has completed, you can run the CLI using the dockerfile-utils binary.

> dockerfile-utils --help
Usage: dockerfile-utils <command> [<args>]

Options:

  -h, --help                Output usage information
  -v, --version             Output version information

Commands:

  format                    Format a Dockerfile
  lint                      Validate a Dockerfile

Running the CLI with Docker

You can use docker run to launch the command line interface with Docker. This removes the requirement of needing to have Node.js installed locally on your computer. The dockerfile-utils binary is available as a Docker image under the name rcjsuen/dockerfile-utils.

> docker run rcjsuen/dockerfile-utils --help
Usage: dockerfile-utils <command> [<args>]

Options:

  -h, --help                Output usage information
  -v, --version             Output version information

Commands:

  format                    Format a Dockerfile
  lint                      Validate a Dockerfile

To format or lint a Dockerfile in the current working directory, please use the following commands.

> docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils format /Dockerfile
> docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile

dockerfile-utils's People

Contributors

jsoref avatar rcjsuen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dockerfile-utils's Issues

Content that comes after a JSON's closing bracket should be ignored

The following Dockerfile can be built by Docker but the validator will flag it with an error because of the extra argument after the closing bracket.

FROM alpine
SHELL [ "bin/sh" ] ]
$ dockerfile-utils lint Dockerfile
Line: 2
SHELL [ "bin/sh" ] ]
      ^^^^^^^^^^^^^^
Error: SHELL requires the arguments to be in JSON form
$ docker build .
Sending build context to Docker daemon  1.695MB
Step 1/2 : FROM alpine
 ---> 3fd9065eaf02
Step 2/2 : SHELL [ "bin/sh" ] ]
 ---> Running in b0da3c65034a
Removing intermediate container b0da3c65034a
 ---> aa065d62e762
Successfully built aa065d62e762

dockerfile-utils binary does not work

I screwed up the binary by having it refer to the stuff in the /out/src folder instead of /lib.

let dockerfileUtils = require("../out/src/main");
let vscodeLangserver = require("vscode-languageserver-types");
let formatter = require("../out/src/dockerFormatter");

let dockerfileUtils = require("../out/src/main");
let validator = require("../out/src/dockerValidator");

> dockerfile-utils lint
module.js:471
    throw err;
    ^

Error: Cannot find module '../out/src/main'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at validate (dockerfile-utils\bin\dockerfile-utils:158:27)
    at Object.<anonymous> (dockerfile-utils\bin\dockerfile-utils:35:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

> dockerfile-utils format
module.js:471
    throw err;
    ^

Error: Cannot find module '../out/src/main'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at format (dockerfile-utils\bin\dockerfile-utils:143:27)
    at Object.<anonymous> (dockerfile-utils\bin\dockerfile-utils:16:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

Validator should detect invalid duration that includes a hyphen

FROM alpine
HEALTHCHECK --interval=5s-10ms CMD ls
$ docker build .
Sending build context to Docker daemon  1.693MB
Step 1/2 : FROM alpine
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest
 ---> 3fd9065eaf02
Step 2/2 : HEALTHCHECK --interval=5s-10ms CMD ls
time: unknown unit s- in duration 5s-10ms

A duration of 5s-10ms should be flagged as an error by the validator.

> dockerfile-utils lint Dockerfile
> 

Expose ValidationCode in main.d.ts

Depending on the validation error that has been detected, clients need to be able to offer meaningful and appropriate actions for resolving the error. To that end, we need to expose ValidationCode to clients so that they can check what type of validation error has been detected by the linter.

Referencing a tagged image in a private registry in FROM causes an invalid error

The extra semi-colon at the end is causing parsing problems in the validator.

FROM privateregistry.com:5000/image:tag
FROM localhost:1234/node:9
FROM 123.22.33.123:2345/user/image:tag2
$ dockerfile-utils lint Dockerfile
Line: 1
FROM privateregistry.com:5000/image:tag
                                    ^^^
Error: invalid reference format

Line: 2
FROM localhost:1234/node:9
                         ^
Error: invalid reference format

Line: 3
FROM 123.22.33.123:2345/user/image:tag2
                                   ^^^^
Error: invalid reference format

Decimals in duration incorrectly flagged as an error

FROM scratch
HEALTHCHECK --timeout=5s.1ms CMD ls
$ docker build .
Sending build context to Docker daemon  1.693MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : HEALTHCHECK --timeout=5s.1ms CMD ls
 ---> Running in 3af4f3acc567
 ---> 22f68f4e91b1
Removing intermediate container 3af4f3acc567
Successfully built 22f68f4e91b1

It seems like the parsing of a flag's duration isn't quite right.

$ dockerfile-utils lint Dockerfile
Line: 2
HEALTHCHECK --timeout=5s.1ms CMD ls
                      ^^^^^^
Error: time: unknown unit . in duration 5s.1ms

Flag STOPSIGNAL with $ argument as an error

If we run the CLI linter on the file below, we won't get any errors. However, the Docker builder will not build the image as $ is not a valid STOPSIGNAL argument so the linter should be updated to handle this case.

FROM scratch
STOPSIGNAL $
$ docker build .
Sending build context to Docker daemon  1.871MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : STOPSIGNAL $
Invalid signal: $

Create typings main.d.ts file

The published package currently only has js files in the lib/ folder. There should be a main.d.ts file for clients to consume.

Flag double hyphens as an invalid duration

If there are two hyphens in a duration flag, it should be flagged as an error.

FROM alpine
HEALTHCHECK --timeout=--5s CMD ls
$ dockerfile-utils lint Dockerfile
$
$ docker build .
Sending build context to Docker daemon  1.696MB
Error response from daemon: Dockerfile parse error line 2: time: invalid duration --5s

Flag double decimals in a HEALTHCHECK duration flag as an error

FROM alpine
HEALTHCHECK --timeout=5..5s CMD ls
$ docker build .
Sending build context to Docker daemon  1.695MB
Error response from daemon: Dockerfile parse error line 2: time: missing unit in duration 5..5s
$  docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile
$

Flag quoted arguments in ARG, ENV, and LABEL as an error

The following two Dockerfiles will pass the validator just fine.

FROM scratch
ENV "a.b.c=xyz"
FROM scratch
ENV "a.b.c=xyz

However, Docker will refuse to build it. If possible, we should try to detect this case and flag an error as well.

$ docker build .
Sending build context to Docker daemon  1.693MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ENV "a.b.c=xyz"
failed to process "\"a.b.c": unexpected end of statement while looking for matching double-quote
$ docker build .
Sending build context to Docker daemon  1.693MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ENV "a.b.c=xyz
failed to process "\"a.b.c": unexpected end of statement while looking for matching double-quote

Error output does not include the final character

FROM scratch
ABC
> dockerfile-utils lint Dockerfile
Line: 2
AB
^^^
Error: Unknown instruction: ABC

Although three ^ characters are included in the linter's output, the C character has been truncated. If you add a newline character at the end of the invalid instruction then the C won't get truncated so it seems like the final character is the problem here.

Port gets flagged as an error if it refers to a build argument without a default value

FROM scratch
ARG ZOO_PORT
EXPOSE $ZOO_PORT
> dockerfile-utils lint Dockerfile
Line: 3
EXPOSE $ZOO_PORT
       ^^^^^^^^^
Error: Invalid containerPort: $ZOO_PORT

The validator is flagging an error because the variable can't be resolved to a value that makes sense for an EXPOSE instruction (as it resolves to nothing). However, as the value will be provided by the user when the Docker image is built, the argument should just be outright ignored by the validator as we should assume that the value provided by the user is valid.

Travis CI build #65 is broken

Looks like I made a typo in 36b99ae and it's caused Travis CI build #65 to fail.

  375 passing (1s)
  1 failing
  1) Docker Validator Tests
       FROM
         source image
           ok:
      AssertionError [ERR_ASSERTION]: 2 == 0
      + expected - actual
      -2
      +0
      
      at Context.<anonymous> (out/test/dockerValidator.test.js:2160:24)

Unexpanded ARG variable causes incorrect warning about an invalid reference format

It is possible to use ARG variables in a FROM so they need to be expanded before we try to validate it.

ARG version=latest
FROM alpine:$version
$ docker build .
Sending build context to Docker daemon  1.695MB
Step 1/2 : ARG version=latest
Step 2/2 : FROM alpine:$version
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest
 ---> 3fd9065eaf02
Successfully built 3fd9065eaf02
$ dockerfile-utils lint Dockerfile.1
Line: 2
FROM alpine:$version
            ^^^^^^^^
Error: invalid reference format

Here are some other Dockerfiles that are also valid.

ARG version=atest
FROM alpine:l$version
ARG atest=atest
FROM alpine:l$atest
ARG DIGEST=sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
FROM alpine@$DIGEST

Tag docker image with Git commit SHA hash

Besides pushing a rcjsuen/dockerfile-utils:latest image to Docker Hub, we should also push an image with a tag that matches the Git commit SHA hash of the build.

Decimal values in durations are not parsed correctly

FROM alpine
HEALTHCHECK --interval=.1ms CMD l
$ dockerfile-utils lint Dockerfile
$
$ docker build .
Sending build context to Docker daemon  1.695MB
Error response from daemon: Dockerfile parse error line 2: Interval "interval" cannot be less than 1ms

We aren't handling a value of .1ms properly it seems. A value of 0.1ms is correctly flagged as an error though.

$ dockerfile-utils lint Dockerfile.1
Line: 2
HEALTHCHECK --interval=0.1ms CMD l
              ^^^^^^^^
Error: Interval "interval" cannot be less than 1ms

Invalid digests in a private registry with ports should be flagged as an error

FROM localhost/node@
FROM localhost:1234/node@
FROM 123.22.33.123/user/image@
FROM 123.22.33.123:2345/user/image@

These FROM instructions are clearly invalid but we don't seem to be considering all of them. Only the first and third lines are being flagged as an error.

$ docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile

Unable to find image 'rcjsuen/dockerfile-utils:latest' locally
latest: Pulling from rcjsuen/dockerfile-utils
ff3a5c916c92: Pull complete
4d34b95ee50c: Pull complete
58006ba8d4ce: Pull complete
115c0912b672: Pull complete
23475bf850aa: Pull complete
7c7babd76ce1: Pull complete
ac1d2627637c: Pull complete
Digest: sha256:fe13d08564b5770f0867d95e2027dd730e72f78f86c4de63f4ceb77ed5b93985
Status: Downloaded newer image for rcjsuen/dockerfile-utils:latest
Line: 1
FROM localhost/node@
     ^^^^^^^^^^^^^^^
Error: invalid reference format

Line: 3
FROM 123.22.33.123/user/image@
     ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: invalid reference format

COPY incorrectly flags JSON's closing bracket as an invalid argument

Docker will happily build the following Dockerfile but the validator incorrectly flags the closing bracket as an error. Caused by implementing #14.

FROM alpine
COPY [ "t1.txt", "t2.txt", "./" ]
$ docker build .
Sending build context to Docker daemon  1.696MB
Step 1/2 : FROM alpine
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest
 ---> 3fd9065eaf02
Step 2/2 : COPY [ "t1.txt", "t2.txt", "./" ]
 ---> 5c017e611051
Successfully built 5c017e611051
$ dockerfile-utils lint .\Dockerfile.1
Line: 2
COPY [ "t1.txt", "t2.txt", "./" ]
                                ^
Error: When using COPY with more than one source file, the destination must be a directory and end with a / or a \

Dockerfile's resolveVariable resolve variables across build stages incorrectly

import { DockerfileParser } from 'dockerfile-ast';

const content =
`FROM alpine
ARG var=8000
ENV var2=8001
FROM alpine
EXPOSE $var
EXPOSE $var2`

let dockerfile = DockerfileParser.parse(content);
console.log(dockerfile.resolveVariable("var", 4));
console.log(dockerfile.resolveVariable("var2", 5));
8000
8001

As the two EXPOSE arguments are in another build stage, resolveVariable should return undefined instead of resolving to the values defined by the two variables in the first build stage.

Using variables in FROM confuses the validator

Using variables is valid in the base image argument of a FROM but it seems to validator won't ignore it properly.

ARG image=scratch
FROM ${image:-alpine}
$ docker build .
Sending build context to Docker daemon  1.774MB
Step 1/2 : ARG image=scratch
Step 2/2 : FROM ${image:-alpine}
 --->
No image was generated. Is your Dockerfile empty?
$ dockerfile-utils lint Dockerfile
Line: 2
FROM ${image:-alpine}
             ^^^^^^^^
Error: invalid reference format

False positive caused by ARG that continues to nothing

The following unrealistic Dockerfile builds just fine.

FROM scratch
ARG var=value \
# var2=value2
$ docker build .
Sending build context to Docker daemon  1.774MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ARG var=value
 ---> Running in 39d20b950664
Removing intermediate container 39d20b950664
 ---> 52bd1fd4e9ae
Successfully built 52bd1fd4e9ae

However, the validator will flag an error. Note also that the range of the highlighted content seems weird as it includes the whitespace between ARG and var=value as well as the whitespace after the var=value.

$ docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile
Line: 2
ARG var=value \
   ^^^^^^^^^^^
Error: ARG requires exactly one argument

Warn if variable substitution does not have a semi-colon

The validator will not generate any errors for the following Dockerfile. We should check to make sure that such incomplete variables are warned about if possible.

FROM scratch
ARG aaa=${bbb
$ docker build .
Sending build context to Docker daemon  1.695MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ARG aaa=${bbb
failed to process "${bbb": missing ':' in substitution

Travis CI build #1 is broken

Build #1 is broken due to a compilation error. Looks like the refactoring wasn't quite complete as we're referring to vscode-languageserver instead of vscode-languageserver-types.

> [email protected] prepublish /home/travis/build/rcjsuen/dockerfile-utils
> tsc -p ./src

src/dockerFormatter.ts(9,8): error TS2307: Cannot find module 'vscode-languageserver'.
src/dockerValidator.ts(7,8): error TS2307: Cannot find module 'vscode-languageserver'.

Flag an error if COPY's --from flag is invalid

FROM scratch
COPY --from= . .
$ docker build .
Sending build context to Docker daemon  86.15MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : COPY --from= . .
invalid from flag value : invalid reference format
FROM scratch
COPY --from=^abc . .
$ docker build .
Sending build context to Docker daemon  1.873MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : COPY --from=^abc . .
invalid from flag value ^abc: invalid reference format

The --from flag of a COPY instruction must reference a valid build stage or image. The validator should create a warning if this is detected in the Dockerfile.

Validator does not count arguments correctly for ADD and COPY instructions written in JSON

The following Dockerfile can be built just fine but the validator will create warnings because it thinks there is only one argument in the two instructions since there are no spaces in the JSON.

FROM alpine
ADD ["t1.txt","t2.txt"]
COPY ["t1.txt","t2.txt"]
$ dockerfile-utils lint Dockerfile
Line: 2
ADD ["t1.txt","t2.txt"]
    ^^^^^^^^^^^^^^^^^^^
Error: ADD requires at least two arguments

Line: 3
COPY ["t1.txt","t2.txt"]
     ^^^^^^^^^^^^^^^^^^^
Error: COPY requires at least two arguments
$ docker build .
Sending build context to Docker daemon  1.696MB
Step 1/3 : FROM alpine
 ---> 3fd9065eaf02
Step 2/3 : ADD ["t1.txt","t2.txt"]
 ---> 5b13022208ff
Step 3/3 : COPY ["t1.txt","t2.txt"]
 ---> 057ec728c238
Successfully built 057ec728c238

Warn if variable substitution does not have a valid modifier

Only a + or a - can come after a semi-colon for a variable substition. We should create a warning for this if it can be detected.

FROM scratch
ARG aaa=${bbb:x
$ docker build .
Sending build context to Docker daemon  1.695MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ARG aaa=${bbb:x
failed to process "${bbb:x": unsupported modifier (x) in substitution

False positive flagged if quotes used when replacing variables in an ARG, ENV, or LABEL

The following Dockerfile will built without any problems. We need to fix the validator so that it doesn't consider the ENV instruction to be an error.

FROM scratch
ARG BUNDLE_WITHOUT
ENV BUNDLE_WITHOUT=${bundle_without:-'development test'}
$ dockerfile-utils lint Dockerfile
Line: 3
ENV BUNDLE_WITHOUT=${bundle_without:-'development test'}
                                                       ^
Error: Syntax error - can't find = in "}". Must be of the form: name=value
$ docker build .
Sending build context to Docker daemon  1.693MB
Step 1/3 : FROM scratch
 --->
Step 2/3 : ARG BUNDLE_WITHOUT
 ---> Running in 7cc436e68ec3
Removing intermediate container 7cc436e68ec3
 ---> 64a3e0a2f136
Step 3/3 : ENV BUNDLE_WITHOUT=${bundle_without:-'development test'}
 ---> Running in c148dc76c691
Removing intermediate container c148dc76c691
 ---> a608dc772a5d
Successfully built a608dc772a5d

Warn if COPY has more than two arguments and the last one is not a directory

FROM alpine
COPY Dockerfile Dockerfile2 /root
$ docker build .
Sending build context to Docker daemon  1.878MB
Step 1/2 : FROM alpine
 ---> 3fd9065eaf02
Step 2/2 : COPY Dockerfile Dockerfile2 /root
When using COPY with more than one source file, the destination must be a directory and end with a /

If a COPY has more than two arguments, the last argument must be a directory. The Docker builder will check for this by validating that the last argument ends with the OS's path segment separator (either / or \).

Flag hyphens parsed as a time unit as an error

It seems like we're ignoring the hyphen and not flagging the duration as an error.

FROM alpine
HEALTHCHECK --interval=5-5s CMD ls
$ docker build .
Sending build context to Docker daemon  1.695MB
Error response from daemon: Dockerfile parse error line 2: time: unknown unit - in duration 5-5s
$ docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile
$

Warn if variable declaration is not closed

The following Dockerfile cannot be built but it passes the validator.

FROM scratch
ARG aaa=${bbb
$ dockerfile-utils lint Dockerfile
$
$ docker build .
Sending build context to Docker daemon  1.775MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : ARG aaa=${bbb
failed to process "${bbb": missing ':' in substitution

ADD incorrectly flags JSON's closing bracket as an invalid argument

Docker will happily build the following Dockerfile but the validator incorrectly flags the closing bracket as an error. Caused by implementing #17.

FROM alpine
ADD [ "t1.txt", "t2.txt", "./" ]
$ docker build .
Sending build context to Docker daemon  1.696MB
Step 1/2 : FROM alpine
 ---> 3fd9065eaf02
Step 2/2 : ADD [ "t1.txt", "t2.txt", "./" ]
 ---> bbf5b39e1dc5
Successfully built bbf5b39e1dc5
$ dockerfile-utils lint Dockerfile
Line: 2
ADD [ "t1.txt", "t2.txt", "./" ]
                               ^
Error: When using ADD with more than one source file, the destination must be a directory and end with a / or a \

Warn if base image's tag is invalid

If the tag of a FROM is invalid, we should create a warning about it.

FROM alpine:
$ docker build .
Sending build context to Docker daemon   1.88MB
Step 1/1 : FROM alpine:
invalid reference format
FROM alpine:^
$ docker build .
Sending build context to Docker daemon  1.881MB
Step 1/1 : FROM alpine:^
invalid reference format
FROM alpine:a66^
$ docker build .
Sending build context to Docker daemon  1.881MB
Step 1/1 : FROM alpine:a66^
invalid reference format

False positive flagged for quotes in ENV and LABEL instructions

If a LABEL instruction uses quotes for its values, we seem to be flagging it as an error even though it builds just fine. Perhaps this was caused by the fix for #40?

FROM scratch
LABEL "a"="b" \
    "c"="d" \
    "e"="f"
$ docker build .
Sending build context to Docker daemon  1.774MB
Step 1/2 : FROM scratch
 --->
Step 2/2 : LABEL "a"="b"     "c"="d"     "e"="f"
 ---> Running in 9b71e47cfa13
Removing intermediate container 9b71e47cfa13
 ---> 7b64e135ec7f
Successfully built 7b64e135ec7f

The line numbers in the error also seem weird...

$ dockerfile-utils lint Dockerfile
Line: 4-3
Error: Syntax error - can't find = in "    ". Must be of the form: name=value

Line: 4
    "c"="d" \
       ^^^^
Error: LABEL names can not be blank

Line: 5-4
Error: Syntax error - can't find = in "    ". Must be of the form: name=value

Line: 5
    "e"="f"
       ^^^^
Error: LABEL names can not be blank

CLI linter fails on TypeError

Given a Dockerfile that has validation errors in it, trying to lint the file will cause the CLI to crash.

> dockerfile-utils lint
node_modules\dockerfile-utils\bin\dockerfile-utils:188
        if (diagnostics[i].code === validator.ValidationCode.EMPTY_CONTINUATION_LINE) {
                                                            ^

TypeError: Cannot read property 'EMPTY_CONTINUATION_LINE' of undefined
    at validate (node_modules\dockerfile-utils\bin\dockerfile-utils:188:61)
    at Object.<anonymous> (node_modules\dockerfile-utils\bin\dockerfile-utils:35:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

Warn about ARG instructions that do not specify a variable name

ARG instructions must have a name specified.

FROM scratch
ARG =value
$ docker build .
Sending build context to Docker daemon  1.774MB
Error response from daemon: Dockerfile parse error line 2: ARG names can not be blank

We should add support for this in the validator.

$ docker run -v `pwd`/Dockerfile:/Dockerfile rcjsuen/dockerfile-utils lint /Dockerfile
$

Warn if base image's digest is invalid

If the digest of a FROM is invalid, we should create a warning about it.

FROM alpine@sha25:x
$ docker build .
Sending build context to Docker daemon  1.881MB
Step 1/1 : FROM alpine@sha25:x
invalid reference format

Exclude quotes when highlighting erroneous final folder argument in ADD and COPY

Instead of highlighting the entire argument, we should only highlight what is contained within the quotes.

FROM alpine
ADD [ "t1.txt", "t2.txt", "dir" ]
COPY [ "t1.txt", "t2.txt", "dir" ]
$ dockerfile-utils lint Dockerfile
Line: 2
ADD [ "t1.txt", "t2.txt", "dir" ]
                          ^^^^^
Error: When using ADD with more than one source file, the destination must be a directory and end with a / or a \

Line: 3
COPY [ "t1.txt", "t2.txt", "dir" ]
                           ^^^^^
Error: When using COPY with more than one source file, the destination must be a directory and end with a / or a \

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.