Git Product home page Git Product logo

docker-sonarqube's Introduction

Table of Contents

Introduction

Dockerfile to build a SonarQube container image.

Version

Current Version: 5.6

Dependencies

Before you start, you need to make sure you have the following dependencies installed:

Now you can verify that the installation is ok with the following commands:

docker version
docker-compose --version

Reporting Issues

If you have any issues you can report them on the issues page.

In your report please make sure to add:

  • Output of the docker version command
  • The exact docker run or docker-compose command you used (mask any sensitive info)

Installation

Pull the image from the docker index. This is the recommended method of installation as it is easier to update image in the future. These builds are performed by the Trusted Build service.

docker pull harbur/sonarqube:latest

The image builds are being tagged. You can pull a particular version of SonarQube by specifying the version number. For example,

docker pull harbur/sonarqube:5.6

Alternately you can build the image yourself if you run 5.6.

git clone https://github.com/harbur/docker-sonarqube.git
cd docker-sonarqube
docker build --tag="$USER/sonarqube" .

Quick Start

Run the SonarQube with Docker Compose. Docker Compose uses a docker-compose.yml file that describes the environment.

git clone https://github.com/harbur/docker-sonarqube.git
cd docker-sonarqube
docker-compose up

NOTE: It will build Sonar 5.6 container. If you want to run pre build 5.1, please edit the docker-compose.yml accordingly.

NOTE: Please allow a minute or two for the SonarQube application to start.

On another console run:

make port

Point your browser to the given URL and login using the default username and password:

  • username: admin
  • password: admin

You should now have the SonarQube application up and ready for testing. If you want to use this image in production the please read on.

Configuration

Database

SonarQube uses PostgreSQL database backend to store its data. Database is launched as separate container and the linking is handled by Docker Compose.

The DB container is configured to create automatically the user and the database. The user credentials, database name and the database hostname are all injected to the SonarQube container by docker-compose using environment variables and container links.

The SonarQube container does not contain database by itself, there is no simple-container scenario. It needs to run with docker-compose commands (or you can craft manually the docker commands). This makes it a lot more portable, and follows the Single Responsibility Principle and aligns well with the Service-oriented Architecture design pattern. This works seamlessly in the simple-host / multi-container scenario. The multi-host / multi-container scenario is explained later on.

The database used is orchardup/postgresql and uses a Volume to store the database (/var/lib/postgresql) separately from the container instance.

Data Store

The Postgresql database container is configured to persist data inside a Volume: /var/lib/postgresql.

If you want to mount the volume locally, you can append the following lines at the docker-compose.yml inside the postgres section:

NOTE: If you mount the volume locally, you'll singularize your setup, making all instances point to the same directory, safe if you want only one SonarQube instance.

  volumes:
    - /opt/db/sonarqube/:/var/lib/postgresql

Connect with a PostgreSQL client

In order to connect to the database you can do the following:

docker-compose up -d postgresql
docker-compose run postgresql bash -c 'PGPASSWORD=$POSTGRESQL_PASS psql -h $POSTGRESQL_1_PORT_5432_TCP_ADDR $POSTGRESQL_DB $POSTGRESQL_USER'

This will launch the database of PostgreSQL (first command) and then connect to the database with a client (second command). The containers are linked together automatically by docker-compose and the variables are used to pass the connection info.

Shell Access

For debugging and maintenance purposes you may want access the container shell. Since the container does not include a SSH server, you can use the nsenter linux tool (part of the util-linux package) to access the container shell.

Some linux distros (e.g. ubuntu) use older versions of the util-linux which do not include the nsenter tool. To get around this @jpetazzo has created a nice docker image that allows you to install the nsenter utility and a helper script named docker-enter on these distros.

To install the nsenter tool on your host execute the following command.

docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter

Now you can access the container shells using the following commands

sudo docker-enter dockersonarqube_sonarqube_1
sudo docker-enter dockersonarqube_postgresql_1

For more information refer https://github.com/jpetazzo/nsenter

Another tool named nsinit can also be used for the same purpose. Please refer https://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/ for more information.

References

Credits

Inspired by docker-gitlab and docker-redmine

License

docker-sonarqube is available under the MIT license.

Copyright © 2014-2015 Harbur.io

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

docker-sonarqube's People

Contributors

dkapanidis avatar jugalps avatar sebastien-meiffren avatar spiddy avatar

Watchers

 avatar  avatar

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.