Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active September 20, 2024 10:59
Show Gist options
  • Save avoidik/8041e515a0de04fa3b539a0cbdb59239 to your computer and use it in GitHub Desktop.
Save avoidik/8041e515a0de04fa3b539a0cbdb59239 to your computer and use it in GitHub Desktop.
QuickStart - SonarQube in Docker

Run SonarQube

$ git clone https://github.com/SonarSource/docker-sonarqube
$ cd docker-sonarqube
$ docker build -t sonarqube:9.9.4.87374 --build-arg SONARQUBE_VERSION=9.9.4.87374 -f 9/community/Dockerfile 9/community/
$ docker network create sonarqube
$ docker run --rm -i -t --name sonarqube -p 9000:9000 \
    --security-opt seccomp=unconfined --security-opt apparmor=unconfined \
    -e SONAR_SEARCH_JAVAADDITIONALOPTS='-Dbootstrap.system_call_filter=false' \
    --network sonarqube \
    sonarqube:9.9.4.87374

Visit http://localhost:9000, change default password, create project and token.

Prepare project environment

$ mkdir go-lang-test
$ cd go-lang-test
$ docker run --rm -i -t --name go-lang-test \
    --platform linux/aarch64 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v $(pwd):/build \
    -w /build \
    --network sonarqube \
    public.ecr.aws/codebuild/amazonlinux2-aarch64-standard:3.0 bash

Prepare sample project

$ go mod init hello
$ cat <<'EOF' | tee main.go
package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
}
EOF
$ go fmt main.go
$ go run main.go

Run Sonarqube Scanner

$ curl -fsSLO https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.1.0.4477-linux-aarch64.zip
$ unzip sonar-scanner-cli-6.1.0.4477-linux-aarch64.zip
$ export PATH="$PATH:$(pwd)/sonar-scanner-6.1.0.4477-linux-aarch64/bin"
$ SONAR_TOKEN='sqp_f575f529d44c4998a816ea82e5c9615275b3ba59'
$ SONAR_URL='http://sonarqube:9000'
$ sonar-scanner \
  -Dsonar.projectBaseDir="$(pwd)" \
  -Dsonar.projectKey='go-lang-test' \
  -Dsonar.sources='.' \
  -Dsonar.host.url="$SONAR_URL" \
  -Dsonar.login="$SONAR_TOKEN" \
  -Dsonar.verbose=true -X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment