From 74e9c5fe3b343ba3e0a4e0859b8568cd55a3a4ac Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Mon, 8 Mar 2021 19:16:12 +0000 Subject: [PATCH] Add ability to generate Docker Image containing plugin This change adds the relevant docker files to allow building a development docker image containing the code in this repository, or generating an image using a released version of the plugin, with either of these being backed by a particular base Docker image of Sonarqube's community releases. The `.env` file contains the variables required to configure what builds is performed with docker-compose.yml then driving the relevant creation from there. --- .dockerignore | 4 ++++ .env | 8 ++++++++ Dockerfile | 11 +++++++++++ README.md | 40 ---------------------------------------- docker-compose.yml | 45 +++++++++++++++++++++++++++++++++++++++++++++ release.Dockerfile | 9 +++++++++ 6 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 .dockerignore create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 release.Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..dfe1d7365 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +/build/ +/.idea/ +/.gradle/ +/out/ diff --git a/.env b/.env new file mode 100644 index 000000000..e3e8c31d7 --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +# The Sonarqube base image. 'latest' if building locally, '8.5-community' if targeting a specific version +SONARQUBE_VERSION=latest + +# The name of the Dockerfile to run. 'Dockerfile' is building locally, 'release.Dockerfile' if building the release image +DOCKERFILE=Dockerfile + +# The version of the plugin to include in the image; only relevant if 'release.Dockerfile' is being used +PLUGIN_VERSION=1.6.0 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4466e827e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +ARG SONARQUBE_VERSION + +FROM openjdk:11-jdk-slim as builder + +COPY . /home/build/project +WORKDIR /home/build/project +RUN ./gradlew build -x test + +FROM sonarqube:${SONARQUBE_VERSION} +COPY --from=builder --chown=sonarqube:sonarqube /home/build/project/build/libs/sonarqube-community-branch-plugin-*.jar /opt/sonarqube/lib/common/ +COPY --from=builder --chown=sonarqube:sonarqube /home/build/project/build/libs/sonarqube-community-branch-plugin-*.jar /opt/sonarqube/extensions/plugins/ diff --git a/README.md b/README.md index c9133e0dd..769aa4a9f 100644 --- a/README.md +++ b/README.md @@ -26,46 +26,6 @@ The plugin is intended to support the [features and parameters specified in the # Installation Either build the project or [download a compatible release version of the plugin JAR](https://github.com/mc1arke/sonarqube-community-branch-plugin/releases). Copy the plugin JAR file to the `extensions/plugins/` **and** the `lib/common/` directories of your SonarQube instance and restart SonarQube. -## Installation Docker -Add download the plugin and mount it to the container see the last two volumes in the yaml below. -``` -version: 2 - -services: - sonarqube: - image: sonarqube:lts - container_name: sonarqube - ports: - - 9000:9000 - networks: - - sonarnet - environment: - - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar - - SONARQUBE_JDBC_USERNAME=sonar - - SONARQUBE_JDBC_PASSWORD=sonar - volumes: - - sonarqube_conf:/opt/sonarqube/conf - - sonarqube_data:/opt/sonarqube/data - - sonarqube_extensions:/opt/sonarqube/extensions - - sonarqube_bundled-plugins:/opt/sonarqube/lib/bundled-plugins - - /home/user/sonarqube-community-branch-plugin-X.X.X.jar:/opt/sonarqube/extensions/plugins/sonarqube-community --branch-plugin.jar - - /home/user/sonarqube-community-branch-plugin-X.X.X.jar:/opt/sonarqube/lib/common/sonarqube-community-branch --plugin.jar - - db: - image: postgres - container_name: postgres - networks: - - sonarnet - environment: - - POSTGRES_USER=sonar - - POSTGRES_PASSWORD=sonar - volumes: - - postgresql:/var/lib/postgresql - - postgresql_data:/var/lib/postgresql/data -``` - # Configuration ## Global configuration Make sure `sonar.core.serverBaseURL` in SonarQube [/admin/settings](http://localhost:9000/admin/settings) is properly diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..8070b31cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,45 @@ +version: "3.8" + +services: + sonarqube: + depends_on: + - db + image: mc1arke/sonarqube-with-community-branch-plugin:${SONARQUBE_VERSION} + build: + context: . + dockerfile: ${DOCKERFILE} + args: + SONARQUBE_VERSION: ${SONARQUBE_VERSION} + PLUGIN_VERSION: ${PLUGIN_VERSION} + container_name: sonarqube + ports: + - 9000:9000 + networks: + - sonarnet + environment: + - SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar + - SONARQUBE_JDBC_USERNAME=sonar + - SONARQUBE_JDBC_PASSWORD=sonar + volumes: + - sonarqube_conf:/opt/sonarqube/conf + - sonarqube_data:/opt/sonarqube/data + db: + image: postgres:11 + container_name: postgres + networks: + - sonarnet + environment: + - POSTGRES_USER=sonar + - POSTGRES_PASSWORD=sonar + volumes: + - postgresql:/var/lib/postgresql + - postgresql_data:/var/lib/postgresql/data + +volumes: + sonarqube_conf: + sonarqube_data: + postgresql: + postgresql_data: + +networks: + sonarnet: diff --git a/release.Dockerfile b/release.Dockerfile new file mode 100644 index 000000000..46e272b8c --- /dev/null +++ b/release.Dockerfile @@ -0,0 +1,9 @@ +ARG SONARQUBE_VERSION + +FROM sonarqube:${SONARQUBE_VERSION} + +ARG PLUGIN_VERSION +ENV PLUGIN_VERSION=${PLUGIN_VERSION} + +ADD --chown=sonarqube:sonarqube https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/${PLUGIN_VERSION}/sonarqube-community-branch-plugin-${PLUGIN_VERSION}.jar /opt/sonarqube/lib/common/ +ADD --chown=sonarqube:sonarqube https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/${PLUGIN_VERSION}/sonarqube-community-branch-plugin-${PLUGIN_VERSION}.jar /opt/sonarqube/extensions/plugins/