Skip to content

Commit

Permalink
Fix code coverage, introduce local Sonarqube docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-frak committed May 10, 2022
1 parent a5483ce commit 96b8103
Show file tree
Hide file tree
Showing 7 changed files with 3,722 additions and 73 deletions.
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ To check if the plugin works correctly after the upgrade:
2) Run `docker-compose up -d` in `./docker` to create the dependencies necessary for end-to-end testing
3) Run `npx cypress run` in `./docker/e2e` to run end-to-end tests

## SonarQube analysis on a local environment

It's encouraged that you perform a local code analysis before you submit a Pull Request.

### Prerequisites

1. Go to the `./docker` folder
2. Execute `docker-compose -f docker-compose-sonar.yml up -d` to start a local Sonarqube instance
3. Visit http://localhost:9000/
4. Log in with the credentials `admin:admin`
5. Update the password when prompted

### Running the analysis

You can run the analysis using the following command in the repository root:

```shell
mvn clean verify sonar:sonar -Pcode-coverage -Dsonar.login=your_username -Dsonar.password=your_password
```

After a successful analysis, the report will be available at http://localhost:9000/projects

## Any contributions you make will be under the MIT License
In short, when you submit code changes, your submissions are understood to be under the same
[MIT License](https://choosealicense.com/licenses/mit/) that covers the project.
Expand Down
8 changes: 7 additions & 1 deletion docker/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
COMPOSE_PROJECT_NAME=keycloak_migration_demo
KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:17.0.1
KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:17.0.1

SONAR_VERSION=9.4.0-community
SONAR_CONFIG_VERSION=3.13.5
SONAR_USER=admin
SONAR_PASSWORD=admin
SONAR_URL=sonarqube:9000
36 changes: 36 additions & 0 deletions docker/docker-compose-sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.3'
services:
### CODE ANALYSIS ###
sonarqube:
image: sonarqube:$SONAR_VERSION
ports:
- "9000:9000"
networks:
- internal
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
depends_on:
- sonarqube_config
stop_grace_period: 5m

sonarqube_config:
image: alpine:$SONAR_CONFIG_VERSION
environment:
SONAR_URL: $SONAR_URL
SONAR_USER: $SONAR_USER
SONAR_PASSWORD: $SONAR_PASSWORD
entrypoint: ["sh", "/docker-entrypoint.sh"]
volumes:
- ./sonarqube/import_data.sh:/docker-entrypoint.sh:ro
- ./sonarqube/java_profile.xml:/java_profile.xml:ro
networks:
- internal
### END CODE ANALYSIS ###

networks:
internal:

volumes:
sonarqube_data:
sonarqube_extensions:
30 changes: 30 additions & 0 deletions docker/sonarqube/import_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e

echo "Initiating..."

SONAR_RESTORE_PROFILE_URL="$SONAR_URL/api/qualityprofiles/restore"
SONAR_DEFAULT_PROFILE_URL="$SONAR_URL/api/qualityprofiles/set_default"

CUSTOM_PROFILE_JAVA="Sonar%20way%20(extended)"
FILE_JAVA="/java_profile.xml"

# INSTALL CURL
apk --no-cache add curl

# WAIT UNTIL SONARQUBE IS UP
until curl --output /dev/null --silent --head --fail -u "$SONAR_USER":"$SONAR_PASSWORD" "$SONAR_URL/api/system/health"; do
>&2 echo "Sonarqube is unavailable - sleeping"
sleep 1
done
>&2 echo "Sonarqube is up - executing command"

# PROFILE - JAVA
echo "Importing custom profile ($FILE_JAVA)..."

curl -X POST -u "$SONAR_USER":"$SONAR_PASSWORD" "$SONAR_RESTORE_PROFILE_URL" --form backup=@$FILE_JAVA

echo "Setting the profile as default..."
curl -u admin:admin -d "language=java&qualityProfile=$CUSTOM_PROFILE_JAVA" -X POST "$SONAR_DEFAULT_PROFILE_URL"

echo "Data import done."
Loading

0 comments on commit 96b8103

Please sign in to comment.