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