<?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>DEV Community: Phil Nguyen</title>
    <description>The latest articles on DEV Community by Phil Nguyen (@letsmeetphil).</description>
    <link>https://dev.to/letsmeetphil</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%2F294341%2F82e9f1df-a34e-45ea-a528-e0eadb8aa977.jpg</url>
      <title>DEV Community: Phil Nguyen</title>
      <link>https://dev.to/letsmeetphil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/letsmeetphil"/>
    <language>en</language>
    <item>
      <title>Local SonarQube 7.9.1-Community LTS On Kubernetes</title>
      <dc:creator>Phil Nguyen</dc:creator>
      <pubDate>Tue, 17 Dec 2019 00:53:13 +0000</pubDate>
      <link>https://dev.to/letsmeetphil/local-sonarqube-7-9-1-community-lts-on-kubernetes-38d9</link>
      <guid>https://dev.to/letsmeetphil/local-sonarqube-7-9-1-community-lts-on-kubernetes-38d9</guid>
      <description>&lt;p&gt;&lt;a href="https://gitlab.com/afireinside/kubernetes-sonarqube"&gt;https://gitlab.com/afireinside/kubernetes-sonarqube&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Versions
&lt;/h3&gt;

&lt;p&gt;As of this writing, the following versions have been used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;SonarQube 7.9.1-community LTS&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Minikube 1.5.2&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OSX 10.14.6 Mojave&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kubernetes 1.16.2&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Docker 18.09.9&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;SonarQube is a static analysis tool where it analyzes your code for bugs and code smells then shows you a nice report. The report includes why the lines chosen are bugs/code smells and what the recommended solution is.&lt;/p&gt;

&lt;p&gt;Many coding languages are supported in the 7.9.1-community LTS version. I primarily use it for analyzing my Java code. The Java quality profile I prefer is &lt;strong&gt;FindBugs + FB Contrib&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Some of the benefits for having your own instance of SonarQube on your development machine include (but are not limited to)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;being able to make changes to the quality profiles and gates&lt;/li&gt;
&lt;li&gt;not using up the static analysis line limit if you're using an enterprise license&lt;/li&gt;
&lt;li&gt;experimenting with different plugins to find what works for you&lt;/li&gt;
&lt;li&gt;having a later version than what your enterprise version probably is&lt;/li&gt;
&lt;li&gt;privatizing all your code smells and bugs so no one ever has to know&lt;/li&gt;
&lt;li&gt;performing static analysis without making a commit or using up network bandwidth&lt;/li&gt;
&lt;li&gt;not relying on a small set of admins to make impactful changes to the instance&lt;/li&gt;
&lt;li&gt;etc&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;Lets hop into configuration and installation. This article assumes you have a Macbook laptop and &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt;. Installation instructions are also available in the &lt;a href="https://gitlab.com/afireinside/kubernetes-sonarqube"&gt;GitLab repository&lt;/a&gt; listed at the very top.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, you'll need &lt;strong&gt;Minikube&lt;/strong&gt; (local Kubernetes cluster) and &lt;strong&gt;sonar-scanner&lt;/strong&gt; (to perform static analysis)

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;brew install sonar-scanner&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;brew install minikube&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure Minikube to support the Sonar server and start the cluster (takes a few minutes)

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;minikube config set memory 4096&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minikube config set cpus 2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minikube config set vm-driver hyperkit&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;minikube start&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Deploy your instance of SonarQube (will take a few minutes for pods to fully warm up and load SonarQube)

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;kubectl create secret generic postgres-pwd --from-literal=password={some made up password}&lt;/code&gt; Remember to change the password. It can be anything you want&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonar-pv-postgres.yml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonar-pvc-postgres.yml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonar-postgres-deployment.yml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonarqube-deployment.yml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonarqube-service.yml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;kubectl create -f sonar-postgres-service.yml&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Once all the pods are up and running, view your SonarQube instance (this will open a new browser tab with SonarQube). Default username/password is &lt;code&gt;admin/amin&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;minikube service sonar&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Perform static analysis
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Java
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;In the root of your Java project, add an empty &lt;code&gt;sonar-project.properties&lt;/code&gt; file. The &lt;code&gt;sonar-scanner&lt;/code&gt; service will be looking for this file when performing static analysis.&lt;/li&gt;
&lt;li&gt;Paste the following into the newly created &lt;code&gt;sonar-project.properties&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sonar.projectKey={name of project}
sonar.host.url=http://192.168.##.##:##### (url from minikube service sonar command)
sonar.login=${env.SONAR_TOKEN}
sonar.java.binaries=build/classes
sonar.sources=src/main/java
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;An example config would look like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sonar.projectKey=notificationemailproc
sonar.host.url=http://192.168.64.9:31828
sonar.login=${env.SONAR_TOKEN}
sonar.java.binaries=build/classes
sonar.sources=src/main/java
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create and copy a new SonarQube token by going to the SonarQube instance in the browser and navigating to&lt;br&gt;
My Account -&amp;gt; Security tab -&amp;gt; Enter Token Name -&amp;gt; Generate -&amp;gt; Copy token generated&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In your .bashrc or .zshrc file, add the following line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;export SONAR_TOKEN={SonarQube token that was just copied}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reload your rc file &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;source ~/.bashrc&lt;/code&gt; or &lt;code&gt;source ~/.zshrc&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;sonar-scanner&lt;/code&gt; in the project root directory. Once static analysis is finished, you can view the results in your SonarQube instance in the browser.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Useful plugins
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;FindBugs&lt;/li&gt;
&lt;li&gt;Checkstyle&lt;/li&gt;
&lt;li&gt;Mutation Analysis&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thanks for reading! &lt;/p&gt;

&lt;p&gt;Any questions, comments, or concerns, feel free to send me an email at &lt;code&gt;philip.c.nguyen@gmail.com&lt;/code&gt;&lt;/p&gt;

</description>
      <category>sonarqube</category>
      <category>kubernetes</category>
      <category>lts</category>
      <category>minikube</category>
    </item>
  </channel>
</rss>
