Skip to content

Commit 715f733

Browse files
authored
Create an image for quay.io (#14)
* quay * travis is not building
1 parent 8c5183d commit 715f733

File tree

7 files changed

+363
-11
lines changed

7 files changed

+363
-11
lines changed

.travis.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: java
2-
if: tag IS present OR NOT (branch == master)
2+
if: tag IS present OR (branch == master)
33
jdk:
44
- openjdk8
55
cache:
@@ -20,13 +20,18 @@ before_deploy:
2020
- export PLUGIN_JAR=$(ls target/sonar-auth-openshift-plugin*jar)
2121
- echo "deploying $PLUGIN_JAR to GitHub releases"
2222
deploy:
23-
provider: releases
24-
api_key: "${GITHUB_OAUTH_TOKEN}"
25-
file_glob: true
26-
file:
27-
- "${PLUGIN_JAR}"
28-
# - "target/site/jacoco/*"
29-
# - "target/dependency-check-report.html"
30-
skip_cleanup: true
31-
on:
32-
tags: true
23+
- provider: releases
24+
api_key: "${GITHUB_OAUTH_TOKEN}"
25+
file_glob: true
26+
file:
27+
- "${PLUGIN_JAR}"
28+
# - "target/site/jacoco/*"
29+
# - "target/dependency-check-report.html"
30+
skip_cleanup: true
31+
on:
32+
tags: true
33+
- provider: script
34+
skip_cleanup: true
35+
script: bash quay_io
36+
on:
37+
tags: true
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
apiVersion: v1
2+
kind: Template
3+
metadata:
4+
name: "sonarqube"
5+
objects:
6+
- apiVersion: v1
7+
kind: ServiceAccount
8+
metadata:
9+
annotations:
10+
serviceaccounts.openshift.io/oauth-redirectreference.sonarqube: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${ROUTE_NAME}"}}'
11+
name: sonarqube
12+
- apiVersion: v1
13+
kind: RoleBinding
14+
metadata:
15+
name: sonarqube_view
16+
roleRef:
17+
name: view
18+
subjects:
19+
- kind: ServiceAccount
20+
name: sonarqube
21+
- apiVersion: v1
22+
kind: PersistentVolumeClaim
23+
metadata:
24+
name: sonarqube-data
25+
spec:
26+
accessModes:
27+
- ReadWriteOnce
28+
resources:
29+
requests:
30+
storage: ${SONARQUBE_PERSISTENT_VOLUME_SIZE}
31+
status: {}
32+
- apiVersion: v1
33+
kind: ImageStream
34+
metadata:
35+
labels:
36+
name: "${NAME}"
37+
app: "${NAME}"
38+
name: "${NAME}"
39+
spec:
40+
tags:
41+
- annotations:
42+
openshift.io/imported-from: "${CONTAINER_IMAGE}"
43+
from:
44+
kind: DockerImage
45+
name: "${CONTAINER_IMAGE}"
46+
importPolicy: {}
47+
name: latest
48+
referencePolicy:
49+
type: Source
50+
- apiVersion: v1
51+
kind: DeploymentConfig
52+
metadata:
53+
generation: 1
54+
labels:
55+
app: sonarqube
56+
name: sonarqube
57+
spec:
58+
replicas: 1
59+
selector:
60+
app: sonarqube
61+
deploymentconfig: sonarqube
62+
strategy:
63+
activeDeadlineSeconds: 21600
64+
recreateParams:
65+
timeoutSeconds: 600
66+
post:
67+
execNewPod:
68+
command:
69+
- /bin/sh
70+
- -c
71+
- sleep 30 && curl http://admin:admin@sonarqube:9000/api/webhooks/create
72+
-X POST -d "name=jenkins&url=${JENKINS_URL}/sonarqube-webhook/"
73+
containerName: sonarqube
74+
failurePolicy: Abort
75+
type: Recreate
76+
template:
77+
metadata:
78+
annotations:
79+
openshift.io/generated-by: OpenShiftWebConsole
80+
labels:
81+
app: sonarqube
82+
deploymentconfig: sonarqube
83+
spec:
84+
containers:
85+
- env:
86+
- name: JDBC_URL
87+
value: jdbc:postgresql://sonardb:5432/sonar
88+
- name: JDBC_USERNAME
89+
valueFrom:
90+
secretKeyRef:
91+
key: database-user
92+
name: sonardb
93+
- name: JDBC_PASSWORD
94+
valueFrom:
95+
secretKeyRef:
96+
key: database-password
97+
name: sonardb
98+
- name: FORCE_AUTHENTICATION
99+
value: "true"
100+
- name: PROXY_HOST
101+
value: ${PROXY_HOST}
102+
- name: PROXY_PORT
103+
value: ${PROXY_PORT}
104+
- name: PROXY_USER
105+
value: ${PROXY_USER}
106+
- name: PROXY_PASSWORD
107+
value: ${PROXY_PASSWORD}
108+
imagePullPolicy: Always
109+
livenessProbe:
110+
failureThreshold: 3
111+
httpGet:
112+
path: /
113+
port: 9000
114+
scheme: HTTP
115+
initialDelaySeconds: 45
116+
periodSeconds: 10
117+
successThreshold: 1
118+
timeoutSeconds: 1
119+
name: sonarqube
120+
ports:
121+
- containerPort: 9000
122+
protocol: TCP
123+
readinessProbe:
124+
failureThreshold: 3
125+
httpGet:
126+
path: /
127+
port: 9000
128+
scheme: HTTP
129+
initialDelaySeconds: 10
130+
periodSeconds: 10
131+
successThreshold: 1
132+
timeoutSeconds: 1
133+
resources: {}
134+
terminationMessagePath: /dev/termination-log
135+
terminationMessagePolicy: File
136+
volumeMounts:
137+
- mountPath: /opt/sonarqube/data
138+
name: sonar-data
139+
dnsPolicy: ClusterFirst
140+
restartPolicy: Always
141+
schedulerName: default-scheduler
142+
securityContext: {}
143+
serviceAccount: sonarqube
144+
serviceAccountName: sonarqube
145+
terminationGracePeriodSeconds: 30
146+
volumes:
147+
- name: sonar-data
148+
persistentVolumeClaim:
149+
claimName: sonarqube-data
150+
test: false
151+
triggers:
152+
- imageChangeParams:
153+
automatic: true
154+
containerNames:
155+
- sonarqube
156+
from:
157+
kind: ImageStreamTag
158+
name: sonarqube:latest
159+
type: ImageChange
160+
- type: ConfigChange
161+
- apiVersion: v1
162+
kind: Route
163+
metadata:
164+
labels:
165+
app: sonarqube
166+
name: "${ROUTE_NAME}"
167+
spec:
168+
port:
169+
targetPort: 9000-tcp
170+
tls:
171+
termination: edge
172+
to:
173+
kind: Service
174+
name: sonarqube
175+
weight: 100
176+
wildcardPolicy: None
177+
- apiVersion: v1
178+
kind: Service
179+
metadata:
180+
labels:
181+
app: sonarqube
182+
name: sonarqube
183+
spec:
184+
ports:
185+
- name: 9000-tcp
186+
port: 9000
187+
protocol: TCP
188+
targetPort: 9000
189+
selector:
190+
deploymentconfig: sonarqube
191+
sessionAffinity: None
192+
type: ClusterIP
193+
parameters:
194+
- description: Database name for the Posgres Database to be used by Sonarqube
195+
displayName: Postgres database name
196+
name: POSTGRES_DATABASE_NAME
197+
value: sonar
198+
required: true
199+
- name: SONARQUBE_PERSISTENT_VOLUME_SIZE
200+
description: The persistent storage volume for SonarQube to use for plugins/config/logs/etc...
201+
displayName: SonarQube Storage Space Size
202+
required: true
203+
value: 5Gi
204+
- name: ROUTE_NAME
205+
value: sonarqube
206+
description: The name of the route for sonarqube
207+
displayName: SonarQube Route Name
208+
- name: SONAR_AUTOCREATE_USERS
209+
value: 'false'
210+
description: When using an external authentication system, should SonarQube automatically create accounts for users?
211+
displayName: Enable auto-creation of users from external authentication systems?
212+
required: true
213+
- name: PROXY_HOST
214+
description: Hostname of proxy server the SonarQube application should use to access the Internet
215+
displayName: Proxy server hostname/IP
216+
- name: PROXY_PORT
217+
description: TCP port of proxy server the SonarQube application should use to access the Internet
218+
displayName: Proxy server port
219+
- name: PROXY_USER
220+
description: Username credential when the Proxy Server requires authentication
221+
displayName: Proxy server username
222+
- name: PROXY_PASSWORD
223+
description: Password credential when the Proxy Server requires authentication
224+
displayName: Proxy server password
225+
- name: JENKINS_URL
226+
description: The Jenkins URL used for the webhook
227+
displayName: Jenkins URL
228+
value: http://jenkins
229+
- name: CONTAINER_IMAGE
230+
description: The Container Image to use for the ImageStream
231+
displayName: Nexus Container Image
232+
value: quay.io/mcanoy/labs-sonarqube:latest
233+
- name: NAME
234+
displayName: Name
235+
description: The name assigned to all objects and the resulting imagestream.
236+
required: true
237+
value: sonarqube

images/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM docker.io/sonarqube:latest
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+
RUN /opt/sonarqube/bin/plugins.sh $sonar_plugins
13+
ADD sonar-auth-openshift-plugin.jar /opt/sonarqube/extensions-init/plugins/
14+
RUN chown root:root /opt/sonarqube -R; \
15+
chmod 6775 /opt/sonarqube -R
16+
USER 1001

images/plugins.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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@[email protected]@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+
ls /opt/sonarqube/extensions-init/plugins/
38+
39+
rm -f /tmp/pluginList.txt

images/run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
6+
rm -rf /opt/sonarqube/data/plugins/sonar-auth-openshift-plugin*.jar
7+
8+
## If the mounted data volume is empty, populate it from the default data
9+
cp -a /opt/sonarqube/data-init/* /opt/sonarqube/data/
10+
11+
## Link the plugins directory from the mounted volume
12+
rm -rf /opt/sonarqube/extensions/plugins
13+
ln -s /opt/sonarqube/data/plugins /opt/sonarqube/extensions/plugins
14+
15+
mkdir -p /opt/sonarqube/data/plugins
16+
for I in $(ls /opt/sonarqube/extensions-init/plugins/*.jar);
17+
do
18+
TARGET_PATH=$(echo ${I} | sed 's@extensions-init/plugins@data/plugins@g')
19+
if ! [[ -e ${TARGET_PATH} ]]; then
20+
cp ${I} ${TARGET_PATH}
21+
fi
22+
done
23+
24+
if [ "${1:0:1}" != '-' ]; then
25+
exec "$@"
26+
fi
27+
28+
java -jar lib/sonar-application-$SONAR_VERSION.jar \
29+
-Dsonar.web.javaAdditionalOpts="${SONARQUBE_WEB_JVM_OPTS} -Djava.security.egd=file:/dev/./urandom" \
30+
"$@"

images/sonar.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sonar.log.console=true
2+
sonar.jdbc.username=${env:JDBC_USERNAME}
3+
sonar.jdbc.password=${env:JDBC_PASSWORD}
4+
sonar.jdbc.url=${env:JDBC_URL}
5+
sonar.forceAuthentication=${env:FORCE_AUTHENTICATION}
6+
sonar.authenticator.createUsers=${env:SONAR_AUTOCREATE_USERS}
7+
sonar.log.level=${env:SONAR_LOG_LEVEL}
8+
http.proxyHost=${env:PROXY_HOST}
9+
http.proxyPort=${env:PROXY_PORT}
10+
http.proxyUser=${env:PROXY_USER}
11+
http.proxyPassword=${env:PROXY_PASSWORD}
12+
kubernetes.service=https://${env:KUBERNETES_SERVICE_HOST}:${env:KUBERNETES_SERVICE_PORT}/
13+
sonar.auth.openshift.isEnabled=true
14+
sonar.auth.openshift.button.color=#000000
15+
sonar.auth.openshift.sar.groups=sonarqube_admin=sonar-administrators,sonarqube_user=sonar-users
16+
ignore.certs=false
17+
#oauth.cert=/opt/sonarqube/conf/oauth.crt
18+
sonar.search.javaAdditionalOpts=-Dnode.store.allow_mmapfs=false
19+
#sonar.auth.openshift.route.name=customname

quay_io

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cp $PLUGIN_JAR images/
2+
cd images
3+
QUAY_OWNER=$(echo $TRAVIS_REPO_SLUG | cut -d/ -f1)
4+
docker build -t quay.io/$QUAY_OWNER/labs-sonarqube:$TRAVIS_BRANCH -t quay.io/$QUAY_OWNER/labs-sonarqube:latest .
5+
echo "$QUAY_BOT_PASSWORD" | docker login -u "$QUAY_BOT_USERNAME" --password-stdin quay.io
6+
docker push quay.io/$QUAY_OWNER/labs-sonarqube

0 commit comments

Comments
 (0)