diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..7767b6b --- /dev/null +++ b/.env.dist @@ -0,0 +1,5 @@ +SONAR_FQDN='example.com' + +POSTGRES_USERNAME='CHANGEME' + +POSTGRES_PASSWORD='CHANGEME' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..7356467 --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Guillaume 'B.B.' Van Hemmen + +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. diff --git a/README.md b/README.md index 2155120..4c99ddd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ # SonarQube -SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs and code smells on 29 programming languages. SonarQube offers reports on duplicated code, coding standards, unit tests, code coverage, code complexity, comments, bugs, and security recommendations. SonarQube provides automated analysis and integration with Maven, Ant, Gradle, MSBuild, and continuous integration tools. \ No newline at end of file +## Introduction + +This project provides a Docker Compose setup for quickly setting up a SonarQube instance. SonarQube is an open-source +platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect +bugs, code smells, and security vulnerabilities. + +## Table of contents + +1. [Introduction](#introduction) +2. [Table of contents](#table-of-contents) +3. [Prerequisites](#prerequisites) +4. [Installation](#installation) +5. [Usage](#usage) +6. [License](#license) + +## Prerequisites + +- Docker: Make sure Docker is installed and running on your system. +- Docker Compose: You also need Docker Compose to orchestrate the container setup. +- To have + deployed [Traefik standalone](https://git.van-hemmen.com/GuillaumeHemmen-DockerCompose-Infra/traefik-standalone) + or [Traefik Authelia](https://git.van-hemmen.com/GuillaumeHemmen-DockerCompose-Infra/traefik-authelia) + +## Installation + +1. Clone the repository: + + ```bash + git clone https://git.van-hemmen.com/GuillaumeHemmen-DockerCompose-Infra/sonarqube.git + cd sonarqube + ``` + +2. Copy the environment variable template: + + ```bash + cp .env.dist .env + ``` + +3. Customize the `.env` file as necessary for your environment. + +## Usage + +Start the Traefik service with Docker Compose: + + ```bash + docker compose up -d + ``` + +Access SonarQube by navigating to `https://` in your web browser. + +## License + +This project is licensed under the terms of the MIT license. See the [LICENSE](LICENCE) file for details. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..125bf9d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,60 @@ +networks: + network: + traefik_network: + external: true + +volumes: + postgresql: + postgresql_data: + + +services: + app: + image: sonarqube:10.4-community + depends_on: + postgresql: + condition: service_healthy + labels: + - "traefik.docker.network=traefik_network" + - "traefik.enable=true" + - "traefik.http.routers.sonarqube.rule=Host(`${SONAR_FQDN}`)" + - "traefik.http.routers.sonarqube.entrypoints=websecure" + - "traefik.http.routers.sonarqube.tls.certresolver=myresolver" + networks: + - traefik_network + - network + volumes: + # https://github.com/mc1arke/sonarqube-community-branch-plugin + - ./plugins/sonarqube-community-branch-plugin-1.19.0.jar:/opt/sonarqube/extensions/plugins/sonarqube-branch-plugin.jar + environment: + - SONAR_JDBC_USERNAME=${POSTGRES_USERNAME} + - SONAR_JDBC_PASSWORD=${POSTGRES_PASSWORD} + - SONAR_JDBC_URL=jdbc:postgresql://postgresql:5432/sonar + - SONAR_WEB_JAVAADDITIONALOPTS=-javaagent:./extensions/plugins/sonarqube-branch-plugin.jar=web + - SONAR_CE_JAVAADDITIONALOPTS=-javaagent:./extensions/plugins/sonarqube-branch-plugin.jar=ce + deploy: + replicas: 1 + restart_policy: + condition: any + delay: 5s + + postgresql: + image: postgres:11 + networks: + - network + environment: + - POSTGRES_USER=${POSTGRES_USERNAME} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + volumes: + - postgresql:/var/lib/postgresql + - postgresql_data:/var/lib/postgresql/data + deploy: + replicas: 1 + restart_policy: + condition: any + delay: 5s + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-U", "$${POSTGRES_USERNAME}", "-d", "sonar" ] + interval: 1s + timeout: 5s + retries: 10 diff --git a/plugins/sonarqube-community-branch-plugin-1.19.0.jar b/plugins/sonarqube-community-branch-plugin-1.19.0.jar new file mode 100644 index 0000000..95861f1 Binary files /dev/null and b/plugins/sonarqube-community-branch-plugin-1.19.0.jar differ