<?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 Will Jones on Medium]]></title>
        <description><![CDATA[Stories by Will Jones on Medium]]></description>
        <link>https://medium.com/@willdvlpr?source=rss-7e172aad0e30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rUbMbZ2BExpMFVMH1NRlng.jpeg</url>
            <title>Stories by Will Jones on Medium</title>
            <link>https://medium.com/@willdvlpr?source=rss-7e172aad0e30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:54:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@willdvlpr/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[Create a Scrolling Ticker using the Hacker News RSS Feed in React]]></title>
            <link>https://willdvlpr.medium.com/create-a-scrolling-ticker-using-the-hacker-news-rss-feed-in-react-42633320a2b0?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/42633320a2b0</guid>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Thu, 05 Aug 2021 01:46:16 GMT</pubDate>
            <atom:updated>2021-08-05T01:46:16.970Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Stock-Exchange Style Ticker Using ReactJS</em></p><p>This article will walk through how to create a scrolling ticker (using a neat third-party package) to serve RSS content from the Hacker News API. The end result will look similar to the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6XY8IW2bYQ6HVN1lj07kNw.png" /><figcaption>Scrolling ticker on socioprophet.com</figcaption></figure><p>To see the ticker in live action, you can check it out <a href="https://www.socioprophet.com/">here!</a></p><p>The text that you can see coming through the ticker, are posts from <a href="https://news.ycombinator.com/">Hacker News</a>, using the <em>hnrss.org</em> API.</p><h3>What is an RSS Feed?</h3><p>RSS stands for ‘Really Simple Syndication’. In short, RSS is a subscription model that allows applications to access and receive updates on media content. In our case, the RSS Feed we are using is <em>hnrss.org.</em></p><h3>React Ticker Package</h3><p>I’m a huge fan of not reinventing the wheel! And since there is an open source NPM package out there with ‘scrolling ticker’ functionality ready-to-go, why not use it?</p><p>First, add this package to your <em>package.json </em>file;</p><pre>npm install react-ticker</pre><p>OR</p><pre>yarn add react-ticker</pre><p>You can visit the documentation here <a href="https://www.npmjs.com/package/react-ticker">https://www.npmjs.com/package/react-ticker</a>.</p><h3>Setting up the UI and Creating the Ticker Component</h3><p>First, create a <em>TickerFeed.jsx</em> component. Name it whatever you like, just make sure that it has a different name to the package import we will add in later.</p><p>Now, create a basic export function in <em>TickerFeed.jsx</em> and import the <em>react-ticker</em> package from earlier as <em>Ticker</em>;</p><pre>// TickerFeed.jsx</pre><pre>import React, { useState, useEffect } from &#39;React&#39;;<br>import Ticker from &#39;react-ticker&#39;;</pre><pre>const TickerFeed = () =&gt; {<br>   return (<br>      &lt;div&gt;&lt;/div&gt;<br>   );<br>};</pre><pre>export default TickerFeed;</pre><p>Now, in the <em>App.jsx</em> file (or whatever file will display the ticker, maybe you have a <em>Dashboard.jsx</em> or something of that nature), import <em>TickerFeed.jsx</em>;</p><pre>// App.jsx</pre><pre>import React from &#39;react&#39;;<br>import TickerFeed from &#39;./TickerFeed&#39;;</pre><pre>const App = () =&gt; {<br>   return (<br>      &lt;div className=&quot;app&quot;&gt;<br>         &lt;TickerFeed /&gt;<br>      &lt;/div&gt;<br>   );<br>};</pre><p>Our ticker component will take no props, so to render the ticker just add it in as <em>&lt;TickerFeed /&gt;</em>.</p><p>Depending on what styles you wrap the component in will depend on how its located and positioned on the screen, which is up to you. I’m going to discuss the styles required to make the scrolling ticker look awesome!</p><p>Back in <em>TickerFeed.jsx</em>, we need to create a function that will get the RSS data and render the results.</p><pre>// TickerFeed.jsx</pre><pre>import React, { useState, useEffect } from &#39;React&#39;;<br>import Ticker from &#39;react-ticker&#39;;</pre><pre>const TickerFeed = () =&gt; {<br>  <br>   <strong>const GetRssFeedData = () =&gt; {<br>      const [feed, setFeed] = useState();<br>      <br>      useEffect(() =&gt; {<br>      }, []);</strong></pre><pre><strong>};</strong></pre><pre>return (<br>      &lt;div&gt;&lt;/div&gt;<br>   );<br>};</pre><pre>export default TickerFeed;</pre><p>The <em>GetRssFeedData</em> component will run <em>useEffect </em>on each re-render since there is no value in the <em>useEffect</em> dependency array.</p><p>Now we can add the <em>react-ticker</em> element;</p><pre>// TickerFeed.jsx</pre><pre>import React, { useState, useEffect } from &#39;React&#39;;<br>import Ticker from &#39;react-ticker&#39;;</pre><pre>const TickerFeed = () =&gt; {<br>  <br>   const GetRssFeedData = () =&gt; {<br>      const [feed, setFeed] = useState();<br>      <br>      useEffect(() =&gt; {<br>      }, []);</pre><pre>};</pre><pre>return (<br>      <strong>&lt;div className=&quot;ticker&quot;&gt;<br>         &lt;div className=&quot;ticker__field&quot;&gt;<br>            &lt;Ticker offset=&quot;run-in&quot;&gt;<br>               {() =&gt; <br>                  &lt;GetRssFeedData /&gt;<br>               }<br>            &lt;/Ticker&gt;<br>         &lt;/div&gt;<br>      &lt;/div&gt;</strong><br>   );<br>};</pre><pre>export default TickerFeed;</pre><p>I’ve wrapped the Ticker element in a div with the class name <em>ticker__field</em> and then wrapped that in another div with the class name <em>ticker.</em></p><p>The prop, <em>offset,</em> in the <em>Ticker</em> component determines the alignment of the first element that scrolls along. In the case above, I’ve set it to ‘run-in’ which will hide the first element, so that the ticker itself starts empty and then populates. Visit the NPM documentation page for a full list of props that the component will accept, and the different values they can be set to.</p><h4>The Main Styles</h4><p>Before moving on the the <em>GetRssFeedData</em> functionality, we can add styles to the first two divs.</p><pre>.ticker {<br>   position: absolute;<br>   width: 100%;<br>   height: 40px;<br>   z-index: 1;<br>}</pre><pre>.ticker__field {<br>   position: fixed;<br>   top: 50px;<br>   left: 0;<br>   width: 100%;<br>   height: $element-height;<br>   background-color: rgb(35, 35, 35); <br>   opacity: 0.85;<br>   text-rendering: optimizeLegibility;<br>   -webkit-font-smoothing: subpixel-antialiased;<br>}</pre><h4>The useEffect Functionality</h4><p>The <em>useEffect </em>hook will run every time the component has to re-render, therefore, we want to place the API call inside of the <em>useEffect.</em></p><pre>// TickerFeed.jsx</pre><pre>import React, { useState, useEffect } from &#39;React&#39;;<br>import Ticker from &#39;react-ticker&#39;;</pre><pre>const TickerFeed = () =&gt; {<br>  <br>   const GetRssFeedData = () =&gt; {<br>      const [feed, setFeed] = useState();<br>      <br>      <strong>useEffect(() =&gt; {<br>         <br>         let mounted = true;</strong></pre><pre><strong>const getRss = async () =&gt; {<br>            await fetch(&#39;<em>https://hnrss.org/newest</em>&#39;)<br>              .then((<em>res</em>) =&gt; <em>res</em>.text())<br>              .then((<em>data</em>) =&gt; {<br>                 const xmlDoc = <br>                    new DOMParser()<br>                       .parseFromString(<em>data</em>, &#39;text/xml&#39;);</strong></pre><pre><strong>const items = <br>                    Array.from(<br>                       xmlDoc.querySelectorAll(&#39;item&#39;))<br>                         .map((<em>item</em>) =&gt; ({<br>                            title: <em>item<br>                               </em>.querySelector(&#39;title&#39;).textContent,<br>                            link: <em>item<br>                               </em>.querySelector(&#39;link&#39;).textContent,<br>                 }));<br>                 <br>               if (mounted) {<br>                setFeed(items);<br>               }<br>            });<br>         };<br>         getRss();<br>    <br>         return () =&gt; {<br>            mounted = false;<br>         };<br>    }, []);</strong><br> };</pre><pre>return (<br>      &lt;div className=&quot;ticker&quot;&gt;<br>         &lt;div className=&quot;ticker__field&quot;&gt;<br>            &lt;Ticker offset=&quot;run-in&quot;&gt;<br>               {() =&gt; <br>                  &lt;GetRssFeedData /&gt;<br>               }<br>            &lt;/Ticker&gt;<br>         &lt;/div&gt;<br>      &lt;/div&gt;<br>   );<br>};</pre><pre>export default TickerFeed;</pre><p>If you follow along the code in <strong>bold</strong>, you will see that first, I created a function within the <em>useEffect </em>called <em>getRss</em> that is invoked by calling it towards the end of the <em>useEffect</em> hook.</p><p>The first line under the <em>useEffect</em> declaration sets a boolean value <em>mounted</em> to <em>true. </em>At the end of the <em>useEffect </em>I’ve place a return statement that sets <em>mounted </em>to <em>false. </em>This is required as the <em>useEffect</em> functionality takes on asynchronous behaviour by making fetch requests, and ensures that any promises are cancelled before the component is mounted to the DOM<em>. </em>This will avoid memory leaks within your application, which if not taken care of, your browser will complain about.</p><p>Then, we use <em>fetch</em> to call the endpoint ‘<a href="https://hnrss.org/newest">https://hnrss.org/newest</a>’. Alternatively this can and should be done by calling your own server that will then request data from the API, that way effective caching and cross-site strategies can be implemented.</p><p>After the ‘hnrss’ data is fetched, we create a new <em>DOMParser</em> object allowing us to parse the XML response data. From there we map through the <em>xmlDoc</em> variable (that we set the XML response to) and extract <em>‘title’</em> and <em>‘link’</em> to display in the scrolling ticker.</p><p>Finally, if and only if the component is still mounted to the DOM, we set the feed state with the new <em>items</em> array.</p><h4>GetRssFeedData Return Value</h4><p>Now that we have fetched and set the data we need for the scrolling ticker, we need to set a return value for the <em>GetRssFeedData </em>component.</p><pre>// TickerFeed.jsx</pre><pre>import React, { useState, useEffect } from &#39;React&#39;;<br>import Ticker from &#39;react-ticker&#39;;</pre><pre>const TickerFeed = () =&gt; {<br>  <br>   const GetRssFeedData = () =&gt; {<br>      const [feed, setFeed] = useState();<br>      <br>      useEffect(() =&gt; {<br>         <br>         let mounted = true;</pre><pre>const getRss = async () =&gt; {<br>            await fetch(&#39;<em>https://hnrss.org/newest</em>&#39;)<br>              .then((<em>res</em>) =&gt; <em>res</em>.text())<br>              .then((<em>data</em>) =&gt; {<br>                 const xmlDoc = <br>                    new DOMParser()<br>                       .parseFromString(<em>data</em>, &#39;text/xml&#39;);</pre><pre>const items = <br>                    Array.from(<br>                       xmlDoc.querySelectorAll(&#39;item&#39;))<br>                         .map((<em>item</em>) =&gt; ({<br>                            title: <em>item<br>                               </em>.querySelector(&#39;title&#39;).textContent,<br>                            link: <em>item<br>                               </em>.querySelector(&#39;link&#39;).textContent,<br>                 }));<br>                 <br>               if (mounted) {<br>                setFeed(items);<br>               }<br>            });<br>         };<br>         getRss();<br>    <br>         return () =&gt; {<br>            mounted = false;<br>         };<br>    }, []);<br>    <br>    <strong>return feed ? (<br>       &lt;p <em>className</em>=&quot;ticker__field__text&quot;&gt;<br>         {feed.map((<em>items</em>) =&gt; (<br>             &lt;a <br>                <em>key</em>={<em>items</em>.title} <br>                <em>id</em>={uuidv4()} <br>                <em>href</em>={<em>items</em>.link || &#39;&#39;} <br>                <em>target</em>=&quot;_blank&quot; <em>rel</em>=&quot;noopener&quot;&gt;<br>        <br>                {<em>items</em>.title}<br>             &lt;/a&gt;<br>          ))}<br>       &lt;/p&gt;<br>    ) : (<br>       &lt;p <em>className</em>=&quot;ticker__field__text&quot;&gt;<br>          &lt;span <em>style</em>={{ color: &#39;#f4f4f4&#39; }}&gt;<br>            Just Waiting for the Feed!<br>          &lt;/span&gt;<br>       &lt;/p&gt;<br>    );</strong><br>};</pre><pre>return (<br>      &lt;div className=&quot;ticker&quot;&gt;<br>         &lt;div className=&quot;ticker__field&quot;&gt;<br>            &lt;Ticker offset=&quot;run-in&quot;&gt;<br>               {() =&gt; <br>                  &lt;GetRssFeedData /&gt;<br>               }<br>            &lt;/Ticker&gt;<br>         &lt;/div&gt;<br>      &lt;/div&gt;<br>   );<br>};</pre><pre>export default TickerFeed;</pre><p>The return value is a conditional, where if the <em>feed</em> state is set, then that is returned, otherwise placeholder text <em>‘Just Waiting for the Feed!’</em> is returned instead (if there was an error fetching the API data).</p><p>The contents of the returned <em>&lt;p&gt;</em> element is set to <em>items.title </em>which is then wrapped in a link value of <em>items.link. </em>This will link to the corresponding Hacker News post.</p><h4>Final Styling</h4><p>In the return value, the <em>&lt;p&gt;</em> element has a class name of <em>‘ticker__field__text’</em>;</p><pre>.ticker__field__text {<br>   line-height: 50px;<br>   font-size: 14px;<br>   vertical-align: middle;<br>   white-space: nowrap;<br>   margin-left: 3rem;<br>   padding-top: 0px;<br>   height: 40px;<br>}</pre><pre>a {<br>   text-decoration: none;<br>   color: #f4f4f4;<br>   padding-right: 3rem;</pre><pre>}</pre><h3>Putting it Altogether</h3><p>The final code for <em>TickerFeed.jsx</em> should look like the following;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43de3816f30030f7269c5c53ae3cae37/href">https://medium.com/media/43de3816f30030f7269c5c53ae3cae37/href</a></iframe><p>I hope you found some of the ideas in this article either helpful or at least interesting! Feel free take a look at some of the other stuff I’ve written on full-stack development and devops. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42633320a2b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a CI Pipeline with GitLab]]></title>
            <link>https://willdvlpr.medium.com/creating-a-ci-pipeline-with-gitlab-b4bd0b68e80c?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4bd0b68e80c</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Wed, 21 Jul 2021 02:54:08 GMT</pubDate>
            <atom:updated>2021-07-21T02:54:08.134Z</atom:updated>
            <content:encoded><![CDATA[<p>GitLab and Google Container Registry are a Great Couple</p><p>The purpose of this article, is to cover how to create a simple CI pipeline using GitLab to push newly built Docker images to Google Container Registry in GCP (Google Cloud Platform).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*q3FOhfNgzzFx_eE3054SBw.png" /><figcaption>Image is property of <a href="https://gitlab.com/">https://gitlab.com/</a></figcaption></figure><h4>Firstly, you will need your code in a GitLab Project.</h4><p>If you’ve ever created a GitHub repo, then this should be pretty straightforward, if not, <a href="https://docs.gitlab.com/ee/user/project/working_with_projects.html">check out the very detailed GitLab docs!</a></p><h4>Next, your codebase needs to be Docker ready.</h4><p>This means ready-to-go Dockerfiles for containerizing your client and server code. My <a href="https://socioprophet.blog/containerizing-a-react-node-js-app-using-docker-and-nginx-a338d14ad68d">previous article</a> explains how to use Docker to containerize such an application, including all the configuration for a React/Node.js set-up.</p><p>Now, we move over to Google Cloud Platform!</p><h3>Creating a New Google Cloud Project</h3><p>Upon creating a GCP account by signing in to GCP, you will be taken to a home dashboard that looks similar to the image below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9e1OkwGWi_B1pWIWxCigQw.png" /><figcaption>Newly created GCP account dashboard</figcaption></figure><p>From here, simply click ‘CREATE PROJECT’, enter a ‘Project Name’, and click ‘CREATE’.</p><p>In the side navigation, scroll down until you find ‘Container Registry’ under ‘CI/CD’,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pmjRy_z1vUBXBIPhKveueA.png" /></figure><p>Once, you’ve click on ‘Container Registry’, you will have to enable billing for your GCP account, Google offers USD$300 of credit to new accounts to get started, which for the purposes here is more than enough. However, feel free to disable billing and delete your project later to prevent any charges incurring.</p><h4>Create a Service Account</h4><p>We need to create a cloud service account, which will provide us with credentials that we can use later to authenticate between GitLab and GCP.</p><p>Again, in the side navigation, select ‘IAM &amp; Admin’ &gt; ‘Service Accounts’ &gt; Click ‘+ Create Service Account’,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*HKMUO_y-Ft-WpdWhkXdZdA.png" /></figure><p>Steps 2 and 3 are optional but highly recommended if your projects are under and organisation with multiple users, since you should always follow the principle of least privilege where possible.</p><p>Once the service account has been created, select it from the service accounts list and select the ‘KEYS’ tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*21zst3GekfLcQ4qP16AoOQ.png" /><figcaption>Creating a new key for the service account</figcaption></figure><p>Select ‘Create new key’, and choose the JSON option since this will give you a downloadable JSON file with the service account credentials.</p><blockquote>Don’t share this JSON file, and be sure to keep it somewhere safe (just as you would with login details to your own bank account!) The service account keys allow any individual or system to authenticate to your GCP account, hence they should be as restricted as possible.</blockquote><h4>Add Service Account Key to GitLab</h4><p>In your GitLab account, go to the project settings and then select ‘CI/CD’,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/149/1*LfZV72OVYj0oulp0LhLzsA.png" /></figure><p>and then expand on the ‘Variables’ section,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*UFmEb4I30lhQ1tlJL38mRA.png" /></figure><p>As you can see, I already have added the key our SocioProphet codebase, but to add a new secret variable, simply click ‘Add variable’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*tzHono1vAgp6iu2l0B122g.png" /></figure><p>Fill out the ‘Key’ field which in my case I called it ‘GCLOUD_SERICE_KEY’, and then copy and paste the contents of the JSON key file into the ‘Value’ field. Simply leave all the other options as they are and click ‘Add variable’. Your GCP credentials have now been added to your GitLab account!</p><h4>Initializing the GCloud CLI</h4><p>The GCloud CLI provides an SDK for interacting with your Google Cloud account and the various projects you may have, all from the command line. This is important especially since we need to write terminal based commands in our GitLab CI configuration file. The documentation won’t lead you astray and has installation instructions for Linux, macOS and Windows. Check out the docs here titled <a href="https://cloud.google.com/sdk/docs/install">Installing Google Cloud SDK</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*7_MfL3X3twAstS4Zllw08Q.png" /><figcaption>Snippet of the Google Cloud SDK installation documentation, from <a href="https://cloud.google.com/sdk/docs/install">https://cloud.google.com/sdk/docs/install</a></figcaption></figure><p>By this stage, we now have a GCP project with the Google Container Registry enabled, a GitLab project with the GCP service account key stored as a secret variable, and the Cloud SDK CLI installed, now we can create the actual pipeline!</p><h3>GitLab CI Pipeline Configuration</h3><p>First, create a file called <em>.gitlab-ci.yml</em> in the root of your repository.</p><p>You have a lot of options and flexibility over what this pipeline does, however, for now we will add some basic stages such as build, test, and docker_image.</p><p>To use CI/CD in GitLab, you will need to install runners for your project. The <a href="https://docs.gitlab.com/runner/install/">GitLab documentation explains this perfectly</a>.</p><h4>Configuration Base</h4><p>Since each stage needs an environment to run, we need to set that first;</p><pre>image: node:latest</pre><p>Then we can define the stages for the pipeline;</p><pre>stages:<br>  - build<br>  - test<br>  - docker_image</pre><h4>Build Stage</h4><p>The build stage is going to build you application (build client code typically using something like Webpack) to make sure everything is running smoothly.</p><pre>build:<br>  stage: build<br>  script:<br>     - make build_web<br>     - make build_client</pre><p>We define this section as ‘<em>build’</em> and reference it to the <em>build</em> stage we mentioned under ‘<em>stages’</em>. Then we add the required scripts. Yours may be something like</p><pre>...<br>  script:<br>     - npm build</pre><p>However, I use bash scripts and Makefiles to automate a lot of this stuff. If you’re interested I wrote an article explaining how to set this up titled, <a href="https://socioprophet.blog/using-a-makefile-with-your-web-app-6d92a81cc9f6">Using a Makefile with Your Web App</a>.</p><h4>Test Stage</h4><p>Next, if you have testing implemented in you application using Jest or something similar, that can be added in the test stage as follows;</p><pre>test:<br>  stage: test<br>  script:<br>     - &quot;cd ./[your-project]/client/ &amp;&amp; yarn test&quot;</pre><p>Your script may be similar but I’m sure you get the idea 😃</p><h4>Docker Stage</h4><p>Finally, the stage we’ve been building up to!</p><pre>docker_image:<br>  stage: docker_image<br>  image: docker:stable</pre><pre>services:<br>     - docker:dind</pre><p>We have to define a separate image for this stage to run in since we are using Docker here, so just use the latest stable version of Docker!</p><h4>Setting Variables</h4><pre>GCP_PROJECT_ID: [your project id]<br>IMAGE_NAME_CLIENT: [the name of your client docker image]<br>IMAGE_NAME_SERVER: [the name of your server docker image]</pre><p>In the GCP Console, in the header, there will be a drop down menu on your project name, after selecting that, a pop-up screen will appear that lists the project name in the left column and project id in the right column. That is the project id we are using here for the GCP_PROJECT_ID variable.</p><p>The next two variables can of course be called whatever you’d like them to be.</p><h4>Authenticating to Google Container Registry using the Service Key</h4><p>Now we can start defining the scripts for the docker stage. Firstly, we authenticate to GCR using the variable we created earlier, GCLOUD_SERVICE_KEY.</p><pre>script:<br> - docker login -u _json_key -p &quot;$GCLOUD_SERVICE_KEY&quot; <a href="https://gcr.io/">https://gcr.io</a></pre><p>This tells docker to login to gcr at ‘https://gcr.io’ using the JSON value of the service key variable.</p><h4>Building the Docker Images</h4><p>First, let’s build the client image;</p><pre>...</pre><pre>- &quot;cd [into where your client Dockerfile is] &amp;&amp; docker build -t gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME_CLIENT:release-candidate .&quot;</pre><p>This command will build the docker image (according to your Dockerfile) and tag it as <em>gcr.io/[project id]/[image name]:release-candidate</em></p><p>Also, don’t forget the tag version can be whatever you find appropriate for the image.</p><p>Next, build the server image;</p><pre>...</pre><pre>- &quot;cd ../[into where your server Dockerfile is] &amp;&amp; docker build -t gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME_SERVER:release-candidate .&quot;</pre><h4>Pushing the Docker Images to the Container Registry</h4><p>Now, we can push the images to the Google Container Registry!</p><pre>...</pre><pre>- docker push gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME_CLIENT:release-candidate</pre><pre>- docker push gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME_SERVER:release-candidate</pre><h3>Full YAML Configuration</h3><p>Your final configuration should look similar to below;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d6b74f207fb59ff8e4cbaa702098cb0/href">https://medium.com/media/3d6b74f207fb59ff8e4cbaa702098cb0/href</a></iframe><p>Line 40 tells the pipeline to <strong>ONLY</strong> run when code is pushed to the ‘master’ branch which in my case is the production branch.</p><p>After the pipeline runs (GitLab will detect when code is pushed to the repo), you will get a status message, saying ‘passed’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*WUe_uakt1c2WnTUemIfgJQ.png" /><figcaption>Successful pipeline completion</figcaption></figure><p>This means the new docker images will have been pushed to GCR and we can check them out! Go to your GCP Console and under the images tab of ‘Container Registry’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SO5QEvko5hDHETUrtEy-4A.png" /><figcaption>Docker images listed in the Google project container registry</figcaption></figure><p>These images can them be used as part of a managed instance deployment or in Compute Engine in a container optimized OS virtual machine.</p><p><strong>I hope this article helped you get started on your CI/CD journey!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4bd0b68e80c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing a React + Node.js App using Docker (and NGINX)]]></title>
            <link>https://willdvlpr.medium.com/containerizing-a-react-node-js-app-using-docker-and-nginx-60b63796d67b?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b63796d67b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Wed, 07 Jul 2021 00:42:51 GMT</pubDate>
            <atom:updated>2021-10-25T22:28:56.668Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Google Kubernetes Engine or, GKE, is a fully managed Kubernetes service, that allows you to deploy highly scalable and available applications either through the Kubernetes and GCloud CLI or through the GCP (Google Cloud Platform) console.</blockquote><p>This and the following article will run through how to deploy a client/server web app on GKE using Docker to first containerize the application, and Nginx to serve the front-end content. I’ll assume that if you are reading this, you probably understand at least what Kubernetes and Docker is, and why you would use them to deploy your app. A prerequisite would also be that you have installed Docker locally on your machine, as well as Kubernetes and <em>Kubectl. </em>What I really want to do is discuss <strong><em>how</em></strong> its all used!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*KWeXamv1oqIvzKLlPhn-rA.png" /></figure><h3>How are we going to do this?</h3><p>The approach I went with, and in my opinion the most flexible, is to containerize the React code and Node.js code separately. If your server were to experience an interruption or go down all together, you still want users to at least access all the browser functionality of your site while the problem is being fixed. And while all the code will essentially exist in the same Kubernetes cluster, the images that the containerization produces are completely independent of each other!</p><h3>Dockerfile and Dockerignore</h3><h4>Dockerfile</h4><p>A dockerfile is a file that contains all the commands for building the docker image from your code repository. A dockerfile has no extension and is generally at the root of the code that you want containerized.</p><p>Dockerfiles are quite readable using commands such as <strong>FROM</strong>, <strong>COPY</strong>, <strong>RUN</strong>, <strong>EXPOSE</strong>, etc, and typically rely on knowledge of basic Linux/UNIX terminal commands. Your dockerfile procedure will basically include setting up a Linux image that everything can run in, creating a working directory for the code to go in, copying over your <em>package.json</em> file so all the dependencies are there ready to go, then copying over the rest of the React files, running <em>yarn/npm build</em><strong><em> </em></strong>and finally configuring Nginx to serve the files. The Nginx port will be exposed to the Kubernetes cluster so everything communicates nicely.</p><h4>Dockerignore</h4><p>The dockerignore file is basically the docker version of a gitignore file. The same way gitignore tells git what <strong>not</strong> to push to GitHub, dockerignore tells docker what not to add to the container. What we add to this file will be covered below!</p><h3>Containerizing the Server-Side Code (Node.js + Express)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*HGu1nGAkk9HqIb6ashYX7Q.jpeg" /><figcaption>Using Docker to produce a container image of the Node.js back-end</figcaption></figure><p>In the root of your server code (in most setups, in the root of a folder called <em>server</em>) create a file called <em>Dockerfile</em> (no extension). Still in the root directory, create a file called <em>.dockerignore;</em></p><pre>cd server<br>touch Dockerfile .dockerignore</pre><p>Your server structure may now look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*H9jN6GXzJgGc6jh2rRzoAQ.png" /><figcaption>Includes node_modules, routes, package.json, server.js and the newly created Dockerfile and .dockerignore file</figcaption></figure><p>In the Dockerfile, we want to follow these steps;</p><ol><li>Setup the Linux image</li><li>Set the working directory for the container</li><li>Copy over our <em>package.json</em> file</li><li>Install the dependencies into the container (from <em>package.json</em>)</li><li>Tell the container what port to listen to</li><li>Run the server code in the container</li><li>Copy over the rest of the files from your local machine</li></ol><p>Start with the Linux image, simply add to the first line of the Dockerfile;</p><pre>FROM node:15.3.0-alpine3.10</pre><p>It is convention that keywords are capitalized. This line is telling the docker container to use a specific version of Alpine Linux. We need this since our server runs in node and the container environment runs in Linux.</p><p>Next create the working directory;</p><pre>WORKDIR /usr/src/app/server</pre><p>This tells the container we want the code to go into the directory as described ‘<em>/usr/src/app/server’</em>. (This is up to you what path you want to define!)</p><p>Next copy over the <em>package.json</em> file;</p><pre>COPY package.json .</pre><p>The ‘.’ represents the root of the directory we are moving <em>package.json </em>to, which makes sense since this file is always in the root of the code.</p><p>Next we install the dependencies.</p><pre>RUN yarn</pre><p>You may be using NPM so ‘<em>RUN npm install</em>’ would be appropriate there.</p><p>Now we tell the docker container what port to listen to so it communicates with our server code. In my case I’m using port 5001;</p><pre>EXPOSE 5001</pre><p>Now we want to run the server code within the container. Since my <em>package.json </em>start script is <em>node server.js</em> the Dockerfile command is;</p><pre>CMD [ &quot;yarn&quot;, &quot;start&quot; ]</pre><p>This tells the container to use <em>yarn</em> to run the <em>start</em> script in <em>package.json</em>.</p><p>Finally, we need to copy the rest of the local server files over into the container;</p><pre>COPY . .</pre><p>The first ‘.’ represents all files at the level of the Dockerfile in the local directory, and the second ‘.’ tells Docker to copy everything exactly as it is in level with the <em>package.json</em> we copied over before.</p><p>The final Dockerfile should look similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/462d57ef7232ffd471fd78d1860048d2/href">https://medium.com/media/462d57ef7232ffd471fd78d1860048d2/href</a></iframe><h4>.dockerignore</h4><p>The <em>.dockerignore</em> file looks just like a <em>.gitignore </em>file. However, the items we want to ignore are a little different. A typical <em>.dockerignore</em> will look as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5d6a26101d500d8d14c571b62668766/href">https://medium.com/media/f5d6a26101d500d8d14c571b62668766/href</a></iframe><p>We don’t need <em>node_modules</em> since we are running <em>yarn (or npm install)</em> in the container after copying over <em>package.json, </em>so a fresh copy of the <em>node_modules </em>will be installed anyway.</p><p>We also don’t need Git (<em>.git)</em> or the <em>.gitignore </em>file since the container isn’t using version control. If we don’t need it we don’t want it in the container causing unnecessary bloat!</p><p>Depending on how you are managing secrets and environment variables, you may want to ignore any <em>.env</em> files you have as well. I have put <em>.env </em>in my <em>.dockerignore</em> since I have added my variables to the K8 Pod deployment as Kubernetes secrets, so no need for <em>.env</em>.</p><h3>Containerizing the Client-Side Code (React)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*ZCaHnTUNo2Xv1HmNmSht0Q.jpeg" /><figcaption>Using Docker to produce a container image of the React front-end</figcaption></figure><p>For the client side code we are doing the same thing just with a few extra steps involved. First create the <em>Dockerfile </em>and <em>.dockerignore</em> files in the root of you client directory.</p><p>The steps for a docker container running React code are as follows;</p><ol><li>Setup the Linux image</li><li>Set the working directory for the container</li><li>Copy over our <em>package.json</em> file</li><li>Copy over the <em>yarn.lock (or package-lock.json)</em> file</li><li>Add environment dependencies such as node gyp and python for installing certain <em>package.json</em> dependencies</li><li>Copy over the rest of the files from the local machine</li><li>Run the build command</li><li>Set up an Alpine image for Nginx</li><li>Copy over the <em>build/</em> folder into Nginx to serve through HTML</li><li>Remove the default Nginx configuration</li><li>Copy your Nginx configuration into the container</li><li>Expose the Nginx port (default is 80)</li><li>Run the Nginx web server</li></ol><p>First, lets go over creating an Nginx configuration!</p><h4>NGINX Configuration</h4><p>Nginx is simply an open-source web server that can be used to create proxies, perform load balancing, and increase the security of your application. Since our server container <strong>IS</strong> a server, it doesn’t require additional tools to expose itself to a network, however our front-end React code needs Nginx to serve our <em>build </em>content to the web. In this case, we need our front-end container to communicate within our Kubernetes cluster (which itself will be exposed to the public internet) that we will eventually create!</p><p>In the root of you client directory, create a folder called <em>nginx</em> and inside create a file called <em>nginx.conf;</em></p><pre>cd client &amp;&amp; mkdir nginx<br>cd nginx &amp;&amp; touch nginx.conf</pre><p>You can copy the contents of the gist below into your nginx configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a68c86a2172c45e39c873835af1d4d7b/href">https://medium.com/media/a68c86a2172c45e39c873835af1d4d7b/href</a></iframe><p>We are creating a <strong>server</strong> body that listens to port 80 (default exposed Nginx port).</p><p>Then we create a <strong>location /</strong> body (lines 4–8) that will serve the contents of <em>/usr/share/nginx/html/index.htm*</em> when a request for the root domain is made. For example, <strong>yourdomain.com</strong>. This will also work if you are using React-Router and have routes such as <strong>yourdomain.com/page1</strong> or <strong>yourdomain.com/home</strong>.</p><p><em>error_page</em> is defined on line 10 to serve the default Nginx web page for any error it encounters (since Nginx is a web server, all Nginx errors return a 50x status code). Lines 12–14 tell Nginx where to serve the 50x error page from.</p><p>Now that we have a basic Nginx configuration complete, let’s move on to the Docker stuff!</p><p>So, firstly in our client <em>Dockerfile</em> we need the Alpine Linux image;</p><pre>FROM node:15-alpine as build</pre><blockquote>We are setting this ‘<strong><em>as</em></strong> <strong><em>build’</em></strong> to use later in our <em>Dockerfile</em> when we want to run everything we build in the Alpine image within Nginx.</blockquote><p>Next, set up the working directory similar to how we did in the server container;</p><pre>WORKDIR /usr/src/app/</pre><p>Then, copy over the <em>package.json</em> file into the current directory using ‘.’;</p><pre>COPY package.json .</pre><p>Also copy over <em>yarn.lock (or package-lock.json)</em> depending on what you’re using;</p><pre>COPY yarn.lock .</pre><p>Next, we add a script that will install some dependencies into the container such as node-gyp and Python. We need these since we have third-party NPM packages as dependencies to install for our application. We then install the dependencies from our <em>package.json</em> file and remove all the virtual environment dependencies we just added.</p><blockquote>It is likely your local dev environment has all these things installed, but since the Alpine Linux image is bare bones, we need to give it a hand;</blockquote><pre>RUN apk add --no-cache --virtual .gyp \<br>    python \<br>    make \<br>    g++ \<br>    &amp;&amp; yarn \<br>    &amp;&amp; apk del .gyp</pre><p>Simply copy and paste the above into your <em>Dockerfile. </em>Without these modules, your container will struggle to install your NPM dependencies (and as with any React application <strong>not using</strong> <em>create-react-app</em>, there are a lot!)</p><p>Next, copy over the rest of the client files;</p><pre>COPY . .</pre><p>Now, we can build. I’m using Webpack to create the output bundle, in which my <em>package.json</em> script looks like ‘<em>build: webpack’, </em>so;</p><pre>RUN yarn build</pre><p>That’s stage 1 of our client Docker container complete! Next, Nginx.</p><p>Let’s pull down the Nginx image;</p><pre>FROM nginx:stable-alpine</pre><p>Remember the <strong><em>as build</em></strong> we set earlier, well now we use that here;</p><pre>COPY --from=build /usr/src/app/build /usr/share/nginx/html</pre><p>We are telling docker to use the <strong><em>build</em></strong> we just created above (that resides in the directory <em>/usr/src/app/build</em>) and copy it into the Nginx directory <em>/usr/share/nginx/html</em></p><p>Now we remove the default Nginx configuration;</p><pre>RUN rm /etc/nginx/conf.d/default.conf</pre><p>The default Nginx config is always stored in <em>/etc/nginx/conf.d/default.conf.</em></p><p>Now copy over our Nginx configuration we created earlier;</p><pre>COPY nginx/nginx.conf /etc/nginx/conf.d</pre><p>Now expose the Nginx default port 80;</p><pre>EXPOSE 80</pre><p>And finally run the Nginx server;</p><pre>CMD [ &quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot; ]</pre><p>The final Dockerfile should look similar to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1de1dcdf4338f560430298d5f359274a/href">https://medium.com/media/1de1dcdf4338f560430298d5f359274a/href</a></iframe><h4>.dockerignore</h4><p>The <em>.dockerignore </em>will be very similar to the server one from before, except if you have a <em>build/ </em>directory already in your client code, you don’t want to copy that over, so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef03c334f873bb6b63e2cdbdafec1511/href">https://medium.com/media/ef03c334f873bb6b63e2cdbdafec1511/href</a></iframe><h3>Finally Building the Docker Images</h3><p>Assuming you have Docker installed, we can now use some basic CLI commands to build the images. Making sure you are in the same directory as your Dockerfile;</p><pre>docker build -t [image-name]:[image-version] .</pre><p>Image name and image version can be anything you want. The flag ‘-t’ stand for tag, as we are tagging the build with a name and version. Run this command from both server and client directory.</p><p>You can run,</p><pre>docker ps -a</pre><p>and this will show all the images you have.</p><p>If you made it this far, I hope you found this article helpful! 😄 💻</p><p><strong>In the next article, we will create a Kubernetes cluster on GKE and deploy our client and server images to the cluster, so stay tuned!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b63796d67b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use IBM’s Carbon Design System (React) to Create a Quick UI]]></title>
            <link>https://willdvlpr.medium.com/how-to-use-ibms-carbon-design-system-react-to-create-a-quick-ui-f10b8290f29?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/f10b8290f29</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Thu, 10 Jun 2021 01:40:39 GMT</pubDate>
            <atom:updated>2021-08-17T07:18:35.769Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Will Jones, Engineer &amp; Cofounder SocioProphet</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5sQlEEso8EZ96riBjWTIaw.png" /><figcaption>Image: IBM — <a href="https://www.carbondesignsystem.com/">https://www.carbondesignsystem.com/</a></figcaption></figure><p>When you get to building your web application’s UI, it can be handy to work with a design system. This allows you to rather effortlessly create quick and responsive interfaces, that generally have properties (props) defined in them that allow you to also generate your UX. An extremely popular design framework is Google’s <a href="https://material-ui.com/">Material UI</a>. However, another not as well known, but nonetheless full fledged design system is IBM’s design system, <a href="https://www.carbondesignsystem.com/">Carbon</a>.</p><h3>What is the Carbon Design System?</h3><p>From the Carbon homepage,</p><blockquote>Carbon is IBM’s open source design system for products and digital experiences. With the IBM Design Language as its foundation, the system consists of working code, design tools and resources, human interface guidelines, and a vibrant community of contributors.</blockquote><p>The system is built for developers to use either React, Angular, or Vue. The site <a href="https://www.carbondesignsystem.com/">carbondesignsystem.com</a> has all their components completely open source, design guidelines, color palette examples, and tutorials. The IBM color theme which primarily incorporates offset whites, multiple shades of blue, and of course carbon black, was the inspiration for <a href="https://www.socioprophet.com/">SocioProphet’s</a> design theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZX4EoOhTQbaBy-EhR1z9IA.png" /><figcaption>Image: IBM — <a href="https://www.carbondesignsystem.com/">https://www.carbondesignsystem.com/</a></figcaption></figure><p>While SocioProphet no longer uses any Carbon components, or any part of the Carbon Design System, it was an extremely useful starting point. So, I’ll explain how to get started using Carbon in you React project, and give an example of the simple interface we created to begin with!</p><h3>Installing Carbon</h3><p>I use <em>yarn</em> as my package manager, however, the following works with <em>npm</em>.</p><p>There are three things that need to be installed to get started, those are;</p><ol><li>Component styles — ‘carbon-components’</li><li>React components — ‘carbon-components-react’</li><li>React icons (for the components) — ‘@carbon/icons-react;</li></ol><p>So, in your project (or globally if you prefer),</p><pre>yarn add carbon-components carbon-components-react @carbon/icons-react carbon-icons</pre><p>Carbon styles uses <a href="https://sass-lang.com/">Sass</a>, which is a CSS preprocessor that gives you the ability to ‘program’ CSS. This includes things like variables, inheritance, etc. Essentially Sass is a CSS superset. Anyway, we need to install that as well.</p><pre>yarn add sass</pre><p>In you React project, you will typically have the following structure;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/155/1*9jRk1xfjRbOdbZsAaMyzJw.png" /><figcaption>Typical React app structure (not using CRA)</figcaption></figure><p>After installing Sass and the three Carbon packages, your <em>package.json</em> should look similar to this,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a5dcd7e4397df487b908be57cc929d4/href">https://medium.com/media/6a5dcd7e4397df487b908be57cc929d4/href</a></iframe><p><strong>You will also need to change <em>App.css </em>extension to <em>App.scss</em> and make sure you change the import in <em>App.js</em> to include <em>App.scss.</em></strong></p><p>If you used <em>‘npx create-react-app’</em> to begin your application, you won’t need to worry about the following additions. However, if you are configuring Webpack from scratch, you’ll need to add a few lines and another package.</p><pre>yarn add sass-loader</pre><p><em>sass-loader</em> allows Webpack to load and compile Sass (.scss) files.</p><p>For your Webpack configuration, add the sass-loader to the module rules,</p><pre>module: {<br>    rules: [ <br>       <br>        ...</pre><pre>       {<br>          test: /\.(s*)css$/,<br>          use: [&#39;style-loader, &#39;css-loader&#39;, <strong><em>&#39;sass-loader&#39;</em></strong>],<br>       },</pre><pre>        ...</pre><pre>   ],<br>},</pre><p>Now that everything is set up and installed, let’s move on to using Carbon!</p><h3>Importing Components and Styles</h3><h4>Styles</h4><p>First of all, in your <em>index.scss </em>add the following import,</p><pre>@import &#39;carbon-components/scss/globals/scss/styles.scss&#39;;</pre><p>This import alone will apply the Carbon font family ‘IBM Plex Sans’, font sizes, weight, colors, margins and padding (along with a few other CSS values).</p><p>The import goes in the <em>index.scss</em> file in order to reduce the amount of re-compiling Sass will do. We want to modify our app level styles, such as <em>App.scss</em> as this will lead to quicker compile times.</p><h4>Components</h4><p>A common component you might use is a button, and of course, there is a Carbon button.</p><p>At the top of your <em>App.js</em> file (or whatever component will need a button), add</p><pre>import { Button } from &#39;carbon-components-react&#39;;</pre><p>Then, inside the App component add,</p><pre>&lt;Button&gt;This is a Carbon Button!&lt;/Button&gt;</pre><p>So far, <em>App.js </em>looks like,</p><pre>import React from &#39;react&#39;;</pre><pre>import { Button } from &#39;carbon-components-react&#39;;</pre><pre>import &#39;./App.scss&#39;</pre><pre>const App = () =&gt; {</pre><pre>    return (</pre><pre>        &lt;React.Fragment&gt;<br>        <br>             &lt;Button&gt;This is a Carbon Button!&lt;/Button&gt;</pre><pre>        &lt;/React.Fragment&gt;<br>    );</pre><pre>};</pre><pre>export default App;</pre><p>That’s it! That’s the basically all the important stuff.</p><p>It is good practice to only import what we need. To get a full understanding of how all the Carbon components are organised, you can visit the <a href="https://github.com/carbon-design-system/carbon">GitHub for Carbon Design System</a>.</p><p>For example, the ‘Header’ component is under <em>‘carbon-components-react/lib/components/UIShell’</em>.</p><p>So the import would be,</p><pre>import { Header } from &#39;carbon-components-react/lib/components/UIShell&#39;.</pre><h3>Building a UI From the Carbon Design System</h3><p>I’ll give an example of how we (SocioProphet) used Carbon to build a quick UI as a solid starting point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BkH3lS-HY30k5b5KNeMWg.png" /><figcaption>Initial ‘concept’ UI Shell using Carbon Design System</figcaption></figure><p>As you can see from this dashboard, we wanted a simple header that contained the site name ‘SocioProphet’, some navigation links, such as ‘News &amp; Events’, an app switcher icon, avatar icon, and a left side panel (which expands on mouseover).</p><p>The import for this was all from ‘<em>carbon-components-react/lib/components/UIShell</em>’.</p><pre>import { <br>   HeaderContainer, <br>   Header, <br>   SkipToContent, <br>   HeaderName,  <br>   HeaderNavigation,  <br>   HeaderMenuItem,  <br>   HeaderGlobalBar,  <br>   HeaderGlobalAction,  <br>   SideNav,  <br>   SideNavItems,  <br>   SideNavLink,  <br>   SideNavMenu,  <br>   SideNavMenuItem,<br>} from &quot;carbon-components-react/lib/components/UIShell&quot;;</pre><p>The full dashboard, including link components that can’t be seen in the image above is shown below in the gist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/535af7457d069734d9a0e13c183725c6/href">https://medium.com/media/535af7457d069734d9a0e13c183725c6/href</a></iframe><p>This is about as simple as it gets, since all these components have many props that can be used to give your site functionality. The above file shows a quick mock-up UI that met our initial requirements.</p><h3>Carbon Resources</h3><p>Carbon Design System has three primary themes (all open source) that I am aware of, I’ll share the React Storybooks for those here.</p><h4>Open Source Storybooks</h4><ol><li><a href="https://react.carbondesignsystem.com/?path=/story/getting-started-welcome--welcome">Standard — Carbon Components React v7.36.0</a> + <a href="https://github.com/carbon-design-system/carbon/tree/main/packages/react">GitHub</a></li><li><a href="https://ibm-security.carbondesignsystem.com/?path=/story/layout-modules-library--page">Carbon for IBM Security v1.41.0-prerelease.2</a> + <a href="https://github.com/carbon-design-system/ibm-security/">GitHub</a></li><li><a href="https://carbon-addons-iot-react.com/?path=/story/0-getting-started--about-storybook">carbon-addons-iot-react</a> + <a href="https://github.com/carbon-design-system/carbon-addons-iot-react">GitHub</a></li></ol><p>№2 and №3 provide extensions of the classic Carbon components, and №3 is used in Watson IoT components.</p><p>For SocioProphet’s UI (a few iterations in) we were using a combination of components from all three Storybooks.</p><h3>Further Note</h3><p>The<a href="https://www.carbondesignsystem.com/"> Carbon Homepage</a> provides lots of great learning resources to get started. This article touches briefly on a couple of ‘getting started’ ideas but if you’re eager to learn more, be sure to check out the free tutorial and earn one of those IBM badges! 😃</p><p><a href="https://www.carbondesignsystem.com/developing/react-tutorial/overview">Click Here for the Carbon React Tutorial</a></p><p>I hope this article was potentially helpful to one of your future projects! Check out my previous post on how to use a Makefile and Bash scripts to automate terminal commands when running a React application…</p><p><a href="https://socioprophet.blog/using-a-makefile-with-your-web-app-6d92a81cc9f6">Using a Makefile with Your Web App</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f10b8290f29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using a Makefile with Your Web App]]></title>
            <link>https://willdvlpr.medium.com/using-a-makefile-with-your-web-app-2e9e68bf4b53?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9e68bf4b53</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Thu, 03 Jun 2021 01:51:03 GMT</pubDate>
            <atom:updated>2022-04-17T05:41:43.720Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Will Jones, Engineer &amp; Cofounder SocioProphet</em></p><h3>What is a Makefile and Why Use It?</h3><h4>In short,</h4><p>a Makefile is a set of instructions, that’s it!</p><h4>In long,</h4><p>a Makefile is a file containing target commands that are executed using the UNIX ‘<em>make’</em> utility. These targets are file based targets that the Makefile will look for, however, in our case, we are using the targets as commands rather than physical entities in the file system. So, we create ‘phony’ targets for our commands using <strong><em>.PHONY</em></strong>.</p><p>For example, in the very first line of the Makefile, we define out targets,</p><pre>.PHONY: install_web run_web run_server run_client build_client</pre><p>More on the above later!</p><p>Using a Makefile gives a way to easily organise file compilation, and commonly used terminal commands you will come across when running your web application.</p><p>For example,</p><pre>yarn start // (or npm run start)</pre><pre>yarn // (or npm install)</pre><p>But, let’s say you have a client and server sub directory (as most modern web applications will), then you’ll have to <strong><em>cd</em></strong>from your root directory, into the server, run <strong><em>yarn</em></strong><em> (or </em><strong><em>npm install</em></strong><em>)</em> and then run <strong><em>yarn start </em></strong><em>(or</em><strong><em> npm run start</em></strong><em>). </em>Then, you’ll have to <strong><em>cd</em></strong> out of the server folder and into the client folder, run <strong><em>yarn </em></strong><em>(or </em><strong><em>npm install</em></strong><em>)</em> again, and then run <strong><em>yarn start</em></strong><em> (or</em><strong><em> npm run start</em></strong><em>) </em>again. Tedious terminal work if your are constantly starting and stopping you dev environment.</p><p>So, we use a Makefile to automate all of this!</p><blockquote><em>I know some people will say “why not just use concurrently to run the package.json scripts simultaneously?”, which is of course an option! But, if you intend on containerising your application and keeping the client and server code independent (serving the client over NGINX maybe?) and deploying on a Kubernetes cluster, you’ll want the client and server to have their own package.json files!</em></blockquote><h3>Setting Up</h3><p>In your root directory, we create the Makefile,</p><pre>~/app/$ touch Makefile</pre><p>As you can see, a Makefile has no file extension.</p><p>Then, create a folder to store the bash scripts the Makefile will use,</p><pre>~/app/$ mkdir scripts &amp;&amp; cd scripts</pre><p>For the SocioProphet web platform, we created the initial bash files for our Makefile,</p><pre>~/app/scripts/$ touch install_web.sh run_web.sh run_server.sh run_client.sh build_client.sh</pre><p>You should then have a folder in your root directory as such,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*l91JA9C7TzHPvXexPH0YYA.png" /><figcaption>Bash scripts for Makefile in ‘scripts’ folder</figcaption></figure><p>Now that all the files have been created, we define our Makefile.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/867ae42fb931544c7f853161419ab208/href">https://medium.com/media/867ae42fb931544c7f853161419ab208/href</a></iframe><p>Line 2 defines the targets, lines 5–6, 9–10, 13–14, 17–18, and 21–22 define what each of those target commands will do.</p><p>So, line 5–6 for example, tells the system to <strong><em>cd </em></strong>into <em>socioprophet-web/scripts </em>(or wherever you’d like to store the <em>scripts</em>folder) and then run the bash script <em>install_web.sh</em> using the command <strong><em>bash</em></strong><em>.</em></p><p>To run a Makefile command, use the <strong><em>make</em></strong> utility, for example,</p><pre>make install_web</pre><p>will execute in the terminal,</p><pre>cd socioprophet-web/scripts/ &amp;&amp; bash install_web.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rFzOqJjyqfddpvun" /><figcaption>Photo by <a href="https://unsplash.com/@marcotjokro?utm_source=medium&amp;utm_medium=referral">Marco Tjokro</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Now to Write the Bash Scripts</h3><h4>install_web.sh</h4><p>We will write bash commands in this file that will install all the dependencies for both the client and server sub directories.</p><p>In the first line of a bash file, it is useful to define the shell path.</p><pre><em>#!/usr/bin/env bash</em></pre><p>This of course assumes a dependency on bash, so if you are using a different shell, the definition may be different. (Bash however, is the default for the majority of systems).</p><p>The next two commands to install dependencies are,</p><pre>cd .. &amp;&amp; cd client &amp;&amp; yarn<br>cd .. &amp;&amp; cd server &amp;&amp; yarn</pre><p>(The <strong><em>cd .. &amp;&amp; cd client</em></strong> will be dependent on your project structure)</p><p>The final <em>install_web.sh</em> file,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd212480d80e83336a54adf763e59ee3/href">https://medium.com/media/cd212480d80e83336a54adf763e59ee3/href</a></iframe><p>Now, when we run <strong><em>make install_web</em></strong> the following happens,</p><pre>cd socioprophet-web/scripts/<br>bash install_web.sh<br>cd .. <br>cd client<br>yarn<br>cd..<br>cd server<br>yarn</pre><p>Eight separate commands, reduced to one!</p><blockquote>Please note, the bash commands are dependent upon how you define your scripts inside of your <em>package.json</em>file.</blockquote><h3>Makefile and Bash Scripts Configuration for SocioProphet</h3><h4>Makefile</h4><p>Defines the commands.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf76078347fa219ddd44c1a0178058b5/href">https://medium.com/media/bf76078347fa219ddd44c1a0178058b5/href</a></iframe><h4>install_web.sh</h4><p>Installs client and server dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd212480d80e83336a54adf763e59ee3/href">https://medium.com/media/cd212480d80e83336a54adf763e59ee3/href</a></iframe><h4>run_web.sh</h4><p>Runs the server code in the background and runs the client code such that server and client are running simultaneously in one command <strong><em>make run_web</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4ecf366fa2bf32333e6aedb4c926a3f/href">https://medium.com/media/b4ecf366fa2bf32333e6aedb4c926a3f/href</a></iframe><h4>run_server.sh</h4><p>Runs the server code by itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0f24db42bb0188185aa7841549d1eec/href">https://medium.com/media/c0f24db42bb0188185aa7841549d1eec/href</a></iframe><h4>run_client.sh</h4><p>Runs the client code by itself using the webpack-dev-server</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4ceaba2ace7f7bbb37a2657a3c31975/href">https://medium.com/media/c4ceaba2ace7f7bbb37a2657a3c31975/href</a></iframe><h4>build_client.sh</h4><p>Builds the client code using Webpack into an output build directory</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5130552deee8d9c5a406811b113039de/href">https://medium.com/media/5130552deee8d9c5a406811b113039de/href</a></iframe><h3>Further Note</h3><blockquote>Bash programming allows for variables to be defined, just like in any other language, so if you wanted, you could define variables that represent an npm package that you wanted to install. Therefore, you could have a make command such as <strong><em>make install_package</em></strong> that would run a bash script that would <strong><em>cd</em></strong> into the relevant directory and run <strong><em>yarn add &lt;package name&gt;</em></strong>.</blockquote><blockquote><strong><em>The purpose of this would be never leaving the root directory in your terminal. New files, folders, binaries, anything can be created using the Makefile automation!</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9e68bf4b53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The SocioProphet Platform — Development]]></title>
            <link>https://willdvlpr.medium.com/the-socioprophet-platform-266cea73b024?source=rss-7e172aad0e30------2</link>
            <guid isPermaLink="false">https://medium.com/p/266cea73b024</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Will Jones]]></dc:creator>
            <pubDate>Wed, 02 Jun 2021 02:07:16 GMT</pubDate>
            <atom:updated>2021-06-08T08:13:46.795Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Will Jones, Engineer &amp; Cofounder SocioProphet</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N2BlAJH5d5t8iUPm.jpeg" /><figcaption>socioprophet.com background image</figcaption></figure><p>I intend to use these blog posts as a way of discussing and explaining certain design choices whilst building the SocioProphet web platform from a web development point of view. The web application for SocioProphet is a social networking platform, that will use a combination of peer-to-peer, federated, and centralized collaboration models for the purpose of allowing users to create a democratized community of data, AI, and analytics sharing!</p><p><a href="https://socioprophet.com/">SocioProphet - For Geeks, By Geeks</a></p><p>There is plenty more on this to discuss, however, I will try and keep inline with the motivation of this blog and talk about the tech stack being used and why I have done things a certain way. Think of the blog as a log and the posts as development entries. This will also be a good opportunity to explain things at a more technical level, hopefully allowing you to even learn something new!</p><p>The layout for these posts will cover firstly the business requirement or ‘design problem’, then I’ll try and explain the options to fulfil the requirement, and finally how we (SocioProphet) implemented one of those solutions. I feel it is safe to assume you may be a developer, or even an enthusiast? In such case, I’ll try my best not to bore you with the obvious technicalities and instead focus on the stuff you came here to read 😃</p><h3>Topics to Cover (not in any particular order)</h3><ol><li>Using a Makefile and Bash Scripts with Your React App</li><li>How to Use IBM’s Carbon Design System (React) to Create a Quick UI</li><li>Dockerizing Your Client and Server &amp; Using NGINX to Serve the Client</li><li>Creating a CI/CD Pipeline with GitLab &amp; GKE (Google Kubernetes Engine)</li><li>Google Cloud Platform (GCP) App Verification for API Scopes</li><li>Create a Scrolling Ticker with RSS Feed (Hacker News)</li><li>Using Netlify to Create a Staging Environment for UI/UX Team Review</li><li>Guide to a Web App Structure</li><li>And more…</li></ol><p>Hope you enjoy!</p><h3>A Little Disclaimer</h3><p><em>I am by no means an expert on anything I will discuss, I am simply explaining the decisions I have made, why I made them, and how I implemented them. And of course critiques and feedback is welcomed and definitely encouraged, I’d love to learn something too! 💻</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=266cea73b024" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>