<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Yehanny Olivares</title>
    <description>The latest articles on Forem by Yehanny Olivares (@yehanny).</description>
    <link>https://forem.com/yehanny</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F173348%2Fe800abc3-0643-4a03-b6c9-3e82acdcd79b.png</url>
      <title>Forem: Yehanny Olivares</title>
      <link>https://forem.com/yehanny</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yehanny"/>
    <language>en</language>
    <item>
      <title>Docker Compose - Sonarqube / Sonar Scanner CLI / GITHUB</title>
      <dc:creator>Yehanny Olivares</dc:creator>
      <pubDate>Sat, 03 Dec 2022 17:51:57 +0000</pubDate>
      <link>https://forem.com/yehanny/docker-compose-sonarqube-sonar-scanner-cli-github-13c8</link>
      <guid>https://forem.com/yehanny/docker-compose-sonarqube-sonar-scanner-cli-github-13c8</guid>
      <description>&lt;p&gt;Sonarqube is an open source platform for continuous inspection of code quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;br&gt;
Installation&lt;br&gt;
Support&lt;br&gt;
Optional&lt;br&gt;
License&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sonarqube is an open source platform for continuous inspection of code quality. The platform can be used to perform automatic reviews with static analysis of code to detect bugs, code smells and security vulnerabilities on 20+ programming languages including Java, C#, JavaScript, TypeScript, C/C++, COBOL and more. SonarQube is the only product on the market that supports a leak approach as a practice to code quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can copy all the files inside this repository in your project, also you'll need &lt;a href="https://www.docker.com/%C2%A0and%C2%A0https://docs.docker.com/compose/%C2%A0to"&gt;https://www.docker.com/ and https://docs.docker.com/compose/ to&lt;/a&gt; run the commands inside your local environment&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SonarQube + Postgres DB&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Copy the .env.example to .env inside the repository&lt;/p&gt;

&lt;p&gt;Run first the sonarqube + db services. SonarQube server will take some minutes to deploy and we can't run the Sonar Scanner until this first task is done, we also need to setup our project and if we're using for example GitHub we'll need to:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub App Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a GitHub App from Settings &amp;gt; Developer Settings &amp;gt; GitHub App to get our API Credentials, Secret and Private Key&lt;/p&gt;

&lt;p&gt;Install that new App for a single or multiple repositories to connect to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup your Repository Permissions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Checks: Read and Write&lt;br&gt;
Commit statuses: Read&lt;br&gt;
Metadata: Read&lt;br&gt;
Pull requests: Read and Write&lt;/p&gt;

&lt;p&gt;Save and next copy your credentials because we're going to need it for the next step&lt;/p&gt;

&lt;p&gt;App ID:&lt;br&gt;
Client ID:&lt;br&gt;
Client secrets:&lt;br&gt;
Private key:&lt;/p&gt;

&lt;p&gt;Now it's time to deploy our SonarQube instance, run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker compose up -d sonarqube db&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then double check both services are mounted and running, and you should see something like this&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker ps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NAME COMMAND SERVICE STATUS PORTS postgresql "docker-entrypoint.s…" db running 5432/tcpsonarqube "/opt/sonarqube/bin/…" sonarqube running 0.0.0.0:9000-&amp;gt;9000/tcp, :::9000-&amp;gt;9000/tcp&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Go to your SonarQube server &lt;a href="http://localhost:9000%C2%A0and"&gt;http://localhost:9000 and&lt;/a&gt; login with the default credentials. User: admin Pass: admin and then change them to your custom password, save and go to &amp;gt; Projects and select GitHub and use your App credentials that we created before to fill the form&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running the Sonar Scanner&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Setup your .env Variables with the one that SonarQube just created for us&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SONAR_LOGIN=&lt;br&gt;
SONAR_PROJECT_KEY=&lt;br&gt;
SONAR_SOURCES=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now it's time to run our first test using this command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker compose up sonar-scanner-cli&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Wait for the test to finnish and go to &lt;a href="http://localhost:9000%C2%A0to"&gt;http://localhost:9000 to&lt;/a&gt; see your results! Isn't that awesome? Happy Testing&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optional&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;vm.maxmapcount Issue&lt;/p&gt;

&lt;p&gt;You may have vm.maxmapcount size issue and for that I've created a bash file to solve it add execute permissions to the file sonarqube-init.sh&lt;/p&gt;

&lt;p&gt;On Linux&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chmod +x sonarqube-init.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;On MacOS and Windows&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chmod 755 sonarqube-init.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then run it: ./sonarqube-init.sh&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SonarQube Properties file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can setup the properties of your project using the sonar-project.properties file&lt;/p&gt;

&lt;p&gt;must be unique in a given SonarQube instance&lt;br&gt;
sonar.projectKey=sample&lt;/p&gt;

&lt;p&gt;--- optional properties ---&lt;/p&gt;

&lt;p&gt;//defaults to project key&lt;br&gt;
sonar.projectName=My project&lt;br&gt;
//defaults to 'not provided'&lt;br&gt;
sonar.projectVersion=1.0.0&lt;/p&gt;

&lt;p&gt;Path is relative to the sonar-project.properties file. //Defaults to .&lt;br&gt;
sonar.sources=.&lt;/p&gt;

&lt;p&gt;Encoding of the source code. Default is default system encoding&lt;br&gt;
sonar.sourceEncoding=UTF-8&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don't hesitate to comment if you have any issue, and I'll help you for sure to solve it, I'm 24/7 in my email&lt;/p&gt;

&lt;p&gt;If you want to support this effort and time on doing this I'll be so grateful with you (And with God) You can &lt;a href="https://www.buymeacoffee.com/yehanny"&gt;https://www.buymeacoffee.com/yehanny&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitHub Repo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://cpmlink.net/9R-GAQ"&gt;https://cpmlink.net/9R-GAQ&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>sonarqube</category>
      <category>devops</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
