★ wanayoo — archive 1999 https://github.com/nodejs/docker-node/issues/225Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unfriendly output in Jenkins #225

Closed
mraxus opened this issue Aug 29, 2016 · 19 comments
Closed

Unfriendly output in Jenkins #225

mraxus opened this issue Aug 29, 2016 · 19 comments

Comments

@mraxus
Copy link

@mraxus mraxus commented Aug 29, 2016

Hello and thanks for docker-node!

I have an issue with the printout from the container.

Step 10 : RUN make release-staging
 ---> Running in 53a9e21d6a66
[91mnpm[0m[91m [0m[91minfo it worked if it ends with[0m[91m ok
npm[0m[91m info using npm@3.10.3
npm info using node@v6.4.0
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mok[0m[91m 
[0mnpm install
[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mit worked if it ends with[0m[91m ok
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m npm@3.10.3
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m node@v6.4.0
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mattempt[0m[91m registry request try #1 at 1:22:04 PM
[0m[91mnpm[0m[91m [0m[91mhttp[0m[91m [0m[91mrequest[0m[91m GET https://registry.npmjs.org/babel-core

Before each [ there is an ESC character but I stripped that from the same since it's not shown in the output of the Jenkins console.

My question:

Can I disable the output from printing all these extra characters?

I tried to add this in the Dockerfile but it did not seem to help =-(

ENV NPM_COLOR false

Cheers,
-- mraxus

@chorrell
Copy link
Contributor

@chorrell chorrell commented Aug 29, 2016

If this is the v6 image, then what you are most likely seeing is there is the output of npm@3's progress bar.

Try this:

ENV NPM_CONFIG_PROGRESS false

https://docs.npmjs.com/misc/config#progress

@Starefossen
Copy link
Member

@Starefossen Starefossen commented Aug 29, 2016

@chorrell is right, and while your at it, disable the spinner as well:

ENV NPM_CONFIG_PROGRESS false
ENV NPM_CONFIG_SPIN false
@mraxus
Copy link
Author

@mraxus mraxus commented Aug 29, 2016

@chorrell and @Starefossen Thanks for your replies.
You are correct in the v6 image. I am running node:6.4.0.

However, the updated Dockerfile with both progress and spin had no effect.
Here is the content of the Dockerfile.

FROM node:6.4.0
ENV NPM_CONFIG_PROGRESS false
ENV NPM_CONFIG_SPIN false

WORKDIR /app

ARG REVISION
ARG BRANCH
ARG S3_STAGING_BUCKET

RUN apt-get update
RUN apt-get install -y python-pip
RUN pip install awscli

ADD . .

RUN chmod 755 *.sh

RUN make test                              <-- Here is the call to npm install
RUN make release-staging
RUN make build-production

CMD ["./release.sh"]

Is there anything else you need?
I also tried to include ENV NPM_CONFIG_COLOR false but without success. (I will stop testing that =p)

Should be said, before the npm commands, there are no problems with the std output.

@chorrell
Copy link
Contributor

@chorrell chorrell commented Aug 30, 2016

As a simple test case, just doing something like this works when I tried it:

FROM node:6.4.0

ENV NPM_CONFIG_PROGRESS false
ENV NPM_CONFIG_SPIN false

WORKDIR /app

RUN npm install express

Are you running the npm install command via a make file or from a shell script that's called from a make file? If that's the case, you probably want to put the environment variables in either the make file or the shell/bash script to disable the progress bar:

export NPM_CONFIG_PROGRESS=false
export NPM_CONFIG_SPIN=false

I don't think the ENV instruction works in the same ay as export, meaning it doesn't make the variable available to bash sub-processes.

Another option would be to add a .npmrc file to your project with the npm settings you want and the file via a COPY:

COPY .npmrc /app

And in your .npmrc file:

progress=false
spin=false
@mraxus
Copy link
Author

@mraxus mraxus commented Aug 30, 2016

Thanks for the additional suggestions @chorrel. However, none of the suggested ideas helped.

I searched for info regarding the codes generated by the npm command. This is the result:
http://jafrog.com/2013/11/23/colors-in-terminal.html

The format almost exactly matches my logs.

And continuing testing with building docker images locally, I noticed that the npm install is coloring certain lines. These match the pattern of the extra characters from my Jenkins logs.

I have continued to try to turn off the colors with both with:

  • ENV NPM_CONFIG_COLOR false
  • .npmrc config
  • a .sh file with
    • export NPM_CONFIG_COLOR=false; npm install async
    • NPM_CONFIG_COLOR=false npm install async

Each time I still get the red coloring when viewing the docker console. When doing the same procedures locally, the output was not colored.

My only conclusion is that the configuration doesn't work for in the docker image. Please prove me wrong =)

@Starefossen
Copy link
Member

@Starefossen Starefossen commented Aug 30, 2016

@mraxus could you try to add --color false to all your npm commands. Like this:

npm --color false install async
@mraxus
Copy link
Author

@mraxus mraxus commented Aug 30, 2016

@Starefossen Same results. I would believe this is very easily reproducible for anyone.

Dockerfile

FROM node:6.4.0
ENV NPM_CONFIG_COLOR false

WORKDIR /app

COPY run.sh /app
RUN bash run.sh

CMD ["node", "some_file.js"]

run.sh

#!/bin/bash

export NPM_CONFIG_COLOR=false

npm --color false install async

put them in a folder and run the command:
docker build .

@chorrell
Copy link
Contributor

@chorrell chorrell commented Aug 30, 2016

I think it might have something to do with the output of the docker build command, and not npm. If I do something like this, no colours are displayed:

docker run -it --rm node:6.4.0 npm --color false install async
@mraxus
Copy link
Author

@mraxus mraxus commented Aug 30, 2016

@chorrell Very interesting. Same result for me too.

But it have to be originating from npm somehow, since it still colors but only some part, not everything the same way. Frustrating, nonetheless.

@tianon
Copy link
Contributor

@tianon tianon commented Aug 30, 2016

@mraxus
Copy link
Author

@mraxus mraxus commented Aug 31, 2016

@tianon If that works, it would be amazing. Will try it out, if the infra guys allows ;-) Thanks for the tip!

@chorrell, @Starefossen: I don't think I will spend more time on this, so do with this issue as you please. Thank you so much for the help anyways. Much appreciated!

@chorrell chorrell closed this Sep 7, 2016
@amcsi
Copy link

@amcsi amcsi commented Sep 18, 2016

I have the same problem, except I'm not using Jenkins, but rather Dockerhub where I don't have any control over things like plugins.
I would like to have this issue re-opened.

@chorrell
Copy link
Contributor

@chorrell chorrell commented Sep 19, 2016

At this point it's not clear whether this is something that can be addressed in the Dockerfiles. Based on my experiments in #225 (comment), it seems like it's an issue with docker build or a combined issue with npm and docker build

@chorrell chorrell reopened this Sep 19, 2016
@stephg
Copy link

@stephg stephg commented Mar 8, 2017

Problem is that your Jenkins just does not support ANSI escape sequences in the console output. All output on STDERR in your Dockerfile is printed in red by docker build. So as mentioned by @tianon just use the AnsiColor+Plugin to fix this.

@chorrell
Copy link
Contributor

@chorrell chorrell commented Apr 7, 2017

Closing since #225 (comment) addresses the issue for the OP.

I don't think we can do anything about the Dockerhub (if that's still an issue)

@chorrell chorrell closed this Apr 7, 2017
@defaude
Copy link

@defaude defaude commented Jul 20, 2017

Hmm, I still have the exact same problem.

.npmrc:

color=false
progress=false

Dockerfile:

FROM node:8.1.4-alpine
COPY .npmrc .npmrc
# let's take a look at the config
RUN npm config ls -l

Now if I build the image like this:

docker build -t fancy-image-name .

Then the output is still showing colors even though the config says "color = false":

... truncated
Step 3/3 : RUN npm config ls -l
 ---> Running in 69e245ff6077
npm info it worked if it ends with ok
npm info using npm@5.0.3
npm info using node@v8.1.4
npm info ok
; cli configs
long = true
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.0.3 node/v8.1.4 linux x64"

; environment configs
loglevel = "info"

; project config /.npmrc
color = false
progress = false

; default values
... truncated
; color = true (overridden)
... truncated
; loglevel = "notice" (overridden)
... truncated
; long = false (overridden)
... truncated
; metrics-registry = null (overridden)
... truncated
; progress = true (overridden)
... truncated
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden)

The lines featuring npm info at the top are all in nice friendly red => they look like as if a cat walked over the keyboard when I look at the log in Jenkins...

@zsteinkamp
Copy link

@zsteinkamp zsteinkamp commented Oct 2, 2017

I noticed that npm outputs progress to STDERR. Redirecting STDERR to STDOUT in my Dockerfile fixed the output problem:
e.g. change this:
RUN npm install
to this:
RUN npm install 2>&1

@amcsi
Copy link

@amcsi amcsi commented Oct 14, 2017

@zsteinkamp Wow that magically worked :o

@chorrell
Copy link
Contributor

@chorrell chorrell commented Oct 15, 2017

Oh, this would be a really good thing to add to the docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.