Skip to content

Commit 3e38378

Browse files
authored
Add SonarQube analysis (#25)
* Add SonarQube scanning to CI/CD pipeline * Enable shell scanning * Enable Docker and GitHub actions scanning * Have packages listed alphabetically (docker:S7018) * Prefer COPY to ADD (docker:S7029) * Enclose variables in double quotes (docker:S6570) * Make return values explicit when appropriate (shelldre:S7682) and better report some errors
1 parent 66d32b3 commit 3e38378

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

.github/workflows/proxy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,8 @@ jobs:
9292
- name: Inspect Anchore scan SARIF report
9393
if: ${{ !cancelled() }}
9494
run: cat ${{ steps.anchore-scan.outputs.sarif }}
95+
96+
- name: SonarQube Scan
97+
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
98+
env:
99+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Dockerfile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ ENV CHROOT_DIR=/etc/haproxy/webroot
6161

6262
# Install certbot and Route53 DNS plugin
6363
RUN apk update \
64-
&& apk add --no-cache certbot py-pip inotify-tools tar curl openssl \
64+
&& apk add --no-cache certbot curl inotify-tools openssl py-pip tar \
6565
&& rm -f /var/cache/apk/* \
6666
&& pip install certbot-dns-route53 --break-system-packages
6767

6868
# Add ACME LUA plugin
6969
ADD acme-plugin.tar.gz /etc/haproxy/lua/
7070

71-
RUN mkdir -p ${CHROOT_DIR} \
72-
&& mkdir -p ${CERT_DIR} \
71+
RUN mkdir -p "${CHROOT_DIR}" \
72+
&& mkdir -p "${CERT_DIR}" \
7373
&& mkdir -p /var/log/letsencrypt \
74-
&& mkdir -p ${LE_DIR} && chown haproxy:haproxy ${LE_DIR} \
74+
&& mkdir -p "${LE_DIR}" && chown haproxy:haproxy "${LE_DIR}" \
7575
&& mkdir -p /etc/letsencrypt \
7676
&& mkdir -p /var/lib/letsencrypt \
7777
&& touch /etc/periodic/daily/cert-renew \
@@ -81,18 +81,18 @@ RUN mkdir -p ${CHROOT_DIR} \
8181
&& chown -R haproxy:haproxy /etc/haproxy \
8282
&& chown -R haproxy:haproxy /var/lib/letsencrypt \
8383
&& chown -R haproxy:haproxy /var/log/letsencrypt \
84-
&& chown -R haproxy:haproxy ${CHROOT_DIR} \
85-
&& chown -R haproxy:haproxy ${CERT_DIR}
84+
&& chown -R haproxy:haproxy "${CHROOT_DIR}" \
85+
&& chown -R haproxy:haproxy "${CERT_DIR}"
8686

8787
RUN apk del tar && \
8888
rm -f /var/cache/apk/*
8989

90-
ADD haproxy.cfg /etc/haproxy/haproxy.cfg
91-
ADD haproxy-edge-terminated-tls.cfg /etc/haproxy/haproxy-edge-terminated-tls.cfg
92-
ADD certs /etc/haproxy/certs
90+
COPY haproxy.cfg /etc/haproxy/haproxy.cfg
91+
COPY haproxy-edge-terminated-tls.cfg /etc/haproxy/haproxy-edge-terminated-tls.cfg
92+
COPY certs /etc/haproxy/certs
9393

94-
ADD cli.ini /root/.config/letsencrypt/
95-
ADD entrypoint.sh /
94+
COPY cli.ini /root/.config/letsencrypt/
95+
COPY entrypoint.sh /
9696
RUN chmod +x /entrypoint.sh
9797

9898
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=10 CMD curl --fail --silent "http://127.0.0.1:${HTTP_PORT}/docker-health" || exit 1

entrypoint.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ restart() {
140140
if check_proxy; then
141141
log_info "Config is valid so requesting restart..."
142142
$HAPROXY_RESTART_CMD
143-
else
144-
log_info "HAProxy config invalid, not restarting..."
143+
return $?
145144
fi
145+
146+
log_info "HAProxy config invalid, not restarting..."
147+
return 1
146148
}
147149

148150
start_monitor() {
@@ -423,7 +425,7 @@ cert_init() {
423425
sync_haproxy() {
424426
if [ -z "$RENEWED_LINEAGE" ]; then
425427
log_error "sync-haproxy expect RENEWED_LINEAGE variable to be set"
426-
exit 1
428+
return 1
427429
fi
428430

429431
DOMAIN_FOLDER="$RENEWED_LINEAGE"
@@ -433,8 +435,9 @@ sync_haproxy() {
433435

434436
cat "${DOMAIN_FOLDER}/privkey.pem" \
435437
"${DOMAIN_FOLDER}/fullchain.pem" \
436-
> "/tmp/haproxy.pem"
437-
mv "/tmp/haproxy.pem" "${CERT_DIR}/${DOMAIN}"
438+
> "/tmp/haproxy.pem" || return $?
439+
mv "/tmp/haproxy.pem" "${CERT_DIR}/${DOMAIN}"
440+
return $?
438441
}
439442

440443
if [ $# -eq 0 ]

sonar-project.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sonar.projectKey=openremote_proxy
2+
sonar.organization=openremote
3+
4+
sonar.shell.activate=true
5+
sonar.docker.activate=true
6+
sonar.githubactions.activate=true

0 commit comments

Comments
 (0)