Install Node.Js in a Sonarqube instance on the docker-compose

时光怂恿深爱的人放手 提交于 2020-01-25 07:05:12

问题


so I'm trying to launch SonarQube on the docker through docker-compose. This is my .yml file:

version: "3"


services:
  sonarqube:
    image: sonarqube
    ports:
     - "9000:9000"
     - "5432:5432"
    links:
      - db:db
    environment:
     - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
     - SONARQUBE_JDBC_USERNAME=postgres
     - SONARQUBE_JDBC_PASSWORD=sonar
    volumes:
     - ..../Work/tools/_SonarQube_home/conf:/opt/sonarqube/conf
#     - sonarqube_data:/opt/sonarqube_new/data
     - ...../Work/tools/_SonarQube_home/data:/opt/sonarqube/data
     - ....../Work/tools/_SonarQube_home/extensions:/opt/sonarqube/extensions
     - ..../Work/tools/_SonarQube_home/bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  db:
    image: postgres
    environment:
     - POSTGRES_USER=postgres
     - POSTGRES_PASSWORD=sonar
     - POSTGRES_DB=sonar
    volumes:
     - .../Work/tools/_PostgreSQL_data:/var/lib/postgresql
     # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
     - ..../Work/tools/_PostgreSQL_data/data:/var/lib/postgresql/data

Everything boots up and works kind of correctly. Then I'm lauching the analysis of the project and get this error:

INFO: Sensor JavaScript analysis [javascript]
ERROR: Failed to parse Node.js version, got 'Couldn't find the Node.js binary. Ensure you have Node.js installed.

If this would be regular install, I'd just add NodeJs, but it's docker.

How should I fix this? Thanks!


回答1:


Unless there are pre-build images out there for SonarQube with NodeJS installed, you could make your own custom image. It would look something like below:

./app/Dockerfile

FROM sonarqube

USER root
RUN apt-get update && apt-get install nodejs npm -y
USER sonarqube
version: "3"


services:
  sonarqube:
    build: ./app
    ports:
     - "9000:9000"
     - "5432:5432"
    links:
      - db:db
    environment:
     - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar
     - SONARQUBE_JDBC_USERNAME=postgres
     - SONARQUBE_JDBC_PASSWORD=sonar
    volumes:
     - ..../Work/tools/_SonarQube_home/conf:/opt/sonarqube/conf
#     - sonarqube_data:/opt/sonarqube_new/data
     - ...../Work/tools/_SonarQube_home/data:/opt/sonarqube/data
     - ....../Work/tools/_SonarQube_home/extensions:/opt/sonarqube/extensions
     - ..../Work/tools/_SonarQube_home/bundled-plugins:/opt/sonarqube/lib/bundled-plugins

  db:
    image: postgres
    environment:
     - POSTGRES_USER=postgres
     - POSTGRES_PASSWORD=sonar
     - POSTGRES_DB=sonar
    volumes:
     - .../Work/tools/_PostgreSQL_data:/var/lib/postgresql
     # This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
     - ..../Work/tools/_PostgreSQL_data/data:/var/lib/postgresql/data

You could then build and startup the new images:

docker-compose build
docker-compose up -d

Test if node is installed:

docker-compose exec sonarqube node -v
docker-compose exec sonarqube npm -v



回答2:


Thank you guys for the answers, especially @leeman24, that is awesome insight how to deal with docker images.

Although the real solution turned out to be installing NodeJS on MY machine, not the scanner server machine. In other words, server is fine out of the box.



来源:https://stackoverflow.com/questions/58950485/install-node-js-in-a-sonarqube-instance-on-the-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!