replicatedhq / dockerfilelint

An opinionated Dockerfile linter.
https://www.fromlatest.io
MIT License
992 stars 83 forks source link

TypeError: Cannot read property 'reduce' of null #156

Open AmauryOrtega opened 4 years ago

AmauryOrtega commented 4 years ago

When using this Dockerfile with the latest dockerfilelint docker image, an internal error shows up. I checked using /bin/sh to make sure the Dockerfile is accessible, I tried moving the Dockerfile to the working directory of /dockerfilelint/ and using the binary inside /dockerfilelint/bin/ but I got the same error message.

Dockerfile

FROM node:12-alpine as dependencies

# Source directory
WORKDIR /usr/src/app/
RUN chown -R node:node .
USER node

# Dependencies
COPY --chown=node:node package*.json ./
RUN npm ci

# Source code and build configuration
COPY --chown=node:node angular.json tsconfig*.json ./
COPY --chown=node:node ngsw-config.json .
COPY --chown=node:node src/ src/

# Compilation
FROM dependencies as build
RUN npx ng build --prod

FROM nginx:stable-alpine
# hadolint ignore=DL3018
RUN apk --no-cache add curl \
   && rm -rf /var/cache/apk/*
HEALTHCHECK CMD curl -f http://localhost/ || exit 1

COPY --chown=nginx:nginx --from=build /usr/src/app/dist/bouwmapp-frontend/ /usr/share/nginx/app/
COPY --chown=nginx:nginx nginx/app.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

Command

docker run --rm -v "$PWD"/Dockerfile:/Dockerfile:ro replicated/dockerfilelint:latest /Dockerfile

Output

/dockerfilelint/lib/checks.js:194
      if (!options.reduce((valid, item) => valid &&
                   ^
TypeError: Cannot read property 'reduce' of null
    at Object.is_valid_healthcheck (/dockerfilelint/lib/checks.js:194:20)
    at runLine (/dockerfilelint/lib/index.js:287:16)
    at Object.module.exports.run (/dockerfilelint/lib/index.js:63:18)
    at processContent (/dockerfilelint/bin/dockerfilelint:92:50)
    at argv._.forEach (/dockerfilelint/bin/dockerfilelint:86:3)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/dockerfilelint/bin/dockerfilelint:65:8)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
a16bitsysop commented 4 years ago

I think I am getting the same error, have you tried deleting healthcheck and see if error stops

AmauryOrtega commented 4 years ago

@a16bitsysop To give more details, when I originally created this issue, the latest docker image I was using had this image ID ea3ff6887d47.

Using the same image ID and the same Dockerfile without the healthcheck produces this output:

File:   /Dockerfile
Issues: None found 👍

I see that there is a new latest docker image with image ID 24b7b3aae3ac. I've tried both scenarios (with and without healthcheck) but the behavior is the same when the healthcheck is there but the call stack is just slightly different:

/dockerfilelint/lib/checks.js:194
      if (!options.reduce((valid, item) => valid &&
                   ^

TypeError: Cannot read property 'reduce' of null
    at Object.is_valid_healthcheck (/dockerfilelint/lib/checks.js:194:20)
    at runLine (/dockerfilelint/lib/index.js:287:16)
    at Object.module.exports.run (/dockerfilelint/lib/index.js:63:18)
    at processContent (/dockerfilelint/bin/dockerfilelint:92:50)
    at /dockerfilelint/bin/dockerfilelint:86:3
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/dockerfilelint/bin/dockerfilelint:65:8)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)

I'm willing to continue testing new versions so let me know if I can assist in anyway

a16bitsysop commented 4 years ago

@AmauryOrtega I am not a developer, I am a user as well. I am trying to find out what is causing it also.

a16bitsysop commented 4 years ago

@AmauryOrtega if you add an option like: HEALTHCHECK --start-period=60s CMD curl -f http://localhost/ || exit 1 It should work, it has to have an option before the command and has to end in || exit 1

lvjp commented 3 years ago

I made a simple fix to this null pointer...

AmauryOrtega commented 3 years ago

Thanks @lvjp :tada:

@marccampbell Is the fix acceptable?

szaimen commented 1 year ago

I am having the same issue... https://github.com/replicatedhq/dockerfilelint/pull/184 looks good to me as a fix...