Jenkins Nexus SonarQube Docker-Compose: Build The DevOps environment – Cool 4 Components!

You are currently viewing Jenkins Nexus SonarQube Docker-Compose: Build The DevOps environment – Cool 4 Components!
Share this post and Earn Free Points!

This is another my post in which I present how to build DevOps" env (Jenkins Nexus SonarQube Docker-Compose") in a simple way how to set up the environment using the benefits of Docker-Compose".

Introduction

Jenkins Nexus SonarQube Docker-Compose

This time we will focus on an example where we will configure an environment consisting of:

Jenkins

The leading open" source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

Jenkins" is an open-source automation server that is commonly used in DevOps" environments to automate the build, test, and deployment of software. It is designed to be highly extensible and provides a wide range of plugins that can be used to integrate with various tools and services.

In a DevOps" environment, Jenkins" is often used to automate the software delivery pipeline, enabling teams to build, test, and deploy software more quickly and efficiently. It can be used to automate tasks such as building and testing code, running static analysis tools, and deploying code to various environments.

Jenkins" is typically used in conjunction with other tools and services, such as version control systems (e.g. Git), continuous integration tools (e.g. Maven"), and containerization platforms (e.g. Docker"). It can be integrated with these tools using plugins or by using APIs or command-line tools.

Overall, Jenkins is a powerful tool that is widely used in DevOps environments to automate the software delivery process and improve the efficiency of software development teams".

SonarQube + PostgreSQL

SonarQube" is an automatic code review tool to detect bugs, vulnerabilities, and code smells in your code. It can integrate with your existing workflow to enable continuous code inspection across your project branches and pull requests.

PostgreSQL is a powerful, open" source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. –

Nexus

The free artifact repository with universal format support. Single source of truth for all of your components, binaries, and build artifacts. Efficiently distribute parts and containers to developers. Deployed at more than 100,000 organisations globally.

Build DevOps Environment

In the following steps we will build the DevOps" envronment using Docker-Compose".

Create Docker-Compose.yml File

version: "3"
services:
  jenkins:
    image: jenkinsci/blueocean
    container_name: jenkins
    environment:
      - DOCKER_HOST=tcp://localhost:2375
      - JENKINS_UC=http://updates.jenkins.io
      - JENKINS_UC_EXPERIMENTAL=http://updates.jenkins.io/experimental
      - JENKINS_INCREMENTALS_REPO_MIRROR=http://repo.jenkins-ci.org/incrementals
    user: root
    ports:
      - "8080:8080"
      - "8443:8443"
      - "50000:50000"  
    expose:
      - "8080"
    volumes:
      - jenkins-data:/var/jenkins_home
      - jenkins-home:/home


  nexus:
    image: sonatype/nexus3
    container_name: nexus
    volumes:
      - "nexus-data:/nexus-data"
    ports:
      - "8081:8081"
    expose:
      - "8081"

  sonarqube:
    image: sonarqube
    container_name: sonarqube
    ports:
      - "9000:9000"
    environment:
      - sonar.jdbc.url=jdbc:postgresql://db:5432/sonar
    volumes:
      - sonarqube_conf:/opt/sonarqube/conf
      - sonarqube_data:/opt/sonarqube/data
      - sonarqube_extensions:/opt/sonarqube/extensions

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

volumes:
  nexus-data: {}
  jenkins-data: {}
  jenkins-home: {}
  sonarqube_conf: {}
  sonarqube_data: {}
  sonarqube_extensions: {}
  postgresql: {}
  postgresql_data: {}

Check Container Status

Before we start the further part of the configuration, check that all containers are in “UP” status.

docker-compose ps
          Name                        Command               State                                    Ports                                  
--------------------------------------------------------------------------------------------------------------------------------------------
jenkins                    /sbin/tini -- /usr/local/b ...   Up      0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:8443->8443/tcp
jenkins_nexus_sonar_db_1   docker-entrypoint.sh postgres    Up      5432/tcp                                                                
nexus                      sh -c ${SONATYPE_DIR}/star ...   Up      0.0.0.0:8081->8081/tcp                                                  
sonarqube                  ./bin/run.sh                     Up      0.0.0.0:9000->9000/tcp 

Jenkins – First Run

The Jenkins" user" interface is available at: http://localhost:8080

At the first start we will be asked to enter the administrator password, which is saved in the file: /var/jenkins_home/secrets/initialAdminPassword, which is located on the container file system with Jenkins". To open" the contents of this file we must “enter” this container using SSH. To do this, run the following command from the terminal:

# docker exec -it <docker_container_name>  /bin/bash
docker exec -it jenkins /bin/bash

Once inside the container, run the command below. The string is our administrator password.

cat /var/jenkins_home/secrets/initialAdminPassword
1367d1e351194e839abb21682498e63d

Plugins Installation

Następnie zainstaluj sugerowane wtyczki. Jest to zbiór podstawowych rozszerzeń, które można traktować jako pakiet startowy.

And than:

Creating an Administrator Account

The next step is to create an administrator account".

After creating the admin account", we can fully use Jenkins".

Nexus – First Run

The Nexus" user" interface is available at: http://localhost:8081

When you try to log in for the first time, we will receive information that the admin user" password has been generated and is located under the path: /nexus-data/admin.password. Let’s check the password!

Using the command below we will enter to the Nexus" container.

docker exec -it nexus /bin/bash

cat /nexus-data/admin.password
05feffa3-f8e3-49ed-b765-002d6b90d2a5

We paste the above password into the login" form. Then we will be asked to set your password, which I encourage.

SonarQube – First Run

The SonarQube" user" interface is available at: http://localhost:9000

Click the “Log-in” button in the upper right corner. The default" administrator user" is admin and the password is also admin.

Summary

As you can see, creating an environment with Docker-Compose" is really easy. In a few minutes we can create and start using tools.

To sum up, below is a list of URLs to: Jenkins", Nexus" and SonarQube".

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

How useful was this post?

Click on a star to rate it!

Average rating 4.8 / 5. Vote count: 1331

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?