<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kavishka Sasindu on Medium]]></title>
        <description><![CDATA[Stories by Kavishka Sasindu on Medium]]></description>
        <link>https://medium.com/@sasindu0215?source=rss-9331d0ca78b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GFnQPuFqdJMune0SGxXryQ.jpeg</url>
            <title>Stories by Kavishka Sasindu on Medium</title>
            <link>https://medium.com/@sasindu0215?source=rss-9331d0ca78b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:42:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sasindu0215/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to configure MySQL Server on Ubuntu Server]]></title>
            <link>https://medium.com/@sasindu0215/how-to-configure-mysql-server-on-ubuntu-server-20b197463ba8?source=rss-9331d0ca78b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/20b197463ba8</guid>
            <category><![CDATA[mysql-server]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[vm]]></category>
            <dc:creator><![CDATA[Kavishka Sasindu]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 20:07:35 GMT</pubDate>
            <atom:updated>2025-06-30T20:07:35.201Z</atom:updated>
            <content:encoded><![CDATA[<p>So basically, in the modern world, everything contains data. That can be physical data and logical data, but in the case of how we store our data.</p><p>For that, our physical data can be stored in files. In the context of storing data, when we come to logical data, it can be used by some applications for personal services based on the data.</p><p><em>As an example, think you have your mobile banking application. So here you have many functionalities to perform services like transferring data, topping up data, etc. For that, your data must be stored in a secure place in the logical environment.</em></p><p><strong>Now comes the solution as databases. Which means we can store our logical data in a logical environment, it called a database.</strong></p><p>For the availability those databases need to available for 24/7 because users are accessed the application or communicate with their data all the time. Now the database servers in comming as the solution. In the database server we can create databases those databases can be used 24/7.</p><p><strong><em>Database servers are specialized computers (physical) that run database management systems (DBMS) and host one or more databases (logical). These servers ensure that data is available, secure, and accessible at all times, supporting features like multi-user access, data integrity, and real-time processing — critical for applications like mobile banking that must be available 24/7.</em></strong></p><p>As an example mysql-server.MySQL Server is a foundational technology for modern applications that require secure, reliable, and scalable data management. It abstracts the complexities of physical storage while providing powerful logical data organization and access, making it a standard choice for applications that need to be available and performant at all times.</p><p>Now we look at into how to configure mysql-server on ubuntu virtual machine.</p><pre>First you need to create a ubuntu virtual machine.( use cloud services like AWS,AZURE,GCP etc)</pre><p><strong>STEP 1 →</strong></p><p><strong>Then after log into ubuntu vm and update(fetch the latest version of packages) the and upgrade( install the outdatd software packages that you fetched) the packages list.</strong></p><pre>sudo apt update -y &amp;&amp; sudo apt upgrade -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8JG_ccxklS7ZggS0cz5fg.png" /></figure><p><strong>STEP 2 → Now install the mysql-server on to your ubuntu virtual machine</strong></p><pre>sudo apt install mysql-server -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQ6hbkeGpcqA1ndZ6dl3QA.png" /></figure><p><strong>STEP 3 → Then we need to to following steps on the secure installation</strong></p><p>after below command you have pop up the below steps to proceed</p><pre>sudo mysql_secure_installation</pre><ol><li>setup root password</li><li>remove access to anonymous users</li><li>disallow remote root login</li><li>remove test database</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*hKdodNRHaBvv-RXs9KXo3Q.png" /><figcaption>run mysql_secure_installation command</figcaption></figure><blockquote><strong>Setup root password and remove access to the anonymous user</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E_Q_9_1CKR2WHMAOjFDhbA.png" /></figure><blockquote><strong>Disallow remote root login</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Af0hvvAofWtnJawcBX56dg.png" /></figure><blockquote><strong>Remove test databases</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*jsL5z-azxUTgermZ_qUi7g.png" /></figure><blockquote><strong>Reload privilges table</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*8YgcYiB6MRNcgFjq2X3Vww.png" /></figure><p>then all done for the 3rd step.</p><p><strong>STEP 4 → login to mysql using root username and configured password in above root password setup</strong></p><pre>mysql -u root -p   #(after typing this command press enter it prompt the enter password section)</pre><p><strong>STEP 5 → Create user for accessing the database for the specific host or all host addresses.</strong></p><pre>CREATE USER &quot;&lt;username&gt;&quot;@&quot;&lt;host ip address&gt;&quot; IDENTIFIED BY &quot;&lt;password&gt;&quot;;<br><br>example: <br>CREATE USER &quot;ksdev&quot;@&quot;192.168.10.55&quot; IDENTIFIED BY &quot;12345&quot;;</pre><p>in here host address is your accessing machine address it can be vm or localhost.</p><p><strong>STEP 6 → Then grant privilleges to the database (all privilleges)</strong></p><pre>GRANT ALL PRIVILLEGES ON &lt;databse name&gt;.* TO &quot;&lt;usernem&gt;&quot;@&quot;&lt;host ip address&gt;&quot; WITH GRANT OPTION;<br><br>#( 1.&lt;databse name&gt;.*  --&gt; it tell all tables in the specific database can be have all access<br>   2. *.* --&gt; it tell all the database and all the tables have all access)</pre><p><strong>STEP 7 → exit and log with your password and username</strong></p><pre>exit  #(it exit the mysql)</pre><pre>#(login with your username and password)<br><br>mysql -u &lt;username&gt; -p #(press enter that prompt the enter password and enter your password))</pre><p><strong>STEP 8 → Now you can use your sql server which are run the Database Management System with hosting multiple databses.</strong></p><blockquote><strong>Summary</strong></blockquote><p>In summary, modern applications rely on databases like MySQL Server to store, organize, and secure data efficiently. While physical storage handles where data is kept, logical databases manage how data is accessed and used by applications — enabling features like mobile banking, real-time transactions, and 24/7 availability.</p><p>Configuring your SQL server — whether MySQL, SQL Server, or another system — ensures optimal performance, scalability, and security. By following best practices in setup, monitoring, and maintenance, you provide a robust foundation for applications that need to serve users around the clock. Ultimately, understanding both the physical and logical aspects of data storage, along with proper server configuration, empowers developers and organizations to deliver reliable, fast, and secure digital experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20b197463ba8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating AWS Infrastructure and Deployment with Terraform and Ansible]]></title>
            <link>https://medium.com/@sasindu0215/automating-aws-infrastructure-and-deployment-with-terraform-and-ansible-33950a5f6ff0?source=rss-9331d0ca78b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/33950a5f6ff0</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Kavishka Sasindu]]></dc:creator>
            <pubDate>Sun, 12 Jan 2025 21:41:12 GMT</pubDate>
            <atom:updated>2025-01-12T21:41:12.373Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll walk you through how I automated the deployment of a robust AWS infrastructure using Terraform and configured the deployment of applications using Ansible. This project highlights the synergy between infrastructure as code (IaC) and configuration management tools to achieve scalable, repeatable, and efficient workflows.</p><h3>Project Overview</h3><p>The project involved the following:</p><ol><li><strong>AWS Infrastructure Automation</strong> using Terraform to provision:</li></ol><ul><li>A Virtual Private Cloud (VPC) with public subnets in multiple availability zones.</li><li>An Application Load Balancer (ALB) for load distribution.</li><li>EC2 instances configured to host a static website.</li><li>An Ansible server for configuration management.</li></ul><p>2. <strong>Application Deployment and Configuration</strong> using Ansible to:</p><ul><li>Install and configure Apache on the web servers.</li><li>Deploy static website files to the web servers.</li></ul><p>Here’s a high-level architecture diagram of the infrastructure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W--tQQLjv7jFhl5vx-XLQg.png" /><figcaption>Project Architecture</figcaption></figure><h3>Step 1: Setting Up AWS Infrastructure with Terraform</h3><p>Terraform was used to define and provision the entire AWS infrastructure. Below is an overview of the Terraform resources:</p><h3>Terraform Resources Defined:</h3><ol><li><strong>Provider , VPC and Subnets</strong></li></ol><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br># Creating VPC <br>resource &quot;aws_vpc&quot; &quot;project_vpc&quot; {<br>  cidr_block           = &quot;10.0.0.0/16&quot;<br>  instance_tenancy     = &quot;default&quot;<br>  enable_dns_support   = true<br>  enable_dns_hostnames = true<br><br>  tags = {<br>    Name = &quot;project_vpc&quot;<br>  }<br>}<br><br>#creating internet gateway<br>resource &quot;aws_internet_gateway&quot; &quot;project_igw&quot; {<br>  vpc_id = aws_vpc.project_vpc.id<br><br>  tags = {<br>    Name = &quot;project_igw&quot;<br>  }<br>}<br><br>#create public subnet 1<br>resource &quot;aws_subnet&quot; &quot;public_subnet_1&quot; {<br>  vpc_id                  = aws_vpc.project_vpc.id<br>  cidr_block              = &quot;10.0.1.0/24&quot;<br>  availability_zone       = &quot;us-east-1a&quot;<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;public_subnet_1&quot;<br>  }<br>}<br><br>#create public subnet 2<br>resource &quot;aws_subnet&quot; &quot;public_subnet_2&quot; {<br>  vpc_id                  = aws_vpc.project_vpc.id<br>  cidr_block              = &quot;10.0.2.0/24&quot;<br>  availability_zone       = &quot;us-east-1b&quot;<br>  map_public_ip_on_launch = true<br><br>  tags = {<br>    Name = &quot;public_subnet_2&quot;<br>  }<br>}</pre><p>2. <strong>Security Groups</strong></p><ul><li>Allow SSH and HTTP access to instances and ALB.</li></ul><pre>#security group and rule<br>resource &quot;aws_security_group&quot; &quot;instance_security_group&quot; {<br>  name        = &quot;instance_security_group&quot;<br>  description = &quot;Allow security rules for ec2 instance&quot;<br>  vpc_id      = aws_vpc.project_vpc.id<br><br>  tags = {<br>    Name = &quot;Allow inbound and outbound rules&quot;<br>  }<br>}<br><br>#Security rules for instance<br>resource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;allow_ssh_from_my_ip&quot; {<br>  security_group_id = aws_security_group.instance_security_group.id<br>  cidr_ipv4         = &quot;175.157.23.47/32&quot;<br>  from_port         = 22<br>  ip_protocol       = &quot;tcp&quot;<br>  to_port           = 22<br><br>  tags = {<br>    Name = &quot;Allow SSH from my ip&quot;<br>  }<br>}<br><br># Allow SSH from the Ansible security group<br>resource &quot;aws_security_group_rule&quot; &quot;allow_ssh_from_ansible_sg&quot; {<br>  type                     = &quot;ingress&quot;<br>  from_port                = 22<br>  to_port                  = 22<br>  protocol                 = &quot;tcp&quot;<br>  security_group_id        = aws_security_group.instance_security_group.id<br>  source_security_group_id = aws_security_group.ansible_sg.id<br><br>  description = &quot;Allow SSH from Ansible security group&quot;<br>}<br><br>resource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;allow_http&quot; {<br>  security_group_id = aws_security_group.instance_security_group.id<br>  cidr_ipv4         = &quot;0.0.0.0/0&quot;<br>  from_port         = 80<br>  ip_protocol       = &quot;tcp&quot;<br>  to_port           = 80<br><br>  tags = {<br>    Name = &quot;Allow HTTP&quot;<br>  }<br>}<br><br>resource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;allow_icmp&quot; {<br>  security_group_id = aws_security_group.instance_security_group.id<br>  cidr_ipv4         = &quot;0.0.0.0/0&quot;<br>  from_port         = -1<br>  to_port           = -1<br>  ip_protocol       = &quot;icmp&quot;<br><br>  tags = {<br>    Name = &quot;Allow ICMP&quot;<br>  }<br>}<br><br>resource &quot;aws_vpc_security_group_egress_rule&quot; &quot;allow_all_outbound_traffic&quot; {<br>  security_group_id = aws_security_group.instance_security_group.id<br>  cidr_ipv4         = &quot;0.0.0.0/0&quot;<br>  ip_protocol       = &quot;-1&quot;<br><br>  tags = {<br>    Name = &quot;Allow all outbound traffic&quot;<br>  }<br>}<br><br><br>#scurity group for application load balancer<br>resource &quot;aws_security_group&quot; &quot;alb_sg&quot; {<br>  name        = &quot;alb_sg&quot;<br>  description = &quot;Allow security rules for application load balancer&quot;<br>  vpc_id      = aws_vpc.project_vpc.id<br><br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br>#ansible security group<br>resource &quot;aws_security_group&quot; &quot;ansible_sg&quot; {<br>  name        = &quot;ansible_sg&quot;<br>  description = &quot;Allow security rules for ansible&quot;<br>  vpc_id      = aws_vpc.project_vpc.id<br>}<br><br>resource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;allow_ssh_my_ip&quot; {<br>  security_group_id = aws_security_group.ansible_sg.id<br>  cidr_ipv4         = &quot;175.157.23.47/32&quot;<br>  from_port         = 22<br>  ip_protocol       = &quot;tcp&quot;<br>  to_port           = 22<br><br>  tags = {<br>    Name = &quot;Allow SSH from my ip&quot;<br>  }<br>}<br><br>resource &quot;aws_vpc_security_group_ingress_rule&quot; &quot;allow_http_ansible&quot; {<br>  security_group_id = aws_security_group.ansible_sg.id<br>  cidr_ipv4         = &quot;0.0.0.0/0&quot;<br>  from_port         = 80<br>  ip_protocol       = &quot;tcp&quot;<br>  to_port           = 80<br><br>  tags = {<br>    Name = &quot;Allow http ansible&quot;<br>  }<br>}<br><br>resource &quot;aws_vpc_security_group_egress_rule&quot; &quot;allow_ansible_outbound&quot; {<br>  security_group_id = aws_security_group.ansible_sg.id<br>  cidr_ipv4         = &quot;0.0.0.0/0&quot;<br>  ip_protocol       = &quot;-1&quot;<br><br>  tags = {<br>    Name = &quot;Allow SSH from my ip&quot;<br>  }<br>}</pre><p><strong>3. Application Load Balancer</strong></p><pre>#create a target group fro ALB<br>resource &quot;aws_lb_target_group&quot; &quot;target_group_alb&quot; {<br>  name     = &quot;load-balancer-target&quot;<br>  port     = 80<br>  protocol = &quot;HTTP&quot;<br>  vpc_id   = aws_vpc.project_vpc.id<br><br>}<br><br>#attach instances to target group<br>resource &quot;aws_lb_target_group_attachment&quot; &quot;attachment_1&quot; {<br>  target_group_arn = aws_lb_target_group.target_group_alb.arn<br>  target_id        = aws_instance.web01.id<br>  port             = 80<br>}<br><br>resource &quot;aws_lb_target_group_attachment&quot; &quot;attachment_2&quot; {<br>  target_group_arn = aws_lb_target_group.target_group_alb.arn<br>  target_id        = aws_instance.web02.id<br>  port             = 80<br>}<br><br>#create application load balancer<br>resource &quot;aws_lb&quot; &quot;alb&quot; {<br>  name               = &quot;alb&quot;<br>  internal           = false<br>  load_balancer_type = &quot;application&quot;<br>  security_groups    = [aws_security_group.alb_sg.id]<br>  subnets            = [aws_subnet.public_subnet_1.id, aws_subnet.public_subnet_2.id]<br><br>  tags = {<br>    Environment = &quot;production&quot;<br>  }<br>}<br><br>#create listener for ALB<br>resource &quot;aws_lb_listener&quot; &quot;alb_listener&quot; {<br>  load_balancer_arn = aws_lb.alb.arn<br>  port              = &quot;80&quot;<br>  protocol          = &quot;HTTP&quot;<br><br>  default_action {<br>    type             = &quot;forward&quot;<br>    target_group_arn = aws_lb_target_group.target_group_alb.arn<br>  }<br>}<br><br>output &quot;alb_dns_name&quot; {<br>  value = aws_lb.alb.dns_name<br>}</pre><p>4. <strong>EC2 Instances</strong></p><pre>#ansible server<br>resource &quot;aws_instance&quot; &quot;ansible_server&quot; {<br>  ami                    = &quot;ami-0e2c8caa4b6378d8c&quot;<br>  instance_type          = &quot;t2.micro&quot;<br>  key_name               = aws_key_pair.ec2_key_pair.key_name<br>  subnet_id              = aws_subnet.public_subnet_1.id<br>  vpc_security_group_ids = [aws_security_group.ansible_sg.id]<br><br>  tags = {<br>    Name = &quot;Ansible Server&quot;<br>  }<br>}<br><br>output &quot;ansible_server_public_ip&quot; {<br>  value = aws_instance.ansible_server.public_ip<br>}<br><br>#web01<br>resource &quot;aws_instance&quot; &quot;web01&quot; {<br>  ami                    = &quot;ami-0e2c8caa4b6378d8c&quot;<br>  instance_type          = &quot;t2.micro&quot;<br>  key_name               = aws_key_pair.ec2_key_pair.key_name<br>  subnet_id              = aws_subnet.public_subnet_1.id<br>  vpc_security_group_ids = [aws_security_group.instance_security_group.id]<br><br>  tags = {<br>    Name = &quot;web01&quot;<br>  }<br>}<br><br>output &quot;web01_public_ip&quot; {<br>  value = aws_instance.web01.public_ip<br>}<br><br><br>#web02<br>resource &quot;aws_instance&quot; &quot;web02&quot; {<br>  ami                    = &quot;ami-0e2c8caa4b6378d8c&quot;<br>  instance_type          = &quot;t2.micro&quot;<br>  key_name               = aws_key_pair.ec2_key_pair.key_name<br>  subnet_id              = aws_subnet.public_subnet_2.id<br>  vpc_security_group_ids = [aws_security_group.instance_security_group.id]<br><br>  tags = {<br>    Name = &quot;web02&quot;<br>  }<br>}<br><br>output &quot;web02_public_ip&quot; {<br>  value = aws_instance.web02.public_ip<br>}</pre><p>Once the Terraform scripts were ready, I ran the following commands to deploy the infrastructure:</p><pre>terraform init<br>terraform plan<br>terraform apply</pre><h3>Step 2: Configuring Deployment with Ansible</h3><p>After provisioning the infrastructure, I used Ansible to configure the web servers and deploy the static website.</p><h3>Ansible.cfg</h3><p>Configuration for ansible</p><pre>[defaults]<br>host_key_checking = False<br>inventory = ./inventory<br>forks = 5<br><br>[privilage_escalation]<br>become = True<br>become_method = sudo</pre><h3>Inventory File</h3><p>The inventory file defines the target hosts for Ansible:</p><pre>all:<br>  hosts:<br>    web01:<br>      ansible_host: 10.0.1.189<br>    web02:<br>      ansible_host: 10.0.2.195<br><br>  children:<br>    webservers:<br>      hosts:<br>        web01:<br>        web02:</pre><h3>Ansible Playbook</h3><p>Here’s the playbook to install Apache and deploy the static website:</p><pre>---<br>- name: Provisioning webservers<br>  hosts: webservers<br>  become: yes<br>  tasks:<br>    - name: Instll Apache2<br>      ansible.builtin.apt:<br>        name: apache2<br>        state: present<br><br>    - name: Start Apache2 service<br>      ansible.builtin.service:<br>        name: apache2<br>        state: started<br>        enabled: yes<br><br>    - name: Copy index.html file<br>      ansible.builtin.copy:<br>        src: 2137_barista_cafe/<br>        dest: /var/www/html/</pre><h3>Executing the Playbook</h3><p>Next as your project structure execute the playbook</p><h3>Outcome</h3><p>Once the playbook executed successfully:</p><ul><li>The Apache web server was installed and running on both EC2 instances.</li><li>The static website files were copied to /var/www/html/.</li><li>The Application Load Balancer distributed traffic between the two web servers.</li></ul><p>Visiting the ALB DNS name in a browser displayed the deployed static website.</p><h3>Challenges Faced</h3><ol><li><strong>SSH Connectivity Issues:</strong> Initially, SSH failed due to improper security group rules. I ensured that the Ansible server’s security group was allowed access to the web server security group.</li><li><strong>Permission Errors:</strong> During the file copy task, I faced permission issues. Adding the become: yes directive resolved this.</li><li><strong>Terraform State Management:</strong> Ensuring consistent state files required proper backend configuration.</li></ol><h3>Key Learnings</h3><ul><li>Combining Terraform and Ansible is a powerful approach for managing cloud infrastructure and configuration.</li><li>Debugging SSH and permission-related issues requires a deep understanding of security group rules and user permissions.</li><li>Modularizing Terraform and Ansible configurations enhances reusability and readability.</li></ul><h3>Conclusion</h3><p>This project demonstrates how IaC tools like Terraform and configuration management tools like Ansible can streamline cloud deployments. By automating infrastructure provisioning and configuration, we can achieve scalable, efficient, and repeatable workflows for modern applications.</p><blockquote><strong>Also this is fully hardcoded project…..</strong></blockquote><p>Feel free to share your thoughts or ask questions in the comments. Let’s connect and discuss more about automation and DevOps practices!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33950a5f6ff0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Secure CI/CD Pipeline with Jenkins, Docker, and Trivy on AWS EC2]]></title>
            <link>https://medium.com/@sasindu0215/building-a-secure-ci-cd-pipeline-with-jenkins-docker-and-trivy-on-aws-ec2-e8cb62fc7c43?source=rss-9331d0ca78b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8cb62fc7c43</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[continous-deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[pipeline-as-code]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Kavishka Sasindu]]></dc:creator>
            <pubDate>Tue, 17 Dec 2024 07:28:21 GMT</pubDate>
            <atom:updated>2024-12-17T07:37:58.002Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction</strong></h4><p>In the DevOps world, building secure and automated CI/CD pipelines is essential for fast and reliable software delivery. In this article, I’ll walk you through a <strong>CI/CD pipeline</strong> that uses <strong>Jenkins</strong> for automation, <strong>Docker</strong> for containerization, and <strong>Trivy</strong> for security scanning. This pipeline runs on an <strong>AWS EC2 instance</strong> and integrates with <strong>GitHub</strong> and <strong>Docker Hub</strong> for version control and image hosting.</p><h4><strong>Overview of the CI/CD Pipeline</strong></h4><p>Here’s how the pipeline works:</p><ol><li><strong>Developer pushes code to GitHub.</strong></li><li><strong>Jenkins fetches the code using GitHub , also use webhooks for realtime version management update and runs Build and Test jobs.</strong></li><li><strong>Jenkins builds the Docker image using NPM (Node.js).</strong></li><li><strong>Trivy scans the Docker image for vulnerabilities.</strong></li><li><strong>The secure Docker image is deployed to Docker Hub.</strong></li></ol><p>This automation ensures that the software is built, tested, secured, and deployed seamlessly.</p><h4><strong>Architecture Diagram</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*BYS21TJounS4ynwl9YuAEQ.png" /><figcaption>detailed diagram showcasing the flow of code, build, testing, and deployment.</figcaption></figure><h4><strong>Step-by-Step Guide</strong></h4><ol><li><strong>Setting Up the AWS EC2 Instance</strong></li></ol><p>We will host our Jenkins server on an AWS EC2 instance.</p><ul><li>Launch an <strong>EC2 instance</strong> (Ubuntu Server).</li><li>Install Jenkins (<a href="https://www.jenkins.io/doc/book/installing/">https://www.jenkins.io/doc/book/installing/</a>)</li><li>Install Docker. (<a href="https://docs.docker.com/engine/install/">https://docs.docker.com/engine/install/</a>)</li></ul><p><strong>2. Configuring Jenkins</strong></p><p>Install required plugin</p><ul><li>Docker Pipeline Plugin</li><li>Pipeline Plugin</li><li>Git Plugin</li></ul><p><strong>3. Setting Up GitHub Webhooks</strong></p><ul><li>Go to your GitHub repository settings.</li><li>Add a webhook pointing to your Jenkins server</li><li>This triggers Jenkins whenever you push code.</li></ul><pre>http://&lt;EC2-IP&gt;:8080/github-webhook/</pre><p><strong>4</strong>. <strong>Writing the Jenkins Pipeline Script</strong></p><p>Create a Jenkinsfile in your GitHub repository to automate the build, test, scan, and deployment steps.</p><p>Here’s the full pipeline script:</p><pre>pipeline {<br>    agent any<br>    tools {<br>        nodejs &#39;Node-22.11&#39;<br>    }<br>    environment {<br>        IMAGE_NAME = &#39;express-api&#39;<br>        DOCKER_USERNSME = &#39;&#39;<br>        DOCKER_PASSWORD = &#39;&#39;<br>    }<br>    stages {<br>        stage(&#39;Fetch&#39;) {<br>            steps {<br>                cleanWs()<br>                git url: &#39;https://github.com/KavishkaSasindu/express-api-CI-CD.git&#39;, branch: &#39;main&#39;<br>            }<br>        }<br>        stage(&#39;install dependencies&#39;) {<br>            steps {<br>                script{<br>                    dir(&#39;api&#39;) {<br>                        sh &#39;npm install&#39;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&#39;Build&#39;) {<br>            steps {<br>                script {<br>                    dir(&#39;api&#39;) {<br>                        sh &#39;npm run build&#39;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&#39;Test&#39;) {<br>            steps {<br>                script {<br>                    dir(&#39;api&#39;) {<br>                        sh &#39;npm test&#39;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&#39;build image&#39;) {<br>            steps {<br>                script {<br>                    dir(&#39;api&#39;) {<br>                        sh &#39;docker build -t ${IMAGE_NAME}:${BUILD_NUMBER} .&#39;<br>                    }<br>                }<br>            }<br>        }<br>        stage(&quot;push image docker hub&quot;) {<br>            steps {<br>                script {<br>                    sh &#39;&#39;&#39;<br>                        trivy image ${IMAGE_NAME}:${BUILD_NUMBER}<br>                        docker login -u ${DOCKER_USERNSME} -p ${DOCKER_PASSWORD}<br>                        docker tag ${IMAGE_NAME}:${BUILD_NUMBER} ${DOCKER_USERNSME}/${IMAGE_NAME}:${BUILD_NUMBER}<br>                        docker push ${DOCKER_USERNSME}/${IMAGE_NAME}:${BUILD_NUMBER}<br>                    &#39;&#39;&#39;<br>                }<br>            }<br>        }<br>    }<br>    post {<br>        always {<br>            cleanWs()<br>        }<br>        success {<br>            echo &#39;Build Success&#39;<br>        }<br>        failure {<br>            echo &#39;Build Failure&#39;<br>        }<br>    }<br>}</pre><p>5. <strong>Dockerfile</strong></p><p>Create a simple Dockerfile to containerize your application:</p><p><strong>6. Adding Trivy for Security Scanning</strong></p><p>Trivy scans Docker images for vulnerabilities before deployment. In the Jenkins pipeline, we integrated Trivy in the <strong>“Scan Docker Image with Trivy”</strong> stage.</p><p>Trivy flags vulnerabilities based on their severity (HIGH, CRITICAL) and ensures no insecure image gets pushed to Docker Hub.</p><p><strong>7. Pushing to Docker Hub</strong></p><p>After the image is scanned and verified, Jenkins pushes the image to Docker Hub. Make sure your Docker Hub credentials are configured in Jenkins securely.</p><h3>End-to-End Pipeline Flow</h3><p>Here’s how the pipeline flows:</p><ol><li><strong>Developer</strong> writes code and pushes it to GitHub.</li><li><strong>GitHub</strong> triggers Jenkins via a webhook.</li><li><strong>Jenkins</strong> fetches the code, installs dependencies, and runs tests.</li><li>Jenkins builds the <strong>Docker image</strong>.</li><li>Jenkins scans the image using <strong>Trivy</strong> to identify vulnerabilities.</li><li>If the image passes the scan, it is pushed to <strong>Docker Hub</strong>.</li></ol><h3>Benefits of This Pipeline</h3><ol><li><strong>Automation</strong>: The pipeline automates the entire build, test, and deployment process.</li><li><strong>Security</strong>: Trivy ensures that only secure images are deployed.</li><li><strong>Scalability</strong>: Using AWS EC2 provides flexibility and scalability.</li><li><strong>Reliability</strong>: Jenkins ensures each build is consistent and reliable.</li></ol><h3>Conclusion</h3><p>By integrating <strong>Jenkins</strong>, <strong>Docker</strong>, and <strong>Trivy</strong>, we created a secure and automated CI/CD pipeline. This ensures:</p><ul><li>Code is tested and verified.</li><li>Vulnerabilities are scanned and prevented from entering production.</li><li>Docker images are reliably built and deployed.</li></ul><p>This pipeline serves as a foundation for implementing DevSecOps best practices in your projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8cb62fc7c43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VPROFILE PROJECT (Local)]]></title>
            <link>https://medium.com/@sasindu0215/vprofile-project-local-3f7910e4037f?source=rss-9331d0ca78b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f7910e4037f</guid>
            <dc:creator><![CDATA[Kavishka Sasindu]]></dc:creator>
            <pubDate>Wed, 27 Nov 2024 15:05:04 GMT</pubDate>
            <atom:updated>2024-11-27T15:05:04.381Z</atom:updated>
            <content:encoded><![CDATA[<p>This is multi-tier web application stack project and setup would be locally (Desktop or Laptop). This project is very important for learn DevOps because it provide “What is in DevOps ?”….</p><p>So this is the baseline for learn DevOps tools. Also you can deploy your own web application project in your local computer.</p><p><strong><em>Scenario</em></strong></p><p>Think you are working in a project and this project has various services like Database Service(MySQL ,PostgreSQL), Application Service(Apache Tomcat Server), Web Services(Nginx) etc.</p><p><strong><em>Problem</em></strong></p><p>Sometime we have to making changes in real servers. It is not very comfortable and also local setup can be very complex when we implement it manually. Cause to a lot of time consuming. It is not repeatable.</p><p><strong><em>Solution</em></strong></p><p>This is local setup but it would be automated ,repeatable, and also IAAC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*2nlqiIWvimcZU48UKHgtNA.png" /><figcaption>Solution</figcaption></figure><h3><strong><em>Requirements</em></strong></h3><p><strong><em>Tools</em></strong></p><p>1.Hypervisor → Oracle VM Virtual-box</p><p>2.Automation -&gt; Vagrant</p><p>3.CLI (For Windows )-&gt;Git Bash</p><p>CLI(Mac) → Terminal</p><p>4.IDE -&gt; Sublime Text</p><p><strong><em>Project Services</em></strong></p><ol><li><strong>Nginx </strong>→ It has some functions..<br> <strong><em>Web Server</em></strong> = It acts as a web server. So it can handle client request from static content and server very faster than tomcat.<br> <strong><em>Reverse Proxy</em> </strong>= Nginx server can send the client request for other servers it important to load balancing.<br> <strong><em>Load balancing</em></strong> = This is also a main function, it can act as a load balancer. When the high traffic come to Nginx server it distributes the traffic to other servers.</li><li><strong>Apache Tomcat Server → </strong>It is a web sever and it can run java servlet containers also it can handle dynamic request from client (APIs). JSP(Java Server pages) is compiled into java using Apache Tomcat Server.</li><li><strong>MySQL → </strong>Relational Database and run with a server. It can store user inputs and process those for various tasks to perform client requests.</li><li><strong>Memcached </strong>→ is an open-source, high-performance, distributed memory caching system. It is primarily used to <strong>speed up dynamic web applications</strong> by reducing the load on databases and backend systems.</li><li>RabbitMQ → It is a Message Broker or Queue Agent. It can handle asynchronous communication between different application and components. It means producer and consumers can exchange the messages.</li></ol><p>Additionally NFS</p><p><strong><em>Note ==&gt; </em></strong>(RabbitMQ and Memcached articles were published. Checkout my articles).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxM4tYIbFkehYV-nTOAraw.jpeg" /><figcaption>How to work vprofile project.</figcaption></figure><p><strong><em>Note : Project setup in separate article. So get the idea of project and will see project setup article.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f7910e4037f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Continuous Integration?]]></title>
            <link>https://medium.com/@sasindu0215/what-is-continuous-integration-6db0e59210f5?source=rss-9331d0ca78b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6db0e59210f5</guid>
            <dc:creator><![CDATA[Kavishka Sasindu]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 15:51:46 GMT</pubDate>
            <atom:updated>2024-11-20T15:51:46.753Z</atom:updated>
            <content:encoded><![CDATA[<p>Simply in a software company, there can be many developers. Those Developers write several codes while developing software. Those source codes should be kept in the centralized location.</p><h3><strong>What is that centralized location?</strong></h3><p>This centralized location is called a version control system like GitHub. Here it has centralized repositories and source codes can be pushed by the developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FoLOG8DiS4A9BArKfC7y6w.jpeg" /><figcaption>Version Control System</figcaption></figure><p><strong>Next……</strong></p><p>That code is sent to the build server which fetches the code and performs some actions.</p><blockquote>build : build the source code into executable file.</blockquote><blockquote>test : running automated tested to ensure the code is correct</blockquote><blockquote>evaluate : accessing code , running code test tools and checking the result.</blockquote><p>which can generate artifact(simply sotware). This artifact is kept in the artifact repo. Artifact packaging format based on programming language.</p><p>for example:- Java(war or jar), windows(DDL, EXE, MSI), ZIP/TAR</p><p>after deploying artifacts to the servers and all done and approved then ship it to production servers.</p><h3><strong>What is this build server?</strong></h3><p>The build server is responsible for building source code into executable files (runnable code).</p><p>example for build servers: Jenkins / GitHub Actions / GitLab CI/CD / CircleCC</p><p>example for build tools: Maven(Java) / Make(C, C++) / Webpack(javascript) / npm(Node js) / Ant(Java), etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBFDubpuA9gFhTwEx5Ok_g.png" /><figcaption>Jenkins Server</figcaption></figure><h3><strong>Main Problem</strong></h3><p>Think developers work for 3 days without getting any holiday. Then push the code into the GitHub repo move to the build server and build and test the fetched code. after the test, it can have many errors so developers need to fix those errors. unfortunately, they do have not a vacation.</p><blockquote><strong>Solution for this</strong></blockquote><p>Continuous Process is the solution for this. When the developers push a single commit to the repo move it through an automated system to the build server, and build and test the code fetched, then it has errors and sends a notification to the developers. Developers fix errors and again push to the repo. continuously process will happen and when it testing phase is approved send it to the artifact repo. This is called <strong>Continuous Integration.</strong></p><blockquote><strong>Continuous Intergration</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKvMdWGiuvoR7TWrpJfkBQ.png" /><figcaption>Continuous Process</figcaption></figure><p>Main Goal:- using CI we can identify errors/bugs in the code in the early stage and then fix those without multiplying those errors issues.</p><p>Also, code quality can improve.</p><p>When new code or new change is implemented we can know immediately (fast feedback).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6db0e59210f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>