<?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 Żimuzo Obiechina on Medium]]></title>
        <description><![CDATA[Stories by Żimuzo Obiechina on Medium]]></description>
        <link>https://medium.com/@ziimm?source=rss-f86bf38e5a4b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JIEmd9q_TZOVyiYM3bDXsg@2x.jpeg</url>
            <title>Stories by Żimuzo Obiechina on Medium</title>
            <link>https://medium.com/@ziimm?source=rss-f86bf38e5a4b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 18:28:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ziimm/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 Setup a Terraform Remote Backend  in Google Cloud]]></title>
            <link>https://ziimm.medium.com/how-to-setup-a-terraform-remote-backend-in-google-cloud-6bb3f1829d5c?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bb3f1829d5c</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Thu, 28 Oct 2021 10:40:48 GMT</pubDate>
            <atom:updated>2021-10-28T13:58:24.573Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Setup a Terraform Remote Backend in Google Cloud</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMy_KSraiH74f2uaRcnEww.png" /></figure><p>Terraform is an infrastructure provisioning automation tool that allows you to specify resources to run your application — in the cloud or on-premises — using code. This code is written in Hashicorp Configuration Language (HCL) syntax in a declarative manner, within files with a .tf extension. You only have to define the resources you need, Terraform will handle the rest.</p><h3>Objectives</h3><p>By the end of this article, you should understand:</p><ul><li>Common Terraform commands</li><li>How Terraform works</li><li>Why you need a remote backend</li><li>How to set up a remote backend in Google Cloud</li><li>Workspaces</li></ul><h3>Requirements</h3><p>To get started, you will need:</p><ul><li>A <a href="https://cloud.google.com/">Google Cloud</a> account</li><li>Google <a href="https://cloud.google.com/sdk/docs/install">Cloud SDK</a></li><li>Terraform — follow this <a href="https://www.terraform.io/downloads.html">link</a> to download and install on your PC</li><li>A code editor — VSCode, Sublime Text, etc.</li></ul><p>Before we dive into creating the remote backend, let’s take a brief look at some Terraform commands.</p><h3>Common Terraform commands</h3><p>The common commands when working with a remote backend are:</p><ul><li><a href="https://www.terraform.io/docs/cli/commands/init.html">terraform init</a> : This is the first command to initialize Terraform after writing a new Terraform configuration.</li><li><a href="https://www.terraform.io/docs/cli/commands/plan.html">terraform plan</a> : Detects changes by comparing your current configuration and the state file.</li><li><a href="https://www.terraform.io/docs/cli/commands/apply.html">terraform apply</a> : Executes any changes.</li><li><a href="https://www.terraform.io/docs/cli/commands/workspace/index.html">terraform workspace</a> : For managing workspaces.</li></ul><p>You can learn more about these commands and others in the <a href="https://www.terraform.io/docs/language/settings/backends/remote.html">Terraform documentation</a>.</p><h3>What happens under the hood?</h3><p>When you run Terraform, a state file is created. This state file is a record that maps the infrastructure created on the cloud to the resources defined in your Terraform configuration file. This file is a JSON format with a .tfstate extension.</p><p>Whenever you run terraform plan, the state is pulled down from local storage or a remote backend storage and compared with your current configuration to determine the changes to be made.</p><p>When you run terraform apply, these changes are executed and the state file is updated.</p><p>This is how Terraform can keep track of your infrastructure, making it possible to create, update and destroy infrastructure in an automated manner.</p><h3>Why do you need a remote backend?</h3><p>When it’s just you working on a personal Terraform project, the state file is stored locally — on your PC. However, when working on a team, with multiple individuals working on the project, the same state file will have to be shared. This comes with its own challenges:</p><ul><li>You need a shared location for the storage of state files.</li><li>Multiple people running terraform at the same time may result in data loss or file corruption.</li><li>Secure storage of sensitive data.</li></ul><p>This is why you need a remote backend—it solves these problems in the following ways:</p><ul><li>It provides a shared location for storing state files.</li><li>It supports <em>state locking.</em> This means that when terraform apply is run by a team member, a lock is placed on the state file to prevent another team member from running terraform apply at the same time. This averts the accidental duplication of deployments or data loss.</li><li>Most remote backends support encryption of state files, in transit and at rest, natively. In addition, there is also support for access control using identity management and permissions, to regulate who has access to state files and secrets.</li></ul><h3>Set up the remote backend</h3><p>Terraform supports a number of remote backend platforms — Google Cloud Storage, Amazon S3, Azure Storage and Terraform Cloud. We will be using storage services from Google Cloud — a Cloud Storage Bucket.</p><p>However, before we can configure the remote backend, we need to have an existing storage bucket. So let’s create one.</p><p>In your code editor, create an empty directory. Within this directory, create a main.tf file. We will define our configuration within this file.</p><p>The first step to using Terraform is to configure the cloud provider — so it knows what cloud provider API to connect with. The basic format used to define a resource in Terraform is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c26d02fdbc89fa657e3d95949d0a4c/href">https://medium.com/media/d3c26d02fdbc89fa657e3d95949d0a4c/href</a></iframe><p>So, in order to define GCP as our cloud provider, we use the following block of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/183763e4d8167bb77d4a405825df3d42/href">https://medium.com/media/183763e4d8167bb77d4a405825df3d42/href</a></iframe><p>credentials refers to the private key file of a GCP service account — this is needed for Terraform authentication to GCP. To obtain your private key file, navigate to <strong>IAM &amp; Admin</strong> &gt; <strong>Service Accounts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*lr5PYgjmDnoVKzyfg50eZQ.png" /></figure><p>Select the default Compute Engine service account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2n2W0UEwXfCtkXea27frwg.png" /></figure><p>Click on the <strong>Keys</strong> tab and then the <strong>Add Key</strong> button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBKdPXez7-n6Nb4GtJS-OQ.png" /></figure><p>Select <strong>Add new key</strong> &gt; select key type as JSON. Click <strong>Create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TqZ1yAlvBGr0wLT_279Wrw.png" /></figure><p>This downloads the private key file to your PC. Include the file in your project directory and then pass its path as the value to the variable credentials .</p><p>Next, create a bucket.tf file — to define the storage bucket — and add the following block of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc21a3b018d86e9ff41df192d070d3e9/href">https://medium.com/media/dc21a3b018d86e9ff41df192d070d3e9/href</a></iframe><p>This tells Terraform to create a storage bucket with the given name and location, in GCP. With <em>object versioning</em> enabled, whenever a state file is deleted — accidentally or otherwise — a version is kept; it does not get deleted permanently. This makes it possible to roll back to an older version if something goes wrong.</p><blockquote>For more on object versioning, see the <a href="https://cloud.google.com/storage/docs/object-versioning">documentation</a>.</blockquote><p>Now, that we have the cloud provider and storage bucket declared, navigate to your project directory within your terminal. Run terraform init to initialize Terraform and connect to GCP. You should have an output similar to this:</p><pre>$ terraform init</pre><pre>Initializing provider plugins...<br>- Checking for available provider plugins on <a href="https://releases.../">https://releases...</a><br>...</pre><pre>Terraform has been successfully initialized!<br>...</pre><p>Then, run terraform plan for a representation of the changes that Terraform will apply to create the storage bucket. The output should be:</p><pre>$ terraform plan</pre><pre>Terraform will perform the following actions:</pre><pre># google_storage_bucket.&lt;bucket_name&gt; will be created <br>+ resource &quot;google_storage_bucket&quot; &quot;your-bucket-name&quot; {<br>   ...<br>  }</pre><p>Follow the prompt, and run terraform apply to create the bucket.</p><p>Once the creation is complete, you should have an output similar to this:</p><pre>...<br>google_storage_bucket.&lt;bucket_name&gt;: Creation complete after 12s<br>...<br>Apply complete! Resources: 1 added, 0 changed, 0 destroyed.</pre><p>Head over to your GCP account to confirm that the storage bucket was created — Navigate to <strong>Cloud Storage</strong> &gt; <strong>Browser</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*q87Tfk48EFtsSekBDYbZzg.png" /></figure><p>You should see your created bucket on the Browser page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Chr7tyKS0pjmje0bH6F72A.png" /></figure><p>Now that we have a storage bucket created, let us define our remote backend configuration.</p><p>Add the following block of code within main.tf :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/241b59ab6967ca5db18a6e365121192e/href">https://medium.com/media/241b59ab6967ca5db18a6e365121192e/href</a></iframe><p>This block of code is specific to GCP. It tells Terraform to establish a remote backend in the bucket specified. As for the prefix variable, you can think of it as defining the name of the directory where all the state files will be stored (we will demonstrate this below).</p><p>Run terraform init to initialize the backend. You will see an output similar to this:</p><pre>$ terraform init</pre><pre>Initializing the backend...</pre><pre>Successfully configured the backend &quot;gcs&quot;! Terraform will automatically use this backend unless the backend configuration changes.</pre><pre>Initializing provider plugins...</pre><pre>...</pre><pre>Terraform has been successfully initialized!</pre><p>Now, when you navigate to <strong>Storage</strong> &gt; <strong>Browser</strong> and click on your bucket name, you should see a directory/folder named after the value you passed to prefix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoAMIoPP-mvK5OS_ehhRhQ.png" /></figure><p>You have officially configured a Terraform remote backend!</p><p>But, there’s more…</p><p>Click on the folder to view its content. You will notice that it contains a default.tfstate file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ab6LticaxgakJoh4bBWerQ.png" /></figure><p>This is the state file. But why does it have that name and where did it come from?</p><p>Cue “workspaces”.</p><h3>Workspaces</h3><p>A Terraform workspace is an isolated environment for storing state files. It allows you to run the same configuration file in different/separate environments. The state files are named after the workspace.</p><p>There is a default workspace created for you the first time you initialize Terraform, called default. If you do not create a new workspace, the default workspace is the active workspace for all the Terraform actions you run.</p><p>To view workspaces, run the command terraform workspace list. The output should be:</p><pre>$ terraform workspace list<br>* default</pre><p>The asterisk indicates the active workspace.</p><p>To create a new workspace, run the command terraform workspace new &lt;name&gt; . The output should be:</p><pre>$ terraform workspace new &lt;name&gt;<br><strong>Created and switched to workspace &quot;&lt;name&gt;&quot;!</strong></pre><pre><strong>You&#39;re now on a new, empty workspace. Workspaces isolate their state, so if you run &quot;terraform plan&quot; Terraform will not see any existing state for this configuration.</strong></pre><p>Now, when you run terraform workspace list , you will have two workspaces with an asterisk on the just created workspace:</p><pre>$ terraform workspace list<br>  default<br>* &lt;new workspace&gt;</pre><p>For demonstration purposes, let’s assume the new workspace created is called staging . The output will be:</p><pre>$ terraform workspace list<br>  default<br>* staging</pre><p>Within this new workspace, run terraform plan :</p><pre>$ terraform plan</pre><pre>Terraform will perform the following actions:</pre><pre># google_storage_bucket.&lt;bucket_name&gt; will be created <br>+ resource &quot;google_storage_bucket&quot; &quot;your-bucket-name&quot; {<br>   ...<br>  }</pre><p>You’ll notice that Terraform wants to create an entirely new storage bucket from scratch. Each workspace is completely isolated from the other — once within a workspace, Terraform has no knowledge of state files in other workspaces.</p><blockquote><strong>NOTE</strong>: Although Terraform can use a single configuration file in multiple work spaces, the resources created need to have unique name values. As a result, you will need to specify these values in a separate .tfvars file. But this is outside the scope of this article. Learn more <a href="https://www.terraform.io/docs/language/values/variables.html">here</a> and <a href="https://amazicworld.com/difference-between-variable-tf-and-variable-tfvars-in-terraform/">here</a>.</blockquote><p>Run terraform apply to create the new storage bucket.</p><p>Now, when you navigate to Cloud<strong> </strong>Storage &gt; Browser &gt; Bucket, you will find a new .tfstate state file created within the bucket, as seen in this image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQ7wpwYD3SxlemERTlNk5A.png" /></figure><p>Back in your project directory, you’ll also notice that you have the.tfstate file created by Terraform. This file should not be committed to Git version control to prevent the state file from being edited. This is because the state file is a private interface meant only for internal use within Terraform.</p><p>Also, it is best practice to create workspaces for different environments — development, staging, production — to avoid accidentally breaking the app in production.</p><h3>Clean up</h3><p>Run terraform destroy (in both workspaces) to take down the resources created in this demonstration to avoid incurring unplanned charges from the cloud provider.</p><h3>Done!</h3><p>Now you can collaborate seamlessly on your project through a remote backend. Explore the Terraform <a href="https://www.terraform.io/docs/language/settings/backends/remote.html">documentation</a> to learn more about remote backends.</p><p>To get you started using Terraform, you can check out my <a href="https://github.com/Z11mm/sca-project-c2-iac">repo</a> for some resource configurations.</p><p>~ <strong>Hope you found this article helpful. Thank you for reading!</strong> ~</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bb3f1829d5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set Up A CI/CD Pipeline with NodeJS, Jenkins and Google Cloud]]></title>
            <link>https://ziimm.medium.com/set-up-a-ci-cd-pipeline-with-nodejs-jenkins-and-google-cloud-cc63b7ed9f41?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc63b7ed9f41</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 18:06:13 GMT</pubDate>
            <atom:updated>2021-10-26T08:05:25.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HzqA8obpkkv6acYgJq2cHg.png" /></figure><p>This article describes how to set up a CI/CD pipeline in Jenkins that builds and deploys a NodeJS application to the Google Cloud Platform(GCP).</p><blockquote>Prior knowledge of how to manage users in Linux and how to configure an Nginx server is required.</blockquote><p>We will cover the following in this article:</p><ul><li>Create Compute Engine virtual machine(VM) instances on Google Cloud.</li><li>Install and configure necessary dependencies on VM.</li><li>Set up SSH credentials with GitHub.</li><li>Add GitHub webhook.</li><li>Create Jenkinsfile.</li><li>Set up Publish Over SSH in Jenkins.</li><li>Create CI/CD pipeline.</li></ul><h4>Prerequisites:</h4><ul><li>A Google Cloud account — if you do not already have an account, create one <a href="https://cloud.google.com/free">here</a>.</li><li>Jenkins<em> (v2.312)</em></li><li>Node <em>(v16.9.1)</em></li><li>npm <em>(v7.24.0)</em></li></ul><h3>Create virtual machine instances</h3><p>We will need to have the Jenkins application running on its server and the NodeJS application running on another.</p><p>Let’s create two VM instances on GCP — a Jenkins server and an application server, on the default VPC network. Use the <a href="https://cloud.google.com/sdk/docs/quickstart">gcloud command-line tool</a> to run the following commands:</p><pre># Create jenkins server<br>$ gcloud compute --project=&lt;project-name&gt; instances create &lt;instance-name&gt; --zone=us-central1-f --machine-type=e2-small --subnet=default --tags=&lt;add-tags&gt;,http-server</pre><pre># Create application server<br>$ gcloud compute --project=&lt;project-name&gt; instances create &lt;instance-name&gt; --zone=us-central1-a --machine-type=e2-small --subnet=default --tags=&lt;add-tag&gt;,http-server</pre><p>Create firewall rules to expose port 8080 for Jenkins and port 3000 for your NodeJS application:</p><pre># for app server<br>$ gcloud compute firewall create &lt;name&gt; --network --action allow --target-tags &lt;instance-tag&gt; --source-ranges 0.0.0.0/0 --rules tcp:3000</pre><pre># for jenkins server<br>$ gcloud compute firewall create &lt;name&gt; --network --action allow --target-tags &lt;instance-tag&gt; --source-ranges 0.0.0.0/0 --rules tcp:8080</pre><p>Confirm that the VMs are up and running:</p><pre>$ gcloud compute instances list</pre><p>Confirm the firewall rules are created:</p><pre>$ gcloud compute firewall-rules list</pre><p>Connect to instances through SSH and create a jenkins user in both instances:</p><pre># Connect via SSH<br>$ gcloud compute ssh --zone=us-central1-a &lt;jenkins-server&gt;</pre><pre># Create user<br>$ adduser jenkins</pre><pre># Perform the same operations in the application server</pre><p>Now that we have our server instances up and running, let’s install the necessary dependencies required to run the NodeJS application.</p><h3>Install and configure dependencies on the Jenkins server</h3><p>Before we can begin to use the Jenkins application to set up a CI/CD pipeline for the NodeJS application, we need to do the following:</p><ul><li><a href="https://www.jenkins.io/doc/book/installing/linux/#debianubuntu">Install Jenkins</a> on the server.</li><li>Install <a href="https://linuxize.com/post/how-to-install-node-js-on-debian-10/#installing-nodejs-and-npm-from-the-nodesource-repository">node and npm</a> on the Jenkins server to enable Jenkins to run dependencies for the NodeJS application.</li><li>Install mocha to run tests — use the command npm install -g mocha</li></ul><p>Enter the public IP address of the Jenkins server into your browser to view the Jenkins application — remember to include the port number. Follow the instructions to complete the installation.</p><p>Once Jenkins installation is complete, search for and install the NodeJS plugin — <strong>Manage Jenkins &gt; Manage Plugins</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hgRMVoaR5dWCZ261k8Hwfg.png" /></figure><p>And then, enable NodeJS as a tool to use within Jenkins. Navigate to <strong>Manage Jenkins</strong> &gt; <strong>Global Tool Configuration</strong> &gt; <strong>NodeJS installations &gt;</strong> <strong>Add NodeJS.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9QF1Dlsd6auDZfOevbZHg.png" /><figcaption>Add NodeJS installation</figcaption></figure><p>Now, let’s configure the application server.</p><h3>Install and configure dependencies on the application server</h3><p>We will serve our NodeJS application on an Nginx web server. But first, let’s install <a href="https://linuxize.com/post/how-to-install-node-js-on-debian-10/#installing-nodejs-and-npm-from-the-nodesource-repository">node and npm</a> on the application server.</p><p>Then, install Nginx:</p><pre>$ sudo apt install nginx</pre><p>Configure Nginx as a reverse proxy — add the following server configuration to your configuration file in the /etc/nginx/sites-available directory( you may also use the default file /etc/nginx/sites-available/default ):</p><pre>server {<br>       listen 80;<br>       listen [::]:80;</pre><pre>       server_name _;       <br>       root /var/www/&lt;your-directory-name-containing-app-files&gt;;</pre><pre>       index index.html app.js;       <br>       <br>       location / {<br>               try_files $uri $uri/ =404; <br>               proxy_pass http://&lt;app-server-external-ip&gt;:3000<br>       }<br>}</pre><p>The proxy_pass directive declares that the Nginx should serve as a proxy and send requests that target the / root url to whatever IP address or domain name specified — in this case, it will be the application server url with the default port for the NodeJS application.</p><p>We also need to install a tool that will monitor the application and keep it online once it is deployed to the application server— the pm2 tool. <br>Install pm2 using the following command:</p><pre>$ npm install pm2 -g</pre><p>In your code editor, create a pm2 config file following this <a href="https://pm2.keymetrics.io/docs/usage/use-pm2-with-cloud-providers/">template</a>.</p><h3>Set up SSH credentials with GitHub</h3><p>We need to enable the Jenkins application to securely connect with GitHub via SSH. In your Jenkins server, create an SSH key pair. Run the following command:</p><pre>$ ssh-keygen</pre><p>At the prompt, add the file location(or leave as is). You may also add a passphrase at the prompt. Press Enter to create the keys.</p><p>Add the public key to GitHub — run cat &lt;file path to .pub file&gt; and copy the public key.</p><p>Go to the GitHub repository for your NodeJS application. Navigate to <strong>Settings</strong> &gt; <strong>Deploy Keys &gt; Add Deploy Key</strong>. Paste in the public key in the text box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTkYnUBHMnx64ZOak2zkug.jpeg" /><figcaption>Add public SSH key</figcaption></figure><p>Add the private key to the Jenkins application — go back to your Jenkins server; run cat &lt;file path to private key&gt; and copy the private key.</p><p>In the Jenkins GUI, go to <strong>Manage Jenkins</strong> &gt;<strong>Manage Credentials</strong>. Click on &#39;global&#39; and select <strong>Add Credentials. </strong>Select <strong>Enter directly</strong> and paste in the private key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h9CioTVImiGelnHG2Pdq2g.png" /><figcaption>Navigate to <strong>Manage Jenkins</strong> &gt;<strong>Manage Credentials</strong>. Click on ‘global’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sw1L81kqww0VgzKZG269Yw.png" /><figcaption>Add credentials form</figcaption></figure><p>Next, install git on your Jenkins server:</p><pre>$ sudo apt install git</pre><p>Confirm that the git plugin is enabled on the Jenkins application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*16yBz_GtqzOrwJFYUgh67A.png" /><figcaption>Ensure git plugin is enabled</figcaption></figure><h3>Add GitHub webhook</h3><p>A <a href="https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks">webhook</a> listens for any specified events on a target application. When there is an event, it sends data(requests) that trigger processes in a specified endpoint.</p><p>We want to automatically trigger the CI/CD pipeline to run anytime there is a push commit to the repository.</p><p>First, let’s generate an access token. This token is a form of authentication to ensure that the request received is from GitHub only.</p><p>In Jenkins, click on the user icon on the top right, select <strong>Configure</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*Ot1daKhg8lYSdoDQd-JkoQ.png" /></figure><p>Go to <strong>Add New Token</strong>. Generate an API token and copy it. Save changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fL9OCqeOXdGvGl7pwMoeCg.png" /></figure><p>Go to GitHub. Navigate to <strong>Settings &gt; Webhooks &gt; Add Webhook</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7qiUN9cmfEpbKm83zKM2AA.jpeg" /></figure><p>The payload URL will be &lt;your-jenkins-instance-URL&gt;/github-webhook/ . Paste in the API token in the <strong>Secret</strong> field. You may leave the other options as is. Click on the <strong>Add webhook</strong> button.</p><h3>Set up Publish Over SSH</h3><p>We will automate the deployment process to the application server. To do this, we need to establish SSH authentication for a secure connection.</p><p>Install the Publish Over SSH plugin — <strong>Manage Jenkins </strong>&gt; <strong>Manage Plugins.</strong></p><p>In the Jenkins GUI, navigate to <strong>Manage Jenkins &gt; Configure System &gt; Publish Over SSH</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdERdcM034WDsLbtAHIEyg.png" /></figure><p>Add the required details:</p><ol><li>Enter your Passphrase — if you have one set up with SSH.</li><li>Enter the path to the private key of your Jenkins in the “Path to Key” field.</li><li>In the <strong>SSH Servers</strong> section, enter a logical name in “Name”.</li><li>Enter the IP address of the application server in the “Hostname” field.</li><li>Enter the username to log in within the “Username” field.</li><li>Enter the directory that the build artifact should be stored in the remote server, in the “Remote Directory” field.</li><li>Click “Test Configuration”.</li><li>Click “Save”.</li></ol><blockquote>Learn more about Publish Over SSH in the Jenkins official documentation <a href="https://www.jenkins.io/doc/pipeline/steps/publish-over-ssh/">here</a>.</blockquote><h3>Create a Jenkinsfile</h3><p>A Jenkinsfile is a declarative document that contains your pipeline script — it contains the commands and instructions that you would like the Jenkins application to carry out for you at different stages of the pipeline. You can apply <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#creating-a-jenkinsfile">this</a> template to create your Jenkinsfile.</p><p>Below is a sample Jenkinsfile for a NodeJS application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbda4564d5ffdaec08d3b499571400a2/href">https://medium.com/media/cbda4564d5ffdaec08d3b499571400a2/href</a></iframe><p>The <em>Build</em> stage installs the node dependencies and creates a compressed file containing only files relevant to the application— a tar.gz file: this is the build artifact.</p><p>The <em>Test</em> stage runs the tests written in Mocha.</p><p>The <em>Deploy</em> stage connects with the remote server via SSH and then publishes the application by running the commands specified within the steps block.</p><blockquote>Learn more about the Pipeline syntax <a href="https://www.jenkins.io/doc/book/pipeline/syntax/">here</a>.</blockquote><blockquote>If you are unsure of the code to include in your pipeline script, navigate to the <a href="https://www.jenkins.io/doc/book/pipeline/getting-started/#snippet-generator">Pipeline Syntax Generator</a> to generate code snippets for various actions you would like to declare within your script.</blockquote><h4>Create CI/CD pipeline</h4><p>Now that we have all installations and configurations done, let’s go ahead and create a simple pipeline in Jenkins. On your Jenkins <strong>Dashboard</strong>, select <strong>New Item</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*C15SCaxzC6e6cvl-oR7Wlw.png" /></figure><p>Enter a name, select <strong>Pipeline</strong> and click <strong>OK</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knzafLwPfkQhF22j_0b_9g.png" /></figure><p>Under <strong>Build Triggers</strong>, select <strong>GitHub hook trigger for GITScm polling</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YkZh1_yhZ8eyrBePihzmA.png" /></figure><p>Under <strong>Advanced Project Options</strong>, select <strong>Pipeline Script From SCM</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vwkYm3SdmzJMYdjW7WP46Q.png" /></figure><p>Go to your GitHub repository, copy the SSH remote URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*LCUHfzUNFRpnTykTIu9I8Q.png" /></figure><p>Under <strong>SCM</strong>, add the SSH remote URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UnFwVUq8YWFPlWIF2tBiqg.png" /></figure><p>Select the SSH credentials you created above — for SSH authentication with Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEvPLRN4TnBBKTeBmwHoWg.png" /></figure><p>Under <strong>Branches To Build</strong>, enter the branch name. Click “<strong>Save</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OhlV1nJu2xO943Io7trSPQ.png" /></figure><p>Your pipeline is all set up! Now, any commit pushed to the specified branch of the GitHub repository automatically triggers the CI/CD pipeline.</p><h3>Putting it all together</h3><p>Generally, when you’re deploying a NodeJS application, you should have a frontend part of the application — usually in React. In order to connect these two parts, follow these steps described in <a href="https://link.medium.com/HM7jDrvdFkb">this article</a> to deploy a React application.</p><p>The only modification you will need to make is to add the following snippet to the Nginx configuration file — within the <em>location</em> directive:</p><p>proxy_pass &lt;node server ip&gt;</p><h4>Conclusion</h4><p>In a nutshell, setting up SSH credentials with GitHub and adding a webhook to listen for events on the repository constitutes the <strong>continuous integration (CI)</strong> part of the pipeline — while Publish over SSH takes care of the <strong>continuous deployment (CD) </strong>phase.</p><p>You can implement the process described above using this project <a href="https://github.com/Z11mm/jenkins-test-app">here</a> — to see how everything works together. Ideally, it should run smoothly; however, if you run into any issues, feel free to reach out to me—we’ll work through it together.</p><p><strong>I hope you find this article useful. Thank you for reading!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc63b7ed9f41" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Deploy a ReactJS Web Application on DigitalOcean]]></title>
            <link>https://ziimm.medium.com/how-to-deploy-a-reactjs-web-application-on-digitalocean-11d6d8d57b68?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/11d6d8d57b68</guid>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Tue, 14 Sep 2021 21:32:00 GMT</pubDate>
            <atom:updated>2021-10-26T08:14:43.129Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="An image of a screen displaying some code containing divs." src="https://cdn-images-1.medium.com/max/1024/0*K4gM7i7zYqXxCpW3" /><figcaption>Photo by <a href="https://unsplash.com/@florianolv?utm_source=medium&amp;utm_medium=referral">Florian Olivo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>DigitalOcean is a cloud provider that offers services structured around different cloud service models — infrastructure-as-a-service (IaaS),platform-as-a-service(PaaS), software-as-a-service(SaaS) and so on.</p><p>This article is a walkthrough on how to deploy a ReactJS web application on DigitalOcean’s IaaS offering — DigitalOcean Droplets — with Nginx.</p><blockquote><strong>CAVEAT</strong>: Creating a React app is outside the scope of this article. However — after you are done writing code for your React application — you will need to run npm run build to bundle your React application into a /build directory — in order to optimize your application for best performance within a deployment environment.</blockquote><p>For this article, the main highlights are:</p><ul><li>Create a DigitalOcean Droplet.</li><li>Install Nginx on it.</li><li>Get source files from Git repository.</li><li>Modify configuration files</li><li>Serve web content from source files for React app.</li></ul><p>Now, let’s get into it.</p><h4>Setup a DigitalOcean Droplet</h4><p>DigitalOcean offers an infrastructure-as-a-service (IaaS) option in the form of virtual machine instances called Droplets.</p><p><a href="https://docs.digitalocean.com/products/droplets/how-to/create/">Provision a droplet</a> with an Ubuntu 20.04 image, with the lowest payment plan ($5/month) — since we will be using the instance for demonstration purposes. Also, choose password-based authentication at this stage. This droplet is our host machine for the Nginx server.</p><blockquote>Note that the default username is <em>root@&lt;droplet-external-IP&gt;</em> ; that is, <em>root@xxx.xx.xx.xx</em> . Your password is whatever value you pass in while creating the droplet.</blockquote><p>Once the droplet is created, <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-20-04">set up SSH key</a>s for secure log in to your droplet.</p><h4>Install Nginx</h4><p>After you set up SSH-based authentication, <a href="https://medium.com/codex/users-groups-and-permissions-in-linux-93895ae57d93">create a new user</a> with administrative privileges.</p><p>Switch to the new user:</p><pre>$ su &lt;username&gt;</pre><p>Install Nginx:</p><pre>$ sudo apt update <br>$ sudo apt install nginx</pre><h4>Configure firewall</h4><p>You need to set firewall rules using the firewall service ufw to allow web access to the Nginx server. View a list of firewall configurations with the following command:</p><pre>$ sudo ufw app list</pre><p>You should get this output:</p><pre>Available applications:<br>  Nginx Full<br>  Nginx HTTP<br>  Nginx HTTPS<br>  OpenSSH</pre><p>To allow HTTP traffic, use the actual profile name — rather than the value 80 for HTTP and 443 for HTTPS. Run the command:</p><pre>$ sudo ufw allow &#39;Nginx HTTP&#39;<br>$ sudo ufw allow OpenSSH</pre><p>Verify that the configuration is active:</p><pre>$ sudo ufw status</pre><p>This should be the output:</p><pre>Status: active</pre><pre>To                         Action      From<br>--                         ------      ----<br>OpenSSH                    ALLOW       Anywhere                  <br>Nginx HTTP                 ALLOW       Anywhere                  <br>OpenSSH (v6)               ALLOW       Anywhere (v6)             <br>Nginx HTTP (v6)            ALLOW       Anywhere (v6)</pre><blockquote>If your output says status:inactive, run the command sudo ufw enable</blockquote><p>Run the following commands to restart the server (for the changes to take effect) and check the status of the Nginx server:</p><pre>$ sudo systemctl restart nginx<br>$ sudo systemctl status nginx</pre><p>Nginx should be active and running as shown:</p><pre>nginx.service - A high performance web server and a reverse proxy server<br>     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)<br>     Active: active (running) since Tue 2021-09-07 17:20:37 UTC; 23h ago<br>       Docs: man:nginx(8)<br>   Main PID: 6448 (nginx)<br>      Tasks: 5 (limit: 9513)<br>     Memory: 5.1M<br>     CGroup: /system.slice/nginx.service<br>             ├─6448 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;<br>             ├─6449 nginx: worker process<br>             ├─6450 nginx: worker process<br>             ├─6451 nginx: worker process<br>             └─6452 nginx: worker process</pre><p>Enter your droplet’s IP address on your browser to confirm that Nginx is running properly. You can retrieve your IP address using the command:</p><pre>$ curl -4 icanhazip.com</pre><p>If Nginx is running properly, the default Nginx start-up page should display on your browser.</p><h4>Deploy React application</h4><p>Generally, Nginx serves web documents from the /var/www directory — the default start-up page originates from an index.html file in the /var/www/html directory.</p><p>Therefore, as a rule, place the web documents for your website in a named directory within the /var/www directory.</p><p>Let’s add the source files for the ReactJS application.</p><p>Clone your Git repository (for the React app) the /var/www directory:</p><pre>$ cd /var/www<br>$ git clone &lt;git-repo-link&gt;</pre><p>This should create a directory /var/www/&lt;your-directory-name&gt; containing your source files/directories.</p><p>The /build directory for the React application — within /var/www/&lt;your-directory-name&gt; — is the most important here because it contains the index.html file to be served.</p><blockquote><strong>TIP</strong>: You may delete all other files and directories except the <em>/build</em> directory that contains the index.html file — since that is the only directory needed.</blockquote><p>Change ownership of the /var/www/&lt;your-directory-name&gt; directory to ensure you have the permissions to modify files within the directory. Run the command:</p><pre>$ sudo chown -R $USER:$USER /var/www/&lt;your-directory-name&gt;</pre><p>This will assign ownership to the new user you created above.</p><p>Next, let’s create a server configuration for our React application.</p><h4>Add server configurations</h4><p>All Nginx configuration files are within the /etc/nginx directory:</p><ul><li>The main configuration file for global Nginx settings is the nginx.conf located in /etc/nginx/.</li><li>Configuration files for each domain(website) hosted on the server are located within /etc/nginx/sites-available.</li></ul><p>The configuration files in /etc/nginx/sites-available usually end with the .conf extension — however, you may choose to name them without the extension. These configuration files help Nginx identify and track the websites that it hosts.</p><p>Navigate to /etc/nginx/sites-available . It should contain a default or default.conf file. Create your own .conf file:</p><pre>$ touch &lt;filename&gt;.conf</pre><p>Open the newly created file in any text editor — we’ll be using vi :</p><pre>$ vi &lt;filename&gt;.conf</pre><p>The configuration for the React application will be placed in a server block. This block specifies how requests to the IP address or domain should be handled.</p><p>Paste the following configuration snippet:</p><pre># Virtual Host configuration for &lt;your-domain-name&gt;</pre><pre>server {<br>       listen 80;<br>       listen [::]:80;</pre><pre>#       server_name &lt;your-domain-name&gt;;</pre><pre>       root /var/www/&lt;your-directory-name&gt;/build;<br>       index index.html;</pre><pre>       location / {<br>               try_files $uri $uri/ =404;<br>       }<br>}</pre><ul><li>The listen directive specifies the HTTP port to allow web access — 80 for IPv4 and [::]:80 for IPv6 .</li><li>The server_name directive specifies the domain name or website address the server handles requests for. <em>(This directive can be omitted if you do not have a domain name).</em></li><li>The root directive points to the location of the web documents — html , css , js files. The line below the root directive specifies the possible html files to look for and read from.</li><li>The location directive takes a URL parameter and matches it with whatever is specified — / in our case — to enable the server to respond with the appropriate content for that URL.</li></ul><p>Run the command :wq to save and exit the editor.</p><p>Create a symbolic link between your/etc/nginx/sites-available&lt;filename&gt;.conf file and /etc/nginx/sites-enabled directory:</p><pre>$ ln -s /etc/nginx/sites-available&lt;filename&gt;.conf /etc/nginx/sites-enabled</pre><blockquote><strong>Some information on symbolic links:</strong></blockquote><blockquote>A symbolic link creates a special type of file that contains a pointer to a referenced file or directory.</blockquote><blockquote>Both the symbolic link and the file being referenced are indistinguishable from one another — whatever is written to the original file reflects in the symbolic link.</blockquote><blockquote>A common use case for symbolic links is in managing multiple versions of a single software. The symbolic link can point to the latest version of the software even though previous versions are available on the system — this way all files that depend on the software can just use the symbolic link instead of having to worry about versions.</blockquote><blockquote><strong>Symbolic links to the configuration files are in the </strong><strong>/etc/nginx/sites-enabled directory. The global Nginx configuration file </strong><strong>nginx.conf reads from this directory — through the </strong><strong>include directive — in order to ensure that only the current versions of configurations are applied.</strong></blockquote><p>Run the following command to confirm that there are no issues with your configuration:</p><pre>$ sudo nginx -t</pre><p>The following output indicates a satisfactory configuration:</p><pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful</pre><p>Now, restart the Nginx server. Run the command:</p><pre>$ sudo systemctl restart nginx</pre><p>Refresh your browser. The React application should be successfully deployed.</p><h3>Conclusion</h3><p>Deploying an application on the cloud makes it possible to easily get an application up and running with minimal cost. You can take this process a step further by <a href="https://ziimm.medium.com/set-up-a-ci-cd-pipeline-with-nodejs-jenkins-and-google-cloud-cc63b7ed9f41">setting up a CI/CD pipeline</a> to automate the build/deploy process.</p><p>You can also explore DigitalOcean’s App Platform — a PaaS offering — <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-react-application-to-digitalocean-app-platform">here</a>.</p><h4>~~~~~~~~~~ ~~~~~~~~ Thank you for reading! ~~~~~~~~~~~~~~~~~</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11d6d8d57b68" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Users, Groups and Permissions in Linux]]></title>
            <link>https://medium.com/codex/users-groups-and-permissions-in-linux-93895ae57d93?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/93895ae57d93</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[system-administration]]></category>
            <category><![CDATA[linux-commands]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 07:28:42 GMT</pubDate>
            <atom:updated>2021-09-07T00:43:11.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A laptop screen with the words “Users, Groups and Permission”, along with the Linux trademark logo." src="https://cdn-images-1.medium.com/max/1024/1*Z7TykzAXWD-J58QyrSThLQ.png" /><figcaption>Users, Groups, and Permissions in Linux</figcaption></figure><p>In the words of Richard Feynman, “If you want to master something, teach it. The more you teach, the better you learn…”</p><p>So here I am, in my journey to mastery, documenting how I learnt to create users, groups and permissions in Linux in the form of a mini-tutorial.</p><blockquote>We’ll be working with Ubuntu installed on a local virtual server — but most commands used will apply to any other Linux distribution. This article also assumes a basic knowledge of Linux commands.</blockquote><p>The Linux operating system allows multi-user functionality. This means that multiple users can use the operating system concurrently and independently while sharing system resources.</p><p>In this mini-tutorial, we will create 3 groups and 15 users and assign these users across the 3 groups. We will also ensure that users in one group cannot access files in another group unless they are added to that group.</p><p>But first, let’s take a look at the different types of user accounts in Linux.</p><h4>Types of user accounts</h4><p>There are three basic types of Linux user accounts:</p><ol><li><strong>Root user(administrative)</strong>: This user account has full access to system-wide resources, in addition to the permission to create, modify and delete users and groups.</li><li><strong>Regular user accounts</strong>: These are user accounts with a login shell and home directory that perform tasks for personal use — usually common application tasks that are isolated to the user’s home directory.</li><li><strong>Service accounts</strong>: These are accounts assigned to applications but with limited access in order to protect the application from potential attacks while still performing essential functions. They usually will not have a home directory.</li></ol><h4>Create users</h4><p>We will need <em>admin</em> privileges to create users — however, using the <em>root </em>user<em> </em>context is generally avoided, for security reasons.</p><p>First, create a regular user using the useradd command following this syntax:</p><pre>$ useradd -m &lt;name-of-user&gt;</pre><blockquote><strong>TIP</strong>: To learn more about a Linux command, run man &lt;command&gt; , for example, man useradd to display a full description of the command.</blockquote><p>And then, assign admin privileges to this user as follows:</p><pre>$usermod -aG sudo &lt;username&gt;</pre><p>Now, this <em>admin</em> user has superuser privileges and will not need to type in a password with the sudo command.</p><p>Let’s switch to the <em>admin </em>superuser using the following command:</p><pre>$ sudo su &lt;adminuser&gt;</pre><p>And then create more users with the useradd command:</p><pre>$ sudo useradd -m &lt;name of user&gt;</pre><p>Do this for the number of users you need to create — 15 users in this case.</p><h4>View users</h4><p>All users in the system are stored in the /etc/passwd directory. To view all users, run the following command:</p><pre>$ getent passwd</pre><p>This should output something similar to the following:</p><pre>root:x:0:0:root:/root:/bin/bash<br>...<br>user1:x:1002:1002::/home/user1:/bin/sh<br>user2:x:1003:1002::/home/user2:/bin/sh<br>user3:x:1004:1002::/home/user3:/bin/sh<br>user4:x:1006:1003::/home/user4:/bin/sh<br>user5:x:1007:1003::/home/user5:/bin/sh<br>...</pre><p>Each entry has the following features:</p><ul><li>the username: user1</li><li>the encrypted password: x</li><li>the unique identifier (UID) for the user: 100x</li><li>the user group ID (GID): 100x</li><li>the General Electric Comprehensive Operating Supervisor (GECOS) field — which is empty in this case. (<em>This field contains general information as a string of comma-delimited attributes, for example, full name; phone number; etc)</em></li><li>the user home directory: /home/user1</li><li>the default login shell for the user: /bin/sh</li></ul><h4><strong>Delete users</strong></h4><p>To delete a user, run the command:</p><pre>$ sudo userdel -f &lt;user&gt;</pre><p>This removes all related user data, along with all the files in the user’s home directory -f, --force.</p><h4>Add users to a group</h4><p>To add the 15 users to groups, let’s create three different groups — a group for team leads leads, one for developers developers and another for the site reliability engineering team sre — and then add the users to the groups.</p><p>Use the groupadd command to create a group with the following syntax:</p><pre>$ sudo groupadd &lt;groupname&gt;</pre><p>So for our case, we will create three different groups like so:</p><pre>$ sudo groupadd leads<br>$ sudo groupadd developers<br>$ sudo groupadd sre</pre><p>Next, add the already created users to each group assuming each user fits the group role, using the gpasswd command with the following syntax:</p><pre>$ sudo gpasswd -A &lt;user&gt; -M &lt;user,user,user&gt; &lt;groupname&gt;</pre><p>The gpasswd command allows you to manage the creation of groups and members of groups — the -A flag defines group administrators and the -M flag defines the members of the group as a comma-separated list (see the man pages for more details).</p><h4>View groups</h4><p>All groups in the system are stored in the /etc/groups directory. To view all groups, run the following command:</p><pre>$ getent group</pre><p>This should give an output similar to:</p><pre>leads:x:1002:user1,user2,user15<br>developers:x:1003:user3,user4,user5,user6,user7,user8,user9<br>sre:x:1004:user10,user11,user12,user13,user14</pre><p>Next, let’s define the level of access allowed for each group.</p><h4>Permissions and Ownership</h4><p>The reason Linux so elegantly supports a multi-user system is as a result of <em>permissions. </em>Permissions grant users the right to access files and directories within the system. In Linux, the basic permissions are:</p><ul><li><strong><em>Read</em></strong> : the right to open and view the contents of files and directories. Represented by r</li><li><strong><em>Write:</em></strong> the right to modify the content of a file and to add, remove and rename files within a directory. Represented by w</li><li><strong><em>Execute</em></strong>: the right to run a script or application. Represented by x</li></ul><p>Let’s demonstrate the significance of file permissions; create 3 separate files using the following command:</p><pre>$ touch leads.txt developers.txt sre.txt</pre><p>Run the following command to view the files and the current permissions on each file:</p><pre>$ ls -l</pre><p>The output of this command should be similar to this:</p><pre>-rw-r--r-- 1 adminuser adminuser    0 Aug 15 19:41 leads.txt<br>-rw-r--r-- 1 adminuser adminuser    0 Aug 15 19:41 developers.txt<br>-rw-r--r-- 1 adminuser adminuser    0 Aug 15 19:41 sre.txt</pre><p>The parts of the above output relevant to the level of access are the following:</p><ul><li><strong>The first ten characters</strong> -rw-r--r-- symbolize the file access permissions:</li><li>the first character refers to the file type, where - means a regular file. Other notations are d for a directory, l for a symbolic link, and so on.</li><li>the other nine characters define access permissions to the file type — the first three characters rw-are <em>user permissions</em>, the next three r-- are <em>group permissions</em> while the last three r-- are permissions for <em>all other users</em>.</li><li><strong>root: the user that owns (created) the file</strong></li><li><strong>root</strong>: <strong>the group that owns the file</strong></li></ul><p>With the above information in mind, we will assign a specific group to its related file.</p><h4>Assign Group Ownership</h4><p>We want each file to belong to its own group. To do this, let’s assign group ownership using the chgrp (short for <em>change group</em>) command. The syntax for this command is:</p><pre>$ sudo chgrp &lt;group&gt; &lt;file&gt;</pre><p>So, for our example, we’ll run the following commands:</p><pre>$ sudo chgrp leads leads.txt<br>$ sudo chgrp developers developers.txt<br>$ sudo chgrp sre sre.txt</pre><p>Now, when we run the ls -l command, we should get the following output:</p><pre>-rw-r--r-- 1 adminuser leads    0 Aug 15 19:41 leads.txt<br>-rw-r--r-- 1 adminuser developers    0 Aug 15 19:41 developers.txt<br>-rw-r--r-- 1 adminuser sre    0 Aug 15 19:41 sre.txt</pre><p>Each file now belongs to its respective group. This means that only members of the group that owns the file can have whatever permissions specified; that is, read permission (as demonstrated by the middle three characters r--). However, all other users outside of the group also have read permissions (as demonstrated by the last three characters r--).</p><p>So, considering we want to restrict file access to only members belonging to the file group, let’s change that.</p><h4>Modifying permissions</h4><p>To set or change permissions, use the chmod (short for <em>change mode</em>) command (see the manpages for more details).</p><p>When using this command, we specify the following:</p><ul><li><strong>Whom to change permissions for:</strong> u for <em>the user(owner)</em>, g for <em>the</em> <em>group</em> and o for <em>all other users</em>.</li><li><strong>How to change permission:</strong> + (plus sign) to <em>add</em> permissions, — (minus sign) to <em>remove</em> permissions or =(equal sign) to <em>leave as is</em>.</li><li><strong>What permission to change:</strong> r for read, w for write, x for execute.</li></ul><p>Using the information above, let’s take away the read permission for users outside the group and add write and execute permissions to the group as follows:</p><pre>$ sudo chmod g+wx,o-r leads.txt<br>$ sudo chmod g+wx,o-r developers.txt<br>$ sudo chmod g+wx,o-r sre.txt</pre><p>Run the ls -l command to view the modified permissions. The output should be:</p><pre>-rw-rwx--- 1 adminuser leads    0 Aug 15 19:42 leads.txt<br>-rw-rwx--- 1 adminuser developers    0 Aug 15 19:42 developers.txt<br>-rw-rwx--- 1 adminuser sre    0 Aug 15 19:42 sre.txt</pre><p>To demonstrate that files belonging to one group cannot be accessed by another group, login as a different user; for example, user5(who belongs to the developers group), using the following command:</p><pre>$ sudo su user5</pre><p>Now, let’s attempt to read a file that does not belong to the developers group. Run the following command to view the leads.txt file:</p><pre>$ cat leads.txt</pre><p>You should get a warning that says:</p><pre>cat: leads.txt: Permission denied</pre><p>This is expected because user5 does not have the permission to read the contents of the leads.txt file since the file belongs to the leads group, and not the developers group.</p><h4>Conclusion</h4><p>The information shared in this mini-tutorial is by no means exhaustive of the topic of managing users, groups and permissions in Linux. But this should get any beginner, such as myself, up and running with working in Linux.</p><p><strong>PS: I decided to have some fun while learning bash scripting, and wrote scripts </strong><strong>create_users.sh and </strong><strong>delete_users.sh to automate creating and deleting the users described above. See them </strong><a href="https://github.com/Z11mm/bash-scripts"><strong>here</strong></a><strong>.</strong></p><p><strong>— — — — — — — — — Thank you for reading! — — — — — — — — -</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93895ae57d93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/users-groups-and-permissions-in-linux-93895ae57d93">Users, Groups and Permissions in Linux</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding List Comprehensions in Python]]></title>
            <link>https://ziimm.medium.com/understanding-list-comprehensions-in-python-bc217a447943?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc217a447943</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[list-comprehension]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Mon, 03 May 2021 18:53:25 GMT</pubDate>
            <atom:updated>2021-05-03T18:53:25.172Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o6eFHfvyzITNqe9x" /><figcaption>Photo by <a href="https://unsplash.com/@hishahadat?utm_source=medium&amp;utm_medium=referral">Shahadat Rahman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Basic knowledge of Python data structures and Python operators required.</blockquote><p>Starting out learning a new programming language, such as Python, can seem daunting at first, especially with technical terms like ‘list comprehensions’ coming up frequently. But when we deconstruct a concept into its components, we have a better chance of grasping its fundamentals and building on it.</p><p>In this article, you will learn what makes up a list comprehension, the various patterns of writing a list comprehension and the potential use cases for list comprehensions. But first, we will define and describe a list comprehension.</p><h4>What is a list comprehension?</h4><p>‘<strong><em>List</em></strong>’ and ‘<strong><em>comprehension</em></strong>’ are two separate terms in Python. A <strong>list</strong> is a data structure that contains an ordered sequence of values; on the other hand, a <strong>comprehension</strong> is a set of instructions on how a specific output should be created. Hence, a list comprehension is a set of instructions to create a new list.</p><p>The general structure of a list comprehension is as follows:</p><pre>            new_list = [value for variable in iterable]</pre><p>An iterable is any Python object that contains a set of elements. It allows a for loop operation to return each item in order, from the beginning of the object to the end. Examples of iterables are lists, tuples and sets.</p><p>The variable is the name assigned to each element in the iterable.</p><p>The value is the result of the for clause and / or if clause, for each element. Each value is then appended to the new_list in order.</p><blockquote>As written in the <a href="https://docs.python.org/3/">Python docs</a>, a list comprehension consists of square brackets containing an expression followed by a for clause, then zero or more for or if clauses.</blockquote><blockquote>The result will be a new list resulting from evaluating the expression in the context of the for and if clauses which follow it.</blockquote><p><strong>A list comprehension having a </strong><strong>for clause means that it is a one-liner technique that can be derived directly from a for loop</strong>. For example, let us create a new list called <em>numbers</em> from an iterable range of values from 1 to 20, using a for loop:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/615b277f7156ebed02b99e88e2c6838e/href">https://medium.com/media/615b277f7156ebed02b99e88e2c6838e/href</a></iframe><p>With the for loop example above (and for loop operations in general), we are <em>explicitly</em> specifying each step of how we want to create the list. Now, we will rewrite the above as a basic list comprehension:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a1aef50542fe4526199b691906d582f/href">https://medium.com/media/8a1aef50542fe4526199b691906d582f/href</a></iframe><p>Notice that with a list comprehension, you only have to declare what you want the list to contain. Python decides how to create the list.</p><h4>List comprehension patterns</h4><p>In the example above, we learnt how to create a list comprehension from a simple for loop. Other patterns include:</p><ol><li><strong>From a simple for loop with a conditional statement</strong></li></ol><p>In the example below, we want to create a list called numbers, containing only odd numbers, from a range of iterable values from 1 to 20.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ca88b20586258983fb79208556322cc/href">https://medium.com/media/7ca88b20586258983fb79208556322cc/href</a></iframe><p>As a list comprehension, it becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e6bfc4beb48e187d213b30db583cc7d/href">https://medium.com/media/3e6bfc4beb48e187d213b30db583cc7d/href</a></iframe><p><strong>2. From nested for loops</strong></p><p>In the example below, we want to create a new list that combines elements from two separate lists. Each value in the new list should be a tuple that meets the condition in the conditional statement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54fa9e17b861ef103bfb9c1c1b331e92/href">https://medium.com/media/54fa9e17b861ef103bfb9c1c1b331e92/href</a></iframe><p>As a list comprehension, it becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c71f3ffc78c9918c41b2a752a410412/href">https://medium.com/media/6c71f3ffc78c9918c41b2a752a410412/href</a></iframe><p>Notice how the order of the for clause and if statements are the same in both the nested for loop and list comprehension.</p><p><strong>3. Nested list comprehensions</strong></p><p>A list comprehension can contain another list comprehension. In the example below, we have a multidimensional list — a 3x3 matrix. It is a list containing three lists, each with 3 elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/839d436aa56702c5b96525f5b5bb3f71/href">https://medium.com/media/839d436aa56702c5b96525f5b5bb3f71/href</a></iframe><p>To spread this matrix out into a one-dimensional list, we can use a for loop as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1d20b6f3638d9a8aebe3183a5aa0f7e/href">https://medium.com/media/b1d20b6f3638d9a8aebe3183a5aa0f7e/href</a></iframe><p>Using a nested list comprehension, it becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fe4e68efaf5999c26ded382836d2877/href">https://medium.com/media/0fe4e68efaf5999c26ded382836d2877/href</a></iframe><p>Notice how using a for loop is more readable compared to the nested list comprehension? That is a tradeoff to using nested list comprehensions. It can get quite complex and difficult to read.</p><blockquote>When working with multidimensional lists, it is generally recommended to be as explicit as possible. Use for loops to improve readability.</blockquote><h4><strong>When to use list comprehensions</strong></h4><ul><li><strong>To create a new list</strong>. Although, there are alternative ways to create a list — using map or generator expressions, which may be more performant (depending on you and your team’s requirements), list comprehensions provide a succinct approach to creating a new list.</li><li><strong>To optimize your code for readability</strong>. Since list comprehensions are one-liner statements, they can potentially enhance the reading experience of your codebase. Be careful not to overdo it.</li></ul><h4><strong>Conclusion</strong></h4><p>As a beginner, being explicit with writing code comes naturally as you navigate learning the syntax of a programming language. But using techniques such as list comprehensions will give you that push into intermediate level programming. So go for it!</p><p><strong>Additional resources:</strong></p><ul><li>Learn about the history of the introduction of list comprehensions into Python 2.0 <a href="http://python-history.blogspot.com/2010/06/from-list-comprehensions-to-generator.html">here</a>.</li><li>The same principles discussed here apply to set and dictionary comprehensions. Learn more about them <a href="https://docs.python.org/3/tutorial/datastructures.html?highlight=list%20comprehension#dictionaries">here</a>.</li></ul><h4><strong>Thank you for reading. Let me know if you find this article helpful!</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc217a447943" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Does SSH Work?]]></title>
            <link>https://ziimm.medium.com/how-does-ssh-work-905945b7ec31?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/905945b7ec31</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Sun, 21 Mar 2021 10:36:05 GMT</pubDate>
            <atom:updated>2021-03-21T10:36:05.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="An image of a computer screen with cryptic text" src="https://cdn-images-1.medium.com/max/1024/0*6deBUVVGIMpWh5ue" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article is for beginners struggling to understand the concept of SSH. I attempt to break down the SSH connection process to its most basic steps. This article will cover :</p><ul><li>What SSH is.</li><li>The process of initiating SSH.</li><li>Stages in the SSH operation.</li></ul><h4>WHAT IS SSH?</h4><p>The purpose of SSH is to provide a secure channel of communication over an unsecure network such as the internet. It is a network protocol applied to a client-server architecture that encrypts the exchange of data between a server and a client, over a TCP/IP connection. You can think of it as “a way for Alice to send information to Bob without Eve eavesdropping” — an analogy popular in cryptography literature. Let’s say Alice is the client, Bob is the server, and Eve is a potential intruder.</p><h4>THE PROCESS OF INITIATING SSH</h4><p>To begin the SSH operation, the client generates an SSH key pair. This pair comprises a <strong><em>private key (verification key)</em></strong> and a <strong><em>public key (signing key)</em></strong>.</p><p>The public key is shared with anyone. It serves as a sort of digital signature for the client. Once generated, the client uploads the public key to the server. The server has a home directory specifically for the client. This home directory contains another directory named ~/.ssh. The ~/.ssh directory contains a file named authorized_keys. The client’s public key is placed in this authorized_keys file.</p><p>The private key must be kept secret and is known only to the client. Its presence confirms the client’s identity. The server also has its own key pair.</p><p>This concept of a key pair is a requirement for the entire SSH routine.</p><h4>STAGES IN THE SSH OPERATION</h4><p>The steps in establishing an SSH connection pass through two primary stages:</p><p><strong>A)</strong> <strong>Secure encryption for communication</strong></p><p>This stage handles the creation of a ‘shell’, protecting the communication channel from snooping by intruders. Both sides of the communication do this using a form of symmetrical encryption referred to as <strong><em>‘shared secret key encryption’</em></strong>.</p><p>Here, both parties exchange public keys and arrive at a shared secret key used to encrypt information sent over the connection. The key pair used in this stage differs from the initial SSH key pair used for authentication.</p><p>The classic algorithm used in this process is the <strong>Diffie-Hellman key exchange algorithm</strong>. Here’s an analogy of how it works:</p><ol><li>Let’s say Alice and Bob decide to make breakfast. They both decide on a common ingredient to use — eggs.</li><li>Alice chooses a secret ingredient (cheese) that Bob does not know about, and Bob does the same (tomatoes).</li><li>They both mix up their ingredients independently, resulting in different mixtures.</li><li>Bob and Alice exchange mixtures.</li><li>Alice then adds her secret ingredient to Bob’s mixture, while Bob adds his own secret ingredient to Alice’s mixture.</li><li>And finally, they both come up with the same meal — an omelette.</li></ol><p>Now, let’s explore a more technical description of the Diffie-Hellman algorithm.</p><ol><li>The client and server agree on a large prime number as a base value. Any intruder eavesdropping on the communication has access to this number.</li><li>The client and server choose another prime number independently. This number is secret from each other. It will be the private key for this exchange. And is unknown to any intruder.</li><li>Both entities also agree on an encryption generator (usually Advanced Encryption Standard — AES). This generator is used to manipulate the values in a pre-defined way.</li><li>The private key, the encryption generator, and the shared prime number are used to generate a public key that is shared with each other. Both entities perform this operation independently.</li><li>Both entities exchange the generated public keys. Any intruder eavesdropping on the communication also has access to the generated public key of both the client and server.</li><li>The client uses its own private key, the server’s public key, and the original shared prime number to compute a shared secret key. And the server does the same thing.</li><li>Finally, even though each entity computes the shared secret key independently — using opposite public and private keys, each entity outputs the same shared secret key.</li></ol><p>This shared secret key encrypts any message and is also used to decrypt it on the other end. The shared secret key is unknown to Eve because the private key for each entity is secret.</p><p>This symmetric encryption key is session-based. This means that every new connection produces a new shared secret key.</p><p>After establishing a secure session via encryption, the client authentication stage begins.</p><p><strong>B) Authentication</strong></p><p>The simplest method of authentication is using a password. The server basically prompts the client for the password of the account they are attempting to login with. This is not a recommended method. This is because, although the password is encrypted, automated scripts may break the password.</p><p>The recommended approach is the use of SSH key-based authentication. This involves the application of asymmetrical encryption and hashing.</p><p>With asymmetrical encryption, the public key encrypts information that only the private key can decrypt, as opposed to symmetrical encryption where the same key — the shared secret key — is used to encrypt and decrypt information both ways.</p><p>Here’s how it happens:</p><p>1. The client starts by sending an ID for the key pair it would like to authenticate with the server. You can think of this ID as a username or email address.</p><p>2. The server scans the authorized_keys file of the directory that the client is attempting to log into for the key pair ID.</p><p>3. Once a public key with a matching ID is found in the file, the server creates a random number and encrypts the number using the public key.</p><p>4. The server relays this encrypted number to the client.</p><p>5. The client decrypts the number using the private key associated with the public key, disclosing the original random number.</p><p>6. The client integrates this decrypted number with the shared secret key used to encrypt the communication, to form an output.</p><p>7. The client computes the MD5 hash of the output.</p><p>8. The client transmits the MD5 hash back to the server as a response to the encrypted number.</p><p>9. The server performs the same hashing operation using the same shared secret key and the original random number, to arrive at the hash value independently.</p><p>10. The server compares its own hash value with that contained in the client response.</p><p>11. If the values match, it confirms that the client owns the private key.</p><p>12. The client is authenticated and now has access to the server.</p><p>SSH provides a way to protect client-server interactions from <a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">man-in-the-middle attacks</a>. In all versions of SSH, it is imperative to associate public keys with an ID before accepting them as valid.</p><p>Accepting an attacker’s public key without authentication gives the attacker unauthorized access to the server.</p><h4>Additional resources</h4><p><strong>SSH (Secure Shell)</strong>. For an extensive study of SSH, check out this <a href="https://www.ssh.com/ssh/">documentation</a>.</p><p><strong>Encryption Techniques</strong>. For an overview of cryptography and encryption, check out this <a href="https://intellipaat.com/blog/tutorial/ethical-hacking-cyber-security-tutorial/encryption-techniques/">article</a>.</p><p><strong><em>Thank you for reading this article.</em></strong></p><p><strong><em>Let me know in the comments section if you found this article helpful!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=905945b7ec31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git: Three-Way Merge]]></title>
            <link>https://ziimm.medium.com/git-three-way-merge-1b8353155567?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b8353155567</guid>
            <category><![CDATA[team]]></category>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 21:21:29 GMT</pubDate>
            <atom:updated>2020-06-01T21:21:29.681Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SNubrNjuQrPXIUyL.jpg" /><figcaption>Git logo</figcaption></figure><p>Teams working on a project leverage Git, as a distributed version control system, to keep track of changes made to the source code. A particularly useful feature in git is the <strong><em>three-way merge</em></strong><em>. </em>This technique makes it possible to merge changes at different levels of development.</p><p>During development, multiple branches may be created from the master branch to enable an isolated working scope. For example, a feature branch may be created from the master branch. The complete development of a new feature is handled in the feature branch. This feature branch will have changes made to it, in parallel with independent changes also made to the master branch. When the feature is complete, the feature branch is then merged into the master branch.</p><p>Git merging combines a sequence of commits into one unified history of commits. <a href="https://docs.gitlab.com/ee/user/project/merge_requests/fast_forward_merge.html">Git can automatically merge commits</a> unless there are changes that conflict in both commit sequences.</p><p>In the case of both the master and feature branch, the differences in the progress of these two branches can create merge conflicts. If these two branches both have changes to the same part of the same file, Git stops the merging process just before the merge commit so that conflicts can be manually resolved.</p><p>Running the git status command shows which files need to be resolved:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPxp_zsrDAzXHCc0CR4eEA.png" /></figure><p>Anything that has merge conflicts and hasn’t been resolved is listed as unmerged.</p><p>Git presents visual indicators for conflicted sections that need to be resolved. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3U2xTsISvoj9_doDlFNlQ.png" /></figure><p>This means the version in HEAD (your master branch is the top part of that block - everything <strong>above</strong> the =======), while the version in the feature branch looks like everything in the bottom part, everything <strong>below</strong> the =======.</p><p>You can resolve this conflict by replacing the entire block with this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6DWM1WUd0u4558xcxnnPg.png" /></figure><p>It has a little of both sections. Once the conflicts are fixed, the merging process can be continued using the usual stage/commit workflow, that is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1nYCstUqeo3AfCSarjs_9g.png" /></figure><p>Merging is an essential process when working with Git. Check out the git <a href="https://git-scm.com/docs">docs</a> to find out more about git add and git commit.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b8353155567" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Patterns in React(Part III) : The Reducer Pattern]]></title>
            <link>https://ziimm.medium.com/design-patterns-in-react-part-iii-the-reducer-pattern-8937921ecacd?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8937921ecacd</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Wed, 06 May 2020 19:04:19 GMT</pubDate>
            <atom:updated>2020-05-07T05:23:07.521Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Patterns in React(Part III) : The Reducer Pattern</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CR1LJ0jRUMQHU21Z" /><figcaption>Photo by <a href="https://unsplash.com/@nate_dumlao?utm_source=medium&amp;utm_medium=referral">Nathan Dumlao</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>This post is a part of this <a href="https://medium.com/@Ziimm_/four-javascript-design-patterns-in-react-abdbcbcfaee7">series</a> on Design Patterns in React.</blockquote><p>The reducer pattern is one of the commonly used patterns in React. It is a concept derived from the reducer function in Computer Science.</p><p>As written in this <a href="https://en.wikipedia.org/wiki/Reduction_Operator">article</a> on Wikipedia:</p><blockquote>“A reduction operator can help break down a task into various partial tasks by calculating partial results which can be used to obtain a final result. It allows certain serial operations to be performed in parallel and the number of steps required for those operations to be reduced.”</blockquote><p>Remember the array reduce() method? It takes all the index values in an array and reduces them to a single value ( Read about it <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce">here</a>). Let’s use an example.</p><p>Say we want to reverse a string using reduce(), it would look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j_57b1rObdz8Xp3DmwEJGA.png" /></figure><p>The reduce callback function takes in an accumulator reversedString and a current value char , and returns the output of the function — a reversed string.</p><p>In the context of React, this reducer function acts on the state object. The accumulator becomes the state object, while the current value will be the upcoming changes(usually from props) you want to make to the state.</p><p>But why is this necessary?</p><p>React updates the state object in a component using <a href="https://reactjs.org/docs/faq-state.html">setState()</a>.The appropriate approach is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-6-zBrD7vtbdqvfHU5Zf0w.png" /></figure><p>Now, imagine a case where the codebase keeps growing to include many more stateful components. You will end up with multiple setState()calls. This makes it difficult to keep track of changes. This is where the reducer pattern becomes useful. It aggregates state changes in one place.</p><p>Let’s walk through an implementation of the reducer pattern. We’ll update the number of items in a cart by incrementing or decrementing the count. Let’s begin by creating a Cart component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XH6o4o1srOtx6a1y5eDLuA.png" /><figcaption>Cart component without reducer and setState()</figcaption></figure><p>Since there is more than one function that will ‘act’ on the state object, let’s create a reducer called <em>dispatch</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dp3QjmQ2w6wCMpMX_LxFUA.png" /></figure><blockquote>Notice how the structure of the returned function in <strong>dispatch</strong> is similar to the setState() function above?</blockquote><blockquote><strong>dispatch</strong> takes an action as a parameter. It returns a function. This function returns the appropriate updated value of the state. The returned value is passed into setState() to update the state with this value.</blockquote><p>Now, let’s use the reducer within the Cart component. The actions that will make changes to the state are called ADD_ITEM and REMOVE_ITEM. This is what the component will look like once the reducer is added:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIew1SXBKpHzXkX57QtoDg.png" /><figcaption>Cart component using a reducer</figcaption></figure><p>Evidently, this pattern invariably enhances testing and debugging of your codebase. Hope you found this article helpful.</p><p>Try out the code<a href="https://codesandbox.io/s/react-reducer-pattern-g65bo"> here</a>.</p><p><em>Never stop learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8937921ecacd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node JS with Express For Dummies]]></title>
            <link>https://ziimm.medium.com/node-js-with-express-for-dummies-fd013b2c1895?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd013b2c1895</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Fri, 01 May 2020 19:29:10 GMT</pubDate>
            <atom:updated>2020-05-01T19:29:10.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*Yhe1R94CIotr2se7Wf6TQQ.png" /><figcaption>NodeJS</figcaption></figure><blockquote>This article will focus on giving an overview of how a server is set up in Node using Express for a <strong>total</strong> beginner.</blockquote><p>The first time I set up a server for a web application was with Node. I was following along a tutorial and I couldn’t understand why I was doing what…Each line of code written just seemed like an entire galaxy too complex to explore. So I gave up on it.</p><p>However, that’s not what we programmers do! We are here to solve problems, and that includes our own. So I revisited my problem with Node and found out that looking at the ‘big picture’ of Node and what I’m using it to achieve in my application was a good starting point.</p><p>With setting up a server, I broke down my codebase in Node into compartments and converted each compartment into a simple step. Putting these steps together gave me a structure to follow. Subsequently, I could put more things into each compartment and build up a personal catalog for future reference.</p><p>I came up with these three compartments:</p><ol><li>Set up the Express server</li><li>Specify middlewares</li><li>Write server functions</li></ol><p>Let’s start with the first compartment - setting up the server. Here’s how you set up an Express server:</p><ul><li>Install Express as a dependency using npm</li></ul><pre>npm install express --save</pre><ul><li>Import Express into your file</li></ul><pre>const express = require(&#39;express&#39;);</pre><ul><li>Instantiate the express server</li></ul><pre>const server = express();</pre><ul><li>Specify the port that the server should listen</li></ul><pre>server.listen(port number);</pre><p>Now you have a server up and running!</p><p>Generally, the Express server workflow requires channeling network requests and responses through a middleware to perform operations on them. You can have multiple middlewares performing different functions at various levels of your application.</p><blockquote>Middlewares are beyond the scope of this article. You can learn more about using them <a href="http://expressjs.com/en/guide/using-middleware.html#using-middleware">here</a></blockquote><p>To set up a middleware in Express, you require this one-liner :</p><pre>server.use(middleware);</pre><p>The use() function allows you to pass in any middleware functionality you require for your Express application.</p><p>After setting up the middleware, you can proceed to write your server functions to handle network requests and responses. These server functions could be <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">RESTful APIs</a> that handle <em>‘create-read-update-delete’</em> (CRUD) functionalities for the backend of your application.</p><p>Hope you found this article helpful. You can learn more about NodeJS in this <a href="https://nodejs.org/en/docs/guides/">documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd013b2c1895" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Design Patterns in React : Part II]]></title>
            <link>https://ziimm.medium.com/design-patterns-in-react-part-ii-b5b58c622c32?source=rss-f86bf38e5a4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5b58c622c32</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Żimuzo Obiechina]]></dc:creator>
            <pubDate>Sun, 16 Feb 2020 10:18:38 GMT</pubDate>
            <atom:updated>2020-05-11T12:52:57.636Z</atom:updated>
            <content:encoded><![CDATA[<h3>Design Patterns in React(Part II) : The Higher Order Component Pattern</h3><figure><img alt="Buildings connected by a sky bridge." src="https://cdn-images-1.medium.com/max/1024/0*-7BEMekMFqWsfuoS" /><figcaption>Photo by <a href="https://unsplash.com/@mitchel3uo?utm_source=medium&amp;utm_medium=referral">Mitchell Luo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>This post is a part of this <a href="https://medium.com/@Ziimm_/four-javascript-design-patterns-in-react-abdbcbcfaee7">series</a> on Design Patterns in React.</blockquote><p>In the wise words of William of Ockham, “it is futile to do with more things that which can be done with fewer…”; a statement which I dare say,succinctly sums up the concept of the Higher-Order-Component(HOC) Pattern.</p><h4>Higher-Order-Component Pattern</h4><p>This pattern is a concept derived from <a href="https://eloquentjavascript.net/05_higher_order.html">higher-order functions</a>. An HOC is basically a function that takes another component as input and returns an enhanced component as output.</p><pre>const HOC = Component =&gt; EnhancedComponent;</pre><p>To understand why we need higher-order components, let’s consider a scenario where multiple components in an application retrieve data from the same API and display the data in a similar fashion. In the first part of the example below, let’s say the UserProfile class component <a href="https://medium.com/@Ziimm_/four-javascript-design-patterns-in-react-abdbcbcfaee7">from this previous pos</a>t needs to be expanded to display posts associated with the user by getting the data from an API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d344d00592f12d30a042a4b836a2baf/href">https://medium.com/media/3d344d00592f12d30a042a4b836a2baf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4506b779ebf14a3cf4318bd6877d2591/href">https://medium.com/media/4506b779ebf14a3cf4318bd6877d2591/href</a></iframe><p>But, we also want to display a list of users, so we create another component called UserList:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22e9925a9b1e3e3f66dc847cf143eab4/href">https://medium.com/media/22e9925a9b1e3e3f66dc847cf143eab4/href</a></iframe><p>Now, what if we want to have other components in this same application that perform the same task? That will mean replicating this code for each component! That is less than ideal. Remember the DRY principle?</p><p>Cue in higher-order components! What an HOC will do is wrap the functionality/task to be performed, in a function, so that any component passed in as an argument is ‘wrapped’ by this function/component, and then returns a version that automatically gives the passed in component access to the functionality.</p><p>To demonstrate this, let’s create a higher order component that can take in any component as an argument, along with the source url for data-fetching:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11356f55a302426ead7ccb514c45495f/href">https://medium.com/media/11356f55a302426ead7ccb514c45495f/href</a></iframe><p>Do you notice how it has isolated the functionality shared by these components and made it generic? With this HOC pattern in place, we’ll need to modify our initial code. We will convert the UserProfile class component into a functional component, which is then wrapped into the withData HOC, and exported:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b63d402346f5eef4379361b7f4805c6/href">https://medium.com/media/1b63d402346f5eef4379361b7f4805c6/href</a></iframe><p>The same pattern is applied to the UserList component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4045328ec4a3a8f6d7b73f9bae5e0016/href">https://medium.com/media/4045328ec4a3a8f6d7b73f9bae5e0016/href</a></iframe><p>As you can see, this modification has exponentially improved the maintainability potential of the codebase. This pattern leverages the <a href="https://reactjs.org/docs/composition-vs-inheritance.html">composition model of React</a>, allowing for easier debugging.</p><p>A practical example of the HOC in React is the withRouter HOC, which passes to its argument access to the match, location and history objects; useful for navigating through an application. You can learn more about it <a href="https://reacttraining.com/react-router/web/api/withRouter">here</a>.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5b58c622c32" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>