Skip to content

Commit

Permalink
Add ability to generate Docker Image containing plugin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mc1arke committed Mar 30, 2021
1 parent a8dca45 commit 74e9c5f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build/
/.idea/
/.gradle/
/out/
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
40 changes: 0 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 9 additions & 0 deletions release.Dockerfile
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 74e9c5f

Please sign in to comment.