-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
110 lines (79 loc) · 3.52 KB
/
Copy pathDockerfile
File metadata and controls
110 lines (79 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
ARG STAGE=prod
ARG BASE_IMAGE=registry.cloudogu.com/official/java:21.0.10-4
ARG SONAR_BASE_VERSION=25.12.0
ARG SONAR_VERSION=${SONAR_BASE_VERSION}.117093
ARG SONARQUBE_ZIP_SHA256=09215f6f6a56db484946e4355c9801fa357eb92eedc99a2bebedf1d7ae21a341
ARG SONARQUBE_COMMUNITY_WEBAPP_ZIP_SHA256=a91f68bb65474cb607a1929d1a2c08befcc7da3f5b8775422325322c105ebd21
FROM golang:1.26.0 AS compiler-prod
WORKDIR /app
COPY sonarcarp /app
COPY build /app/build
# there is a go-specific Makefile in sonarcarp. we only need the other makefile includes.
RUN make vendor compile-generic
FROM golang:1.26.0-alpine3.23 AS compiler-debug
WORKDIR /app
COPY sonarcarp /app
RUN go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest
RUN CGO_ENABLED=0 go build -gcflags "all=-N -l" -o /app/target/sonarcarp
FROM ${BASE_IMAGE} AS builder
ARG SONAR_BASE_VERSION
ARG SONAR_VERSION
ARG SONARQUBE_ZIP_SHA256
ARG SONARQUBE_COMMUNITY_WEBAPP_ZIP_SHA256
ENV BUILDER_HOME="/builder/sonar"
ENV BUILDER_WEBAPP="/builder/webapp"
WORKDIR /builder
RUN apk --update add build-base curl unzip
RUN curl --fail --remote-name --location https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${SONAR_VERSION}.zip
RUN echo "${SONARQUBE_ZIP_SHA256} *sonarqube-${SONAR_VERSION}.zip" | sha256sum -c -
RUN unzip sonarqube-${SONAR_VERSION}.zip
RUN mv sonarqube-${SONAR_VERSION} ${BUILDER_HOME}
RUN rm sonarqube-${SONAR_VERSION}.zip
RUN curl --fail --output sonarqube-webapp-${SONAR_BASE_VERSION}.zip --location https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/${SONAR_BASE_VERSION}/sonarqube-webapp.zip
RUN echo "${SONARQUBE_COMMUNITY_WEBAPP_ZIP_SHA256} *sonarqube-webapp-${SONAR_BASE_VERSION}.zip" | sha256sum -c -
RUN unzip sonarqube-webapp-${SONAR_BASE_VERSION}.zip -d sonarqube-webapp-${SONAR_BASE_VERSION}
RUN mv sonarqube-webapp-${SONAR_BASE_VERSION} ${BUILDER_WEBAPP}
RUN rm sonarqube-webapp-${SONAR_BASE_VERSION}.zip
FROM ${BASE_IMAGE} AS base
LABEL NAME="official/sonar" \
VERSION="25.12.0-12" \
maintainer="hello@cloudogu.com"
ARG SONAR_VERSION
ENV SONARQUBE_HOME=/opt/sonar \
SERVICE_TAGS=webapp \
SONAR_VERSION=${SONAR_VERSION} \
STARTUP_DIR="/"
RUN set -eux \
&& apk update \
&& apk upgrade \
# temporarily add old repo
&& echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/main" > /tmp/old-repos \
&& echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/community" >> /tmp/old-repos \
\
&& apk add --no-cache --repositories-file=/tmp/old-repos postgresql14-client \
\
# cleanup
&& rm -f /tmp/old-repos \
&& apk add --no-cache procps postgresql14-client curl uuidgen libstdc++ \
&& mkdir -p /opt \
&& mkdir -p /carp \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /opt/sonar/lib/common \
&& addgroup -S -g 1000 sonar \
&& adduser -S -h "$SONARQUBE_HOME" -s /bin/bash -G sonar -u 1000 sonar \
&& chown -R sonar:sonar ${SONARQUBE_HOME} /carp
COPY --from=builder --chown=1000:1000 /builder/sonar ${SONARQUBE_HOME}
COPY --from=builder --chown=1000:1000 /builder/webapp /opt/sonar/web.community
COPY --chown=1000:1000 ./resources /
FROM base AS debug
ENV STAGE=DEBUG
COPY --from=compiler-debug --chown=1000:1000 /go/bin/dlv /carp/dlv
COPY --from=compiler-debug --chown=1000:1000 /app/target/sonarcarp /carp/sonarcarp
FROM base AS prod
COPY --from=compiler-prod --chown=1000:1000 /app/target/sonarcarp /carp/sonarcarp
FROM ${STAGE} AS final
RUN chmod 0744 /carp/sonarcarp
EXPOSE 8080
USER sonar
HEALTHCHECK CMD doguctl healthy sonar || exit 1
CMD ["/startup.sh"]