Skip to content

Commit 6d72fcd

Browse files
committed
Fix sonar configuration
1 parent e434e98 commit 6d72fcd

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

.github/workflows/github-actions.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,15 @@ jobs:
3232
- name: 'Prettier: check'
3333
run: npm run prettier:check
3434
- name: 'Start local Sonar'
35-
run: docker compose -f src/main/docker/sonar.yml up -d
36-
- name: 'Wait for SonarQube to be ready'
3735
run: |
38-
echo 'Waiting for SonarQube to start...'
39-
for attempt in {1..30}; do
40-
if [ "$(curl -s -o /dev/null -w '%{http_code}' http://localhost:9001/api/system/status)" -eq 200 ] && \
41-
curl -s http://localhost:9001/api/system/status | jq -e '.status == "UP"' > /dev/null; then
42-
echo "SonarQube is UP"
43-
break
44-
fi
45-
echo "Waiting for SonarQube... ($attempt/30)"
46-
sleep 10
47-
done
48-
if [ $attempt -eq 30 ]; then
49-
echo 'SonarQube did not become ready in time. Exiting.'
50-
exit 1
51-
fi
36+
docker compose -f src/main/docker/sonar.yml up -d \
37+
&& docker logs -f sonar-token && SONAR_TOKEN=$(docker logs sonar-token)
38+
docker ps -a
5239
- name: 'Test: run tests'
5340
run: |
41+
SONAR_TOKEN=$(docker logs sonar-token)
5442
chmod +x mvnw
55-
./mvnw clean verify -Dsonar.qualitygate.wait=true sonar:sonar
43+
./mvnw clean verify -Dsonar.qualitygate.wait=true sonar:sonar -Dsonar.token=$SONAR_TOKEN
5644
- name: 'Analysis: local Sonar'
5745
run: |
5846
chmod +x tests-ci/sonar.sh

src/main/docker/sonar.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
22
services:
33
sonar:
4-
image: sonarqube:10.7.0-community
4+
image: sonarqube:25.9.0.112764-community
55
container_name: sonar
6-
platform: linux/x86_64
76
# Authentication is turned off for out of the box experience while trying out SonarQube
87
# For real use cases delete sonar.forceAuthentication variable or set sonar.forceAuthentication=true
98
environment:
@@ -12,3 +11,12 @@ services:
1211
# remove the "127.0.0.1:" prefix
1312
ports:
1413
- '127.0.0.1:9001:9000'
14+
sonar-token:
15+
build:
16+
context: .
17+
dockerfile: sonar/Dockerfile
18+
container_name: sonar-token
19+
environment:
20+
- SEED4J_SONAR_URL=http://sonar:9000
21+
depends_on:
22+
- sonar

src/main/docker/sonar/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ubuntu:24.04
2+
RUN \
3+
apt update && \
4+
apt --no-install-recommends install -y curl jq && \
5+
groupadd seed4j && \
6+
useradd seed4j -s /bin/bash -m -g seed4j -G sudo && \
7+
echo 'seed4j:seed4j'|chpasswd && \
8+
apt clean
9+
ENV \
10+
SEED4J_SONAR_URL=http://sonar:9000 \
11+
SEED4J_SONAR_PASSWORD=Seed4J-1339-Project \
12+
SEED4J_SONAR_TOKENNAME=seed4jtoken
13+
COPY sonar/sonar_generate_token.sh /usr/local/bin/sonar_generate_token
14+
RUN chmod 755 /usr/local/bin/sonar_generate_token
15+
USER seed4j
16+
CMD ["sonar_generate_token"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
until [ "$(curl -s $SEED4J_SONAR_URL/api/system/status | jq -r .status)" = "UP" ]; do
4+
sleep 5
5+
done
6+
7+
curl -sS -u admin:admin -X POST \
8+
"$SEED4J_SONAR_URL/api/users/change_password" \
9+
-d "login=admin&previousPassword=admin&password=$SEED4J_SONAR_PASSWORD"
10+
11+
SONAR_TOKEN=$(curl -sS -u admin:$SEED4J_SONAR_PASSWORD -X POST "$SEED4J_SONAR_URL/api/user_tokens/generate" -d "name=$SEED4J_SONAR_TOKENNAME" | jq -r .token)
12+
echo $SONAR_TOKEN

tests-ci/sonar.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
application=$1
44
if [[ $application == '' ]]; then
5-
echo "using jhliteExtensionSample by default"
6-
application='jhliteExtensionSample'
5+
echo "using seed4jSampleExtension by default"
6+
application='seed4jSampleExtension'
77
fi
88

99
retry_count=0

0 commit comments

Comments
 (0)