Dockerfile
FROM node:carbon
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
RUN npm install gulp -g
COPY . .
run gulp build --build
run npm test
EXPOSE 80
CMD [ "npm", "start" ]
Tests are ran using mocha --recursive
build.sh
docker build -t my-app .
echo $?
How can I detect that one mocha test fails, thus npm test
should not be ok, and neither docker build
?
I may have missed something in here.
RUN
in a Dockerfile will fail if the exit code of the command is non-zero. If that happens, docker build
will also fail with a non-zero exit code.
Your npm test
script needs to return a non-zero exit code when the tests fail.
For reference, you can check the exit code like this:
$ npm test
$ echo $?
You may change line run npm test
to run npm test || exit 1
Ran a quick test and confirmed build is failing. Here is a screen shot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With