Skip to content

Commit 9ed5296

Browse files
authored
Merge pull request #6 from stakater-docker/use-base-sonarqube
Use base sonarqube
2 parents 87fffed + 828a699 commit 9ed5296

File tree

8 files changed

+115
-282
lines changed

8 files changed

+115
-282
lines changed

Dockerfile

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,17 @@
1-
FROM stakater/java-centos:7-1.8
2-
3-
ENV SONAR_VERSION=7.1 \
4-
SONARQUBE_HOME=/opt/app/sonarqube \
5-
# Database configuration
6-
# Defaults to using H2
7-
SONARQUBE_JDBC_USERNAME=sonar \
8-
SONARQUBE_JDBC_PASSWORD=sonar \
9-
SONARQUBE_JDBC_URL= \
10-
CONF_MOUNT_PATH="/opt/app/tmp/conf/sonar.properties"
11-
12-
# Comma separated list of Plugin URLS to install
13-
ARG PLUGIN_URLS="https://github.com/vaulttec/sonar-auth-oidc/releases/download/v1.0.4/sonar-auth-oidc-plugin-1.0.4.jar"
14-
15-
# Change to user root to install jdk, cant install it with any other user
16-
USER root
17-
RUN yum install -y unzip && \
18-
yum clean all
19-
20-
RUN set -x \
21-
# pub 2048R/D26468DE 2015-05-25
22-
# Key fingerprint = F118 2E81 C792 9289 21DB CAB4 CFCA 4A29 D264 68DE
23-
# uid sonarsource_deployer (Sonarsource Deployer) <infra@sonarsource.com>
24-
# sub 2048R/06855C1D 2015-05-25
25-
&& (gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F1182E81C792928921DBCAB4CFCA4A29D26468DE \
26-
|| gpg --keyserver ipv4.pool.sks-keyservers.net --recv-keys F1182E81C792928921DBCAB4CFCA4A29D26468DE) \
27-
&& curl -o sonarqube.zip -fSL https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip \
28-
&& curl -o sonarqube.zip.asc -fSL https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip.asc \
29-
&& gpg --batch --verify sonarqube.zip.asc sonarqube.zip \
30-
&& unzip sonarqube.zip \
31-
&& mv sonarqube-$SONAR_VERSION sonarqube \
32-
&& rm sonarqube.zip* \
33-
&& rm -rf $SONARQUBE_HOME/bin/*
34-
35-
# Download plugins from list
36-
RUN mkdir -p ${HOME}/downloads/plugins \
37-
&& cd ${HOME}/downloads/plugins \
38-
&& IFS=, read -ra pluginUrlList <<< "$PLUGIN_URLS" \
39-
&& for plugin_url in "${pluginUrlList[@]}"; \
40-
do \
41-
wget "${plugin_url}"; \
42-
done
43-
44-
# Add Plugins as jar files
45-
ADD plugins/* ${HOME}/downloads/plugins/
46-
47-
RUN chown -R 10001 $SONARQUBE_HOME \
48-
&& chown -R 10001 ${HOME}/downloads/
49-
50-
# Again using non-root user i.e. stakater as set in base image
51-
USER 10001
52-
53-
# Http port
54-
EXPOSE 9000
55-
56-
WORKDIR $SONARQUBE_HOME
57-
COPY run.sh $SONARQUBE_HOME/bin/
58-
ENTRYPOINT ["./bin/run.sh"]
1+
FROM docker.io/sonarqube:7.9.1-community
2+
3+
USER root
4+
ARG sonar_plugins="pmd ldap"
5+
ADD sonar.properties /opt/sonarqube/conf/sonar.properties
6+
ADD run.sh /opt/sonarqube/bin/run.sh
7+
CMD /opt/sonarqube/bin/run.sh
8+
RUN cp -a /opt/sonarqube/data /opt/sonarqube/data-init && \
9+
cp -a /opt/sonarqube/extensions /opt/sonarqube/extensions-init && \
10+
chown root:root /opt/sonarqube && chmod -R gu+rwX /opt/sonarqube
11+
ADD plugins.sh /opt/sonarqube/bin/plugins.sh
12+
ADD https://github.com/rht-labs/sonar-auth-openshift/releases/latest/download/sonar-auth-openshift-plugin.jar /opt/sonarqube/extensions-init/plugins/
13+
ADD https://github.com/dmeiners88/sonarqube-prometheus-exporter/releases/download/v1.0.0-SNAPSHOT-2018-07-04/sonar-prometheus-exporter-1.0.0-SNAPSHOT.jar /opt/sonarqube/extensions-init/plugins/
14+
RUN /opt/sonarqube/bin/plugins.sh $sonar_plugins
15+
RUN chown root:root /opt/sonarqube -R; \
16+
chmod 6775 /opt/sonarqube -R
17+
USER 1001

Jenkinsfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env groovy
2-
@Library('github.com/stakater/fabric8-pipeline-library@v2.9.4') _
2+
@Library('github.com/stakater/stakater-pipeline-library@v2.16.35') _
33

44
pushDockerImage {
5-
dockerRegistryURL = "docker.io"
6-
imagePrefix = "7.1-jdk1.8-centos7"
7-
}
5+
dockerRepositoryURL = "docker.io"
6+
imagePrefix = "7.9.1-community-jdk11.0.5-debian10"
7+
}

LICENSE

Lines changed: 0 additions & 201 deletions
This file was deleted.

plugins.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
# set -x ## Uncomment for debugging
5+
6+
printf 'Downloading plugin details\n'
7+
8+
## Extract sonarqube version
9+
export SQ_VERSION=$(ls /opt/sonarqube/lib/sonar-application* | awk -F"-" '{print $3}' | sed 's@\.jar$@@g')
10+
echo "SONARQUBE_VERSION: ${SQ_VERSION}"
11+
12+
13+
curl -L -sS -o /tmp/pluginList.txt https://update.sonarsource.org/update-center.properties
14+
printf "Downloading additional plugins\n"
15+
for PLUGIN in "$@"
16+
do
17+
printf '\tExtracting plugin download location - %s\n' ${PLUGIN}
18+
MATCH_STRING=$(cat /tmp/pluginList.txt | grep requiredSonarVersions | grep -E "[,=]${SQ_VERSION}(,|$)" | sed 's@\.requiredSonarVersions.*@@g' | sort -V | grep "^${PLUGIN}\." | tail -n 1 | sed 's@$@.downloadUrl@g')
19+
20+
if ! [[ -z "${MATCH_STRING}" ]]; then
21+
DOWNLOAD_URL=$(cat /tmp/pluginList.txt | grep ${MATCH_STRING} | awk -F"=" '{print $2}' | sed 's@\\:@:@g')
22+
PLUGIN_FILE=$(echo ${DOWNLOAD_URL} | sed 's@.*/\(.*\)$@\1@g')
23+
24+
## Check to see if plugin exists, attempt to download the plugin if it does exist.
25+
if ! [[ -z "${DOWNLOAD_URL}" ]]; then
26+
curl -L -sS -o /opt/sonarqube/extensions-init/plugins/${PLUGIN_FILE} ${DOWNLOAD_URL} && printf "\t\t%-35s%10s" "${PLUGIN_FILE}" "DONE" || printf "\t\t%-35s%10s" "${PLUGIN_FILE}" "FAILED"
27+
printf "\n"
28+
else
29+
## Plugin was not found in the plugin inventory
30+
printf "\t\t%-15s%10s\n" "${PLUGIN}" "NOT FOUND"
31+
fi
32+
else
33+
printf "\t\t%-15s%10s\n" $PLUGIN "NOT FOUND"
34+
fi
35+
done
36+
37+
rm -f /tmp/pluginList.txt
-4.24 MB
Binary file not shown.

requirements.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is the Ansible Galaxy requirements file to pull in the correct roles
2+
# to support the operation of CASL provisioning/runs.
3+
4+
# From 'openshift-applier'
5+
- name: openshift-applier
6+
scm: git
7+
src: https://github.com/redhat-cop/openshift-applier
8+
version: v2.1.1

run.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#!/bin/bash
22

3+
set -x
34
set -e
45

5-
if [ "${1:0:1}" != '-' ]; then
6-
exec "$@"
7-
fi
6+
## If the mounted data volume is empty, populate it from the default data
7+
cp -a /opt/sonarqube/data-init/* /opt/sonarqube/data/
88

9-
# Create extensions directories to enable usage after volume mounting
10-
mkdir -p ${SONARQUBE_HOME}/extensions/plugins ${SONARQUBE_HOME}/extensions/jdbc-driver
9+
## Link the plugins directory from the mounted volume
10+
rm -rf /opt/sonarqube/extensions/plugins
11+
ln -s /opt/sonarqube/data/plugins /opt/sonarqube/extensions/plugins
1112

12-
# Install plugins from download dir
13-
mv ${HOME}/downloads/plugins/* ${SONARQUBE_HOME}/extensions/plugins
13+
mkdir -p /opt/sonarqube/data/plugins
14+
for I in $(ls /opt/sonarqube/extensions-init/plugins/*.jar);
15+
do
16+
TARGET_PATH=$(echo ${I} | sed 's@extensions-init/plugins@data/plugins@g')
17+
if ! [[ -e ${TARGET_PATH} ]]; then
18+
cp ${I} ${TARGET_PATH}
19+
fi
20+
done
1421

15-
# Move conf from temp mount path to conf location
16-
if [ -f ${CONF_MOUNT_PATH} ];
17-
then
18-
rm -f ${SONARQUBE_HOME}/conf/sonar.properties
19-
mv ${CONF_MOUNT_PATH} ${SONARQUBE_HOME}/conf/
22+
if [ "${1:0:1}" != '-' ]; then
23+
exec "$@"
2024
fi
2125

22-
exec java -jar lib/sonar-application-$SONAR_VERSION.jar \
23-
-Dsonar.log.console=true \
24-
-Dsonar.jdbc.username="$SONARQUBE_JDBC_USERNAME" \
25-
-Dsonar.jdbc.password="$SONARQUBE_JDBC_PASSWORD" \
26-
-Dsonar.jdbc.url="$SONARQUBE_JDBC_URL" \
27-
-Dsonar.web.javaAdditionalOpts="$SONARQUBE_WEB_JVM_OPTS -Djava.security.egd=file:/dev/./urandom" \
28-
"$@"
26+
java -jar lib/sonar-application-$SONAR_VERSION.jar \
27+
-Dsonar.web.javaAdditionalOpts="${SONARQUBE_WEB_JVM_OPTS} -Djava.security.egd=file:/dev/./urandom" \
28+
"$@"

0 commit comments

Comments
 (0)