<?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: samsha1</title>
    <description>The latest articles on DEV Community by samsha1 (@samsha1).</description>
    <link>https://dev.to/samsha1</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%2F50453%2F39adf4ef-0a89-4cde-8bbe-9161c1fdde6a.jpg</url>
      <title>DEV Community: samsha1</title>
      <link>https://dev.to/samsha1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/samsha1"/>
    <language>en</language>
    <item>
      <title>How you test your code?</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Thu, 28 Mar 2019 17:02:21 +0000</pubDate>
      <link>https://dev.to/samsha1/how-you-test-your-code-3e4o</link>
      <guid>https://dev.to/samsha1/how-you-test-your-code-3e4o</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1e53h7lzujq8ma2j2jf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1e53h7lzujq8ma2j2jf.jpg" alt="unit test" width="625" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Testing code is one of the most important part to understand your application and behavior of code.Every developer knows how painful bugs can be, especially in the production stage as it takes hours of hard work. Testing each scenario can be as good as believing yourself. You write and execute your code, without knowing how it behaves if some exception occurs or some validation violates, this may cause a problem in staging or production. So, running test case plays a vital role in SDLC. You give rich life  and believe your code with eye closed, once your test coverage is at good level.&lt;/p&gt;

&lt;p&gt;Today, we are going to write a simple test methods and run test code using tools like Xdebug and PHPUnit. PHPUnit is a programmer-oriented testing framework. This is the outstanding testing framework for writing Unit tests for PHP Web Applications. With the help of PHPUnit, we can direct test-driven improvement.&lt;/p&gt;

&lt;p&gt;Let's install PHPUnit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://phar.phpunit.de/phpunit-7.5.phar
chmod +x phpunit-7.5.phar
sudo mv phpunit-7.5.phar /usr/bin/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;There are several other way to insall phpunit. &lt;strong&gt;Find more here&lt;/strong&gt;:&lt;a href="https://phpunit.readthedocs.io/en/8.0/installation.html" rel="noopener noreferrer"&gt;phpunit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, To get our Test Coverage full report we need to install Xdebug:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install php-pear
pecl install xdebug
sudo apt-get install php-xdebug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Find More about &lt;strong&gt;Xdebug&lt;/strong&gt; here: &lt;a href="https://xdebug.org/docs/install" rel="noopener noreferrer"&gt;xdebug&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Without making further delay Let's dive into our simple test scenarios where we test whether an array is empty:&lt;/p&gt;

&lt;p&gt;Create a folder &lt;strong&gt;UnitTest&lt;/strong&gt; where we will include all testable files. In this folder, create a subfolder  &lt;strong&gt;tests&lt;/strong&gt;. Create a new file &lt;code&gt;phpunit.xml&lt;/code&gt; in this subfolder and add following code.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;colors=”true”&lt;/code&gt; will show the results in highlighted colors and &lt;code&gt;&amp;lt;directory&amp;gt;./UnitTestFiles/Test/&amp;lt;/directory&amp;gt;&lt;/code&gt; will ask PHPUnit for the location of the files to be tested. The filter tag is used while discovering GUI based report with statistics analysis of our test coverages. &lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Conventions to Write Unit Test Case
&lt;/h2&gt;

&lt;p&gt;Following are some basic conventions and steps for writing tests with PHPUnit:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test File names should have a suffix Test. For example, if First.php needs to 
be tested,the name of the test file name will be FirstTest.php&lt;/li&gt;
&lt;li&gt;Similarly, If the class name is &lt;code&gt;MyFirstClass&lt;/code&gt; than the test class name will be 
&lt;code&gt;MyFirstClassTest&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add test as the prefix for method names. For example, if the method name is 
&lt;strong&gt;getuser()&lt;/strong&gt;, then in test class, it will become &lt;strong&gt;testgetuser()&lt;/strong&gt;. You can 
also use &lt;a class="mentioned-user" href="https://dev.to/test"&gt;@test&lt;/a&gt; annotation in document block to declare it as a testing method.&lt;/li&gt;
&lt;li&gt;All testing methods are &lt;code&gt;public&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;MyFirstClassTest class should be inherited from &lt;strong&gt;PHPUnit\Framework\TestCase&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are the major ground rules for the PHP unit testing framework. The essential configurations and settings are all setup. It is now time to write the first test case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing The First Unit Test Case in PHP
&lt;/h2&gt;

&lt;p&gt;Create a file EmptyTest.php in UnitTest/tests. Add the following code to it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, to run our test code inside terminal type: &lt;em&gt;phpunit &lt;/em&gt; i.e. phpunit tests/EmptyTest.php. &lt;/p&gt;

&lt;p&gt;Note: By running only phpunit, it defaults executes all test file inside UnitTest/tests directory because we have mentioned this directory in phpunit.xml above.&lt;/p&gt;

&lt;p&gt;We will get our test failure because the value inside array is not empty. In my terminal I am getting:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;F                                                                   1 / 1 (100%)

Time: 513 ms, Memory: 10.00MB

There was 1 failure:

1) EmptyTest::testFailure
Failed asserting that an array is empty.

/home/samrat/myproj/testcase/tests/EmptyTest.php:8

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Let's pass our above test case and add one more scenario to test equals.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;It gives an error when $expected is not equal to $actual. If $expected equals $actual then it returns true. Remember, the first argument is &lt;em&gt;expected&lt;/em&gt; and the other is &lt;em&gt;actual&lt;/em&gt;. The above test only passes if expected (0) is equal to (1). To pass above test case just replace 0 with 1 or 1 with 0. Now, run both testcase.&lt;/p&gt;

&lt;p&gt;Our both test must pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHPUnit 7.5.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 with Xdebug 2.7.0
Configuration: /home/samrat/myproj/UnitTest/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 200 ms, Memory: 10.00MB

OK (2 tests, 2 assertions)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can find more about assertion here: &lt;a href="https://phpunit.de/manual/6.5/en/appendixes.assertions.html" rel="noopener noreferrer"&gt;PHPUnit Assertion&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s look at another example in which a developer has created a code to parse the items received in json and validate it for the possible use case may be exception or for other validation rules.&lt;/p&gt;

&lt;p&gt;Let's create &lt;em&gt;app/item_parser.php&lt;/em&gt; file inside UnitTest directory&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;I've created a class called ItemsParser with static method called parse that takes one argument called response, received from json data. We have checked for different exceptions and returned parsed data as an array.&lt;/p&gt;

&lt;p&gt;Let's add some exceptions class for above use cases inside same directory:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now in the UnitTest/tests folder, create a new file called ItemsParserTest.php and add the following test code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Run above test case, Our test case must pass. By, this we can assure ItemParser class is successfully instantiated.&lt;/p&gt;

&lt;p&gt;As, we don't invoke real endpoint. Let's create a fake json data called one.json inside &lt;em&gt;UnitTest/json&lt;/em&gt; and test with it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now Let's write another test method to ensure our data is actually parsed the way we expected it:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;As, we created fake data, and send that data to &lt;em&gt;ItemParser::parse()&lt;/em&gt; method. If we now run our test case we get the data as the way we expected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHPUnit 7.5.8 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.15-0ubuntu0.18.04.1 with Xdebug 2.6.0
Configuration: /home/samrat/myproj/UnitTest/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 377 ms, Memory: 10.00 MB

OK (2 tests, 2 assertions)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Actually, what we did is we send json data and decoupled it on our data only with label and value as key and returned only data that is required as an array.&lt;/p&gt;

&lt;p&gt;Now, Let's test for the array keys we are getting:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;From above code we can ensure that whether we are getting the key we expected i.e label and value.&lt;/p&gt;

&lt;p&gt;What about the exceptions we added to our methods, whether they are working the way we wanted? Well I am not sure so let's test it.&lt;/p&gt;

&lt;p&gt;Say, we have some json data with price in string:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;How our code block response when we send price as string, well we must be sure our code handles such kind of exceptions.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;expectException() method is to ensure whether expected exception is thrown by our code block. Run phpunit and check above code it must by the way!&lt;/p&gt;

&lt;p&gt;Revise, the ItemParser.php file we have used number_format function to convert cent price into dollar.So, Let's write test to check whether our price has been successfully converted.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And These test can go on and on, wouldn't it be nice to get report or analyzer for our test case. To get total test coverage report would be great. So, we have written some test code and let's generate our test report and find out how much code did we really covered?&lt;/p&gt;

&lt;p&gt;It's simple just type this in terminal: phpunit  --coverage-html . &lt;em&gt;In my case phpunit  --coverage-html report/&lt;/em&gt;. You will get whole report in html format. By the way, we can generate in xml, php, text and many other formats. Just type: phpunit --help for more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11zcf3g4j01m32yzpdfu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11zcf3g4j01m32yzpdfu.png" alt="test coverage report" width="800" height="205"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above test coverage explains, our first example test coverage is 100% but ItemParserTest could be better and we only covered some part of our code so let's stick with 90%. I leave it up to you to make it 100%. Actually, 80% code coverage can be acceptable coverage in software world (heard somewhere).&lt;/p&gt;

&lt;p&gt;We also get the report of where we can do better. Here's some other code coverage statistics:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7382itqyzg0b29xrayw3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7382itqyzg0b29xrayw3.png" alt="coverage statistics" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3s5v8q6ym8twwq6i13zd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3s5v8q6ym8twwq6i13zd.png" alt="Insufficent Coverage" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This article explains a basic setup that help you in getting started with PHPUnit for PHP unit testing.&lt;/p&gt;

&lt;p&gt;Hope you find this article helpful. Unit Testing is a vast topic. Here I have given you a brief introduction so that you can start writing your own tests. I would like to  mention several changes in the latest version of PHPUnit. In the previous versions, the class extend with &lt;code&gt;PHPUnit_Framework_TestCase&lt;/code&gt;. In the latest version, it extends with &lt;code&gt;TestCase&lt;/code&gt; only. Please comment below if you have any question or suggestions.&lt;/p&gt;

&lt;p&gt;You are awesome!&lt;/p&gt;

</description>
      <category>testing</category>
      <category>phpunit</category>
      <category>php</category>
      <category>unittesting</category>
    </item>
    <item>
      <title>What's your first step while starting project?</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Tue, 29 Jan 2019 03:56:05 +0000</pubDate>
      <link>https://dev.to/samsha1/whats-your-first-step-while-starting-project-2h24</link>
      <guid>https://dev.to/samsha1/whats-your-first-step-while-starting-project-2h24</guid>
      <description>&lt;p&gt;Once, I am sure I always start by working in database design, step by step it gets vague. So, I just want to know is it the right first step?&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Getting Started in CI/CD for Beginners</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Sun, 13 Jan 2019 16:35:19 +0000</pubDate>
      <link>https://dev.to/samsha1/getting-started-in-cicd-for-begineers-1lp8</link>
      <guid>https://dev.to/samsha1/getting-started-in-cicd-for-begineers-1lp8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mxJmWjW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://coyee.com/uploads/img/20170512/164319_7hbS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mxJmWjW6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/http://coyee.com/uploads/img/20170512/164319_7hbS.png" alt="CI/CD for begineer" width="698" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is CI/CD?
&lt;/h3&gt;

&lt;p&gt;CI/CD stands for Continuous Integration and Continuous Deployment. Continuous Integration means building your application continuously. Consider, a scenario where developer makes some changes in source code. Now Continuous Integration must be able to fetch that source code and prepare a Build.Build also involves compiling and validating your code, code review, Unit Testing and Integration Testing, also packaging your application.&lt;/p&gt;

&lt;p&gt;After Continuous Integration we have Continuous Delivery. Until now your product is ready, tested and ready for delivery. Consider, a Continuous Integration tools like Jenkins which deploy into the test servers to perform a user acceptance testing and once this is done it will be deployed onto the prod server for release. If this step is done manually then it is called Continuous Delivery but yes if its done automatically then its Continuous Deployment. &lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the WorkFlow
&lt;/h3&gt;

&lt;p&gt;First, Let's have simple Hello world project in our local machine and initialize git. Once done push our code to remote repository. Next, We will write simple Jenkins Job so that It will trigger and deploy our code to dev server.We will create two different aws instance for jenkins and dev. Remember, we will run jenkins application inside Docker Container so that we donot have to go through manual installation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fig2bc66u7lpmhnjpy0z6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fig2bc66u7lpmhnjpy0z6.png" alt="CI/CD workflow" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's Bring It To Life
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Inside Local Machine&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Let's create simple Hello World Project written in php.&lt;/p&gt;

&lt;p&gt;Step 2: Initialize git, commit and push your changes to remote repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inside GitHub&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a webhook so that jenkins jobs would trigger or look for changes whenever code is pushed to specified branch.&lt;/p&gt;

&lt;p&gt;Go to Settings -&amp;gt; Webhooks -&amp;gt; Add Webhooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Payload URl&lt;/strong&gt;:The URL is in the form $JENKINS_BASE_URL/github-webhook/ — for example: &lt;a href="https://ci.example.com/jenkins/github-webhook/" rel="noopener noreferrer"&gt;https://ci.example.com/jenkins/github-webhook/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Content Type&lt;/strong&gt;: application/json&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secret Key&lt;/strong&gt;: Secret Key so that github can access jenkins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which events would you like to trigger this webhook?&lt;/strong&gt; : Depends on events you prefer. I have just checked for pushed event i.e. job is triggered whenever something is pushed to github master branch. (For specific branch name you can mention it from jenkins).&lt;/p&gt;

&lt;p&gt;Update Webhooks. That's it inside Github.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inside Jenkins Instance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: ssh to your aws Jenkins instance&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;ssh -i  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 2: Run update your packages.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;sudo apt-get update&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 3: Install docker


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;sudo apt-get install docker.io&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 4: Add Docker to your user group and login again after exit


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;sudo usermod -aG docker ubuntu&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 5: Let's pull docker image for jenkins:


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;docker pull jenkins/jenkins &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 6: Type


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;docker images&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

to see pulled image from jenkins/jenkins repository

Step 7: Run Docker image:


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;docker run -d -p 8080:8080 --name  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Step 8:Type


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

to see running container.

Step 9: Once you setup jenkins inside docker. Try, accessing from browser


        ```
&amp;lt;instance public ip &amp;gt;:&amp;lt;external-port-number&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Before accessing, open the add inbound rules in aws. choose security groups(launch-wizard). click Edit-&amp;gt;Add Rules, set &lt;em&gt;custom tcp rules&lt;/em&gt; and _external port range (my case 8080)_also http rule then save &lt;/p&gt;

&lt;p&gt;Voila! you can then run jenkins, Install suggested plugin (default). Fill the required credential and set your first job set!&lt;/p&gt;

&lt;p&gt;Step 1: create Freestyle Project.&lt;/p&gt;

&lt;p&gt;Step 2: Add some Description and give the github repository url from where jenkins would fetch your project.&lt;/p&gt;

&lt;p&gt;Remember, to setup webhook inside github. Go to &lt;em&gt;settings-&amp;gt;webhooks-&amp;gt;add payload url&lt;/em&gt; i.e /github-webhook/&lt;/p&gt;

&lt;p&gt;Step 3: Write some shell script to deploy your code inside dev-server.&lt;/p&gt;

&lt;p&gt;To establish, a connection between jenkins and dev instance we need to add jenkins public key to dev authorized key.&lt;/p&gt;

&lt;p&gt;In jenkins instance run &lt;em&gt;ssh-keygen&lt;/em&gt; to generate the .pub key and copy public key from .ssh/ to dev ./ssh/authorized_keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;instance = '13.232.89.159' 

ARCHIVE_FILENAME = cicd.zip

zip --symlinks -x *.git* -r $ARCHIVE_FILENAME . #compress all the files and create zip file

echo "--------Copying Files to remote dev server from jenkins ----------"

scp -o StrictHostKeyChecking=no index.tar.gz ubuntu@$instance:/home/ubuntu/

echo "--------Finished Copying----------"

echo "Entering to Dev Instance"

ssh -o StrictHostKeyChecking=no ubuntu@$instance '

  mv $ARCHIVE_FILENAME /var/www/html #move zip file from current directory to /var/www/html

  cd /var/www/html

  unzip $ARCHIVE_FILENAME

  rm -rf $ARCHIVE_FILENAME #remove the file once done

' 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once, the scripting part is done let's save and build our job. After successful job build we can access our deployment server from our browser and see the changes made.&lt;/p&gt;

&lt;p&gt;This is just a simple example we have done, just to understand the workflow of CI/CD.&lt;/p&gt;

&lt;h3&gt;
  
  
  You are awesome!
&lt;/h3&gt;

</description>
      <category>docker</category>
      <category>jenkins</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>event.stopPropagation()</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Thu, 27 Sep 2018 17:07:23 +0000</pubDate>
      <link>https://dev.to/samsha1/eventstoppropagation-3fhm</link>
      <guid>https://dev.to/samsha1/eventstoppropagation-3fhm</guid>
      <description>&lt;p&gt;Currently, I am learning react and came to know how useful event.stopPropagation() function can be.So, Let's dive in.&lt;/p&gt;

&lt;p&gt;Let's create a simple functional component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deleteTask(){

    let tasks=this.state.tasks;
    tasks.splice(index,1);
    this.setState({
       tasks 
    })

}

const ToDoItem = (props) =&amp;gt; {
    return (
        &amp;lt;li onClick={ ()=&amp;gt; { props.clickHandler(props.index)}}
            className={props.details.completed} ? 'completed' : ''&amp;gt;
           Some Text 
        &amp;lt;button onClick={ ()=&amp;gt;{props.deleteTask(props.index)}}&amp;gt;Delete&amp;lt;/button&amp;gt;
        &amp;lt;/li&amp;gt;

    )

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, If you click Delete button the onClick event gets triggered on both li and button element.The point here is we only want to trigger button onClick event but not li. If the props (completed) is not defined in details props then we get console message as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cannot read the property 'completed' of undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because when we click button element, indirectly we are also triggering to li. As, li is parent element of button. li onClick event is triggered and there is no defined 'completed' inside props details. So, to get rid of this issue we can use event.stopPropagation().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ToDoItem = (props) =&amp;gt; {
    return (
        &amp;lt;li onClick={ ()=&amp;gt; { props.clickHandler(props.index)}}
            className={props.details.completed} ? 'completed' : ''&amp;gt;
           Some Text 
        &amp;lt;button onClick={ (evt)=&amp;gt;
            evt.stopPropagation();
            {props.deleteTask(props.index)}}&amp;gt;Delete&amp;lt;/button&amp;gt;
        &amp;lt;/li&amp;gt;

    )

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the event is not propagated to the parent element because of evt.stopPropagation(). So, we are free to go. &lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>How it's like to refactor code, written by other developer?</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Mon, 06 Aug 2018 16:32:24 +0000</pubDate>
      <link>https://dev.to/samsha1/how-its-like-to-refactor-code-written-by-other-developer-5cgf</link>
      <guid>https://dev.to/samsha1/how-its-like-to-refactor-code-written-by-other-developer-5cgf</guid>
      <description>&lt;p&gt;Currently, I am working in Menuboard manager project written by some other developer. Now, the developer is out of contact. So, I am given the task to refactor his code and add some module. My question is How can one understand the flow of code without any code documentation and project goal??&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Walk Through Docker</title>
      <dc:creator>samsha1</dc:creator>
      <pubDate>Sun, 05 Aug 2018 20:11:00 +0000</pubDate>
      <link>https://dev.to/samsha1/walk-through-docker-5bm3</link>
      <guid>https://dev.to/samsha1/walk-through-docker-5bm3</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Floige.co%2Fcontent%2Fimages%2F2014%2FJun%2Fdockerize-go-app.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Floige.co%2Fcontent%2Fimages%2F2014%2FJun%2Fdockerize-go-app.png" alt="Go Inside Docker" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Docker?
&lt;/h2&gt;

&lt;p&gt;Docker is the open platform for developers and system admins to build,ship and run distributed application on laptops,VM or cloud.Docker is widely used for operations to run multiple application in containerization form.For example: one container may have web server to run application and other container may handle mysql database that is used by web application. &lt;strong&gt;Source&lt;/strong&gt; &lt;a href="https://en.wikipedia.org/wiki/Docker_(software)" rel="noopener noreferrer"&gt;wiki&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where is docker used?
&lt;/h2&gt;

&lt;p&gt;Docker can be used in many cases, these days the software packages are run virually with more efficient,fast and secured way. So, Why not Docker?&lt;/p&gt;

&lt;p&gt;Let us move with simple example: Say, your friend want to share a project, which  requires with latest golang version,mysql database and nginx web server....Now, to run this project manually what you need is to install same version of go system file,mysql and web server in your local machine. You also need to go through version configuration issue.&lt;/p&gt;

&lt;p&gt;To get rid of this headache, let's docker our project.&lt;/p&gt;

&lt;p&gt;First, write a simple docker file . create a filename Dockerfile in your root_project directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM amd64/golang:1.10.3
WORKDIR /go/src/app
COPY . .
RUN go get -u github.com/gorilla/mux
RUN go get github.com/pilu/fresh
RUN go get github.com/sirupsen/logrus 
CMD ["fresh"] 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's dig into script that we created&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FROM amd64/golang:1.10.3&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;pulls docker remote repo with go version go:1.10.3&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WORKDIR /go/src/app&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;defines working directory inside docker container.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY . .&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;copies current working directory to /go/src/app inside docker container.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN go get -u github.com/gorilla/mux&lt;br&gt;
RUN go get github.com/pilu/fresh &lt;br&gt;
RUN go get github.com/sirupsen/logrus&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;installs different packages depends on your project. Here, I have installed /gorilla/mux that implements request router and dispatcher for matching incoming requests to their respective handler. /pilu/fresh is a command line tool that builds and (re)starts your web application everytime you save a code. Likewise, logrus is used to log the data of status.Remember, these packages are not mandatory and varies according to your requirement.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD ["fresh"]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;CMD run once we successfully build and run our Dockerfile. If you want to run some command use CMD as simple as that. Here, I have use fresh command because when we docker run or project it automatically runs in command inside docker.&lt;/p&gt;

&lt;p&gt;Once, our docker file is ready build your docker application&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t docker-golang.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;builds docker application where -t flag is the name given to built repository or image as simple as that.&lt;/p&gt;

&lt;p&gt;once, you successfully built image. You are ready to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 8090:8090 -v $(pwd):/go/src/app  --env EXAMPLE_ENV_SETUP=test_value_env --name golang-env docker-golang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;docker run command runs above created image,where:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-d //runs docker image in backgroud (optional)
-p is the port number to run the docker,left:right indicates the port to run outside and inside docker container.
-v //volume created that represents the direcory of file outside and inside docker repository
--env //enviroment value needed while running the project
--name //name of the container which makes easy to remember rather using container id 
--docker-golang //name of image or image id you created while building docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After docker run in daemon mode, use&lt;br&gt;
&lt;br&gt;
&lt;code&gt;docker ps&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
to know the running instance inside docker.&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
ed07831e976a        docker-icinga-env   "fresh"             About an hour ago   Up About an hour    0.0.0.0:8090-&amp;gt;8090/tcp   golang-env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go, You have a running instance inside docker which you can access through browser &lt;strong&gt;localhost:8090&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now, Run the following command in the running container:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker exec -it &amp;lt;runnning container name or id&amp;gt; /bin/bash&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This will create a new Bash session in the container golang-env.This command will take you inside running command where you can check logs and do Whatever hell you like because You have a running instance. It's that easy&lt;/p&gt;

</description>
      <category>docker</category>
      <category>go</category>
    </item>
  </channel>
</rss>
