<?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 ujwal dhakal on Medium]]></title>
        <description><![CDATA[Stories by ujwal dhakal on Medium]]></description>
        <link>https://medium.com/@ujwaldhakal?source=rss-c5a8eaa9345a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vFKVH36UBxeaBh6h3ZorYg.png</url>
            <title>Stories by ujwal dhakal on Medium</title>
            <link>https://medium.com/@ujwaldhakal?source=rss-c5a8eaa9345a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:30:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ujwaldhakal/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[Application Resilience: 4 Ways to Build It]]></title>
            <link>https://ujwaldhakal.medium.com/application-resilience-4-ways-to-build-it-7265e1ff3682?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7265e1ff3682</guid>
            <category><![CDATA[zero-downtime]]></category>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[application-architecture]]></category>
            <category><![CDATA[improvement]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Tue, 22 Nov 2022 12:57:12 GMT</pubDate>
            <atom:updated>2022-11-22T12:57:12.045Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Do you ever wonder if you could keep your application from experiencing any failures or downtime at all?</blockquote><p>The response is “No.” You can’t stop every single failure and downtime that could ever occur to an application.</p><p>You can improve a few areas to develop a robust system and mindset, so don’t worry.</p><p>Systems that recover fast after failure are considered resilient systems. Quick failure recovery does not always imply that if something goes wrong, it will be fixed in a short period of time. If the items could be recovered immediately, they would be recovered. If not, a simple procedure to fix the situation would need to be developed.</p><h3>How to build a resilient system</h3><p>There are multiple ways to build a resilient system but in this system, we will discuss 4 points only.</p><h4>1. Auto healing</h4><p>There should be some means of detecting downtime if your program or a particular component goes down. After a set amount of time, the program should be able to either continue the task from where it stopped off.</p><p>Let’s talk about the ways to introduce auto-healing</p><ul><li>Retry -: You should, if at all possible, have manual or automatic techniques to attempt again things that, for a variety of reasons, were not successful the first time. You can have a few possible retries, for instance, if you are running an eCommerce site and a consumer wants to pay using PayPal but PayPal is down.</li><li>Proper UX: In some circumstances, you can additionally plan the user experience (UX) of the application so that the end user is aware of any unfinished business. so that you can try again with less effort. For instance, anytime you post a video to Facebook, it will let you know after a short while whether the upload was successful or unsuccessful.</li></ul><h4>2. Monitoring</h4><p>You may track the behavior of your application over time by using monitoring. When I use the word &quot;behaving,&quot; I mean everything that is necessary for a business to function properly, including major errors, resource consumption, feature utilization, revenue numbers, and cost numbers.</p><ul><li>Logs: If handled properly, logs can be a highly important source of information. They serve as proof that a certain event occurred. For instance, you keep track of every time a consumer tries to pay and when they are unable to pay at a specific time. It can be used to determine</li><li>Metrics: Metrics are a method for quantifying anything. Anything that is significant to you can be measured. For instance, the total number of 4xx status codes, the total number of registered users, the total number of users who were unable to make a payment using PayPal, etc.</li><li>Alerting: Even if you have solid metrics and logs, what if you always need to check to see if something is working or not as expected? The alerting method involves informing you if there is a problem with the expectation you&#39;ve set. You can set up logs for anytime someone is unable to pay using PayPal so that you are notified through email, Slack, or SMS that the payment has failed for a specific user.</li></ul><h4>3. Testing</h4><p>Testing is a method of determining what would occur if you either gave specific data to a specific function or clicked certain before or after the page loaded if a third-party service went down, etc. It involves confirming your hypotheses regarding specific features, techniques, scenarios, and so forth.</p><p>Your application can be used or abused in a variety of ways, therefore by validating your assumptions, you are already protecting yourself. It enables you to make wiser decisions on what to do next. Writing units, integration, and, if applicable, end-to-end tests are a few examples.</p><h4>4. Incident Retros</h4><p>Failures and other potential negative outcomes are unavoidable, as we’ve already stated. Even when anything goes wrong, there should always be a discussion or report regarding what, when, and how it happened.</p><p>On the incident, retros make sure to not blame anyone because things happen not because of the person but because of not having the right process in the first place. After getting insights into how things happened. Try to come to a conclusion on setting up a process to over this kind of uncertainty for next time. For e.g User A was not able to pay because the payment service was down at that time could be a talk. Setting up a retry first on the first failure if payment still fails notify users that their action has failed. Create a simple way for users to retry the payment themselves.</p><h3>Conclusion</h3><p>Always remember that failure is inevitable; in light of this, attempt to think of three questions. What would happen, how would it affect us, and how could we handle this if something or some part broke down? With this attitude, you’ll start displaying resilience in some way in your work. Building a robust system takes time and work, and the key is to start small and keep going.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7265e1ff3682" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Realtime sync k8s pod with Okteto]]></title>
            <link>https://ujwaldhakal.medium.com/realtime-sync-k8s-pod-with-okteto-31aed432e913?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/31aed432e913</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[okteto]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 18:01:13 GMT</pubDate>
            <atom:updated>2022-07-04T18:01:13.844Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wonder if there are feedback loop cycle that is shorter while working with kubernetes. What if you could sync k8s pod in real-time with <a href="https://www.okteto.com/">Okteto</a>?.</p><p>While working with the k8s system the feedback loop cycle is quite long. I mean if we want to update our code hosted on k8s. The common way to get this done is either we can deploy the code to the desired server or we can directly ssh into the k8s pod and execute some commands. Both ways are not that efficient.</p><h3>Syncing local code</h3><p>In this tutorial, I will show you how to sync code with Okteto in action.</p><p>Okteto is a tool that helps to sync your code with the local/remote k8s server. This is an open-source tool &amp; they have a premium cloud solution for the hosting k8s app.</p><p>For this tutorial, I assume you have an up-and running k8s server running &amp; you are able to access it from your local terminal.</p><ol><li>Install Okteto on your local machine.</li><li>Go to the root of your project and initialize an okteto.xml file. The content looks like this for me. Since I am working with PHP the configuration looks somewhat similar regardless of the language you work with.</li></ol><pre>name: api<br>namespace: &quot;staging-namespace&quot;<br>command: &quot;php-fpm&quot;<br>context: &quot;staging-server&quot;<br>container: php<br>sync:<br>  - .:/var/www/html<br>  - $HOME/.composer:/root/.composer<br>persistentVolume:<br>  enabled: <em>false</em></pre><p>It says that I want to connect the k8s namespace with the name “staging-namespace” and context : “staging-server”. As soon as I connect to the cluster I want to sync the PHP container &amp; use “php-fpm command”. We have also specified the path of the file that we want to sync this means we want to sync all the things that are happening inside a current folder with the one that is hosted inside k8s.</p><p>Now, as soon as you make any changes inside your file the changes will be synced with the correct container name, namespace &amp; context of k8s.</p><h4>Conclusion</h4><p>Okteto is not the only tool that is capable of doing this there are lot more tools that do similar things as Okteto does. But the main purpose here is to make the feedback loop shorter by syncing code to a remote server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31aed432e913" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manage Multiple Cron with Helm Flow Control]]></title>
            <link>https://ujwaldhakal.medium.com/manage-multiple-cron-with-helm-flow-control-e6a7bb58860b?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a7bb58860b</guid>
            <category><![CDATA[cron]]></category>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 12:00:59 GMT</pubDate>
            <atom:updated>2022-04-04T12:00:59.458Z</atom:updated>
            <content:encoded><![CDATA[<p>If you want to set up a <a href="https://www.hivelocity.net/kb/what-is-cron-job/">Cron</a> on your application, using a cron in Kubernetes is straightforward. All you need to do is copy the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/">CronJob template</a>.</p><p>If you have one cronjob then it won&#39;t matter much but if you have many cronjobs then creating each file per cron can be not fun sometimes.</p><p><a href="https://helm.sh/">Helm</a> has <a href="https://helm.sh/docs/chart_template_guide/control_structures/">Flow Control </a>which can be used to manipulate dynamic values in the template.</p><p>In this article, we will create a single cron and then we will loop through the collections of cronjob commands to create multiple cronjob resource.</p><h4>Creating a single CronJob:</h4><p>Create a cronjob by copying the following code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88251474949fa526580a1d56e62880fa/href">https://medium.com/media/88251474949fa526580a1d56e62880fa/href</a></iframe><p>The file above creates a cron that runs every minute and prints some text.</p><h4>Creating multiple Cronjob Commands:</h4><p>Now let&#39;s create multiple cronjob commands which will hold all unique placeholders. We will now create a separate cronjob file that will hold the values i.e name, frequency, command etc of cron. Let&#39;s create a cronjobs.yaml inside .helm/values/cronjobs.yaml.</p><p>We will be creating four cronjobs which will have their own id, name, command, and schedule. But you can add more dynamic values if you want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2107ac99a30533e6f6db292d75f180f5/href">https://medium.com/media/2107ac99a30533e6f6db292d75f180f5/href</a></iframe><h4>Pass dynamic values to helm template:</h4><p>So far we have worked single cronjob then we created multiple cronjob commands. Now we want to loop those cronjobs commands inside the single cronjob so that we do not have to create multiple files manually.</p><p>There are multiple commands we can use in <a href="https://helm.sh/docs/chart_template_guide/control_structures/">Helm Flow Control</a>. For this we will use <em>{{- range $cronjob := $.Values.cronjobs }}</em> to loop over the values and access the dynamic values like {{$cronjob.id}},{{$cronjob.name}},{{$cronjob.schedule}} . As shown in the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07eca6a0e04cbddfff88faa1120983d0/href">https://medium.com/media/07eca6a0e04cbddfff88faa1120983d0/href</a></iframe><p>The final piece of the puzzle is to pass those dynamic values while installing/upgrading Helm. In order to do so, you can pass those values by using the — values keyword with the full path of that cronjobs command file i.e<em>.</em><em>helm/values/cronjobs.yaml. </em>The final command will look something like this:</p><pre>helm upgrade — install — values “.helm/values/cronjobs.yaml” multiple-cronjobs .helm</pre><h4>Conclusion:</h4><p>We set up multiple cronjobs using two files one for defining the specs of the whole Kubernetes cronjob and the next for defining the dynamic values i.e command, frequency, name, etc. You can build/manage complex configurations using the Helm Flow Control.</p><p>Github Link: <a href="https://github.com/ujwaldhakal/multiple-cronjob-helm">https://github.com/ujwaldhakal/multiple-cronjob-helm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a7bb58860b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Protobuf with Go?]]></title>
            <link>https://ujwaldhakal.medium.com/how-to-use-protobuf-on-go-5970f950dbc6?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5970f950dbc6</guid>
            <category><![CDATA[protobuf]]></category>
            <category><![CDATA[protocol-buffers]]></category>
            <category><![CDATA[proto]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[contracts]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 20 Dec 2021 20:48:36 GMT</pubDate>
            <atom:updated>2021-12-21T11:33:11.659Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Have you ever been in a situation where you do not know the structure of data that services are either consuming or publishing?</blockquote><p>Did you know that you have to write a schema only once which defines the structure data and the same schema can be used as validation before sending &amp; receiving data using <a href="https://developers.google.com/protocol-buffers">Protocol Buffers</a>?</p><p>In this tutorial, you will learn about using Protobuf. You will send &amp; receive a message asynchronously using Protobuf with <a href="https://www.rabbitmq.com/">RabbitMQ</a>.</p><h3>Table Of Contents</h3><ul><li>Prerequisites</li><li>Protobuf</li><li>Bootstrapping Project</li><li>Creating Protobuf Messages</li><li>Publishing a Message</li><li>Consuming a Message</li><li>Conclusion</li></ul><h3>Prerequisites</h3><p>This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:</p><ul><li>You have running <a href="https://docs.docker.com/compose/">Docker Composer</a> in your machine.</li><li>You have a basic understanding of <a href="https://www.docker.com/">Docker</a>, <a href="https://go.dev/">GO</a>, <a href="https://www.rabbitmq.com/">Rabbitmq</a>.</li></ul><h3>Protobuf</h3><p>Protobufs are the Messaging Contracts. They are schema that describes the structure of the message. These files are written in .proto extension which is language-neutral i.e write once &amp; use anywhere. Proto Messages are the structured schema that is inside .proto files</p><p>You will write Proto Messages and with the compiler called <a href="https://grpc.io/docs/protoc-installation/">Proto Compiler</a>, you can generate the code which will have a way to serialize &amp; deserialize data into that format.</p><p>There are many benefits of using Messaging Contracts like Protobuf :</p><ol><li>With these Proto Messages, you will know what type of data you are sending &amp; receiving</li><li>Serves as a documentation</li><li>Supports validation for serializing &amp; deserializing</li><li>Proto messages are language-neutral and it supports various programming languages which means you can publish messages from Go &amp; start consuming them from Php / Node etc</li></ol><h3>Bootstrapping Project</h3><p>For creating a new test project follow the steps below:</p><ul><li>Copy Dockerfile &amp; docker-compose.yaml from <a href="https://github.com/ujwaldhakal/golang-protobuf">this repository</a> which will dockerized Go source code, Proto compiler &amp; RabbitMQ</li><li>Create a file publish.go where you will write some code to publish events</li><li>Create a file consume.go where you will write some code to consume events</li></ul><h3>Creating Protobuf Messages</h3><p>In an application, while you sending messages you will serialize data using the definition from Proto Messages. And when consuming messages you will deserialize them using the same Proto Messages. Let&#39;s create a Proto Message so your services can use them to send and receive messages.</p><ol><li>Create a folder messages and inside that folder create a file called user_registered.go</li><li>Inside user_registered.go copy the following codes. Let&#39;s understand the code</li></ol><ul><li>syntax defines which proto version you are going to use</li><li>go_package defines the path where all your generated Protobuf code will be into</li><li>`import “validate/validate.proto”; it is importing the validator so that you can validate message using various rules without writing it by yourself</li><li>All message starts with a message keyword followed by name of the message. Inside the block, you can write key-value pairs where the key defines name &amp; type &amp; the value defines its order &amp; rules if there are any. In our case, you are defining the first field userId which is an integer and should be greater than 0 and the next is an email which is a string and should not be empty.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a78965058736d6bb9ce0181dc32d64c/href">https://medium.com/media/4a78965058736d6bb9ce0181dc32d64c/href</a></iframe><p>3. Run make build-proto on your project root. This command will generate two files user_registered.pb.go and user_registered.pb.validate.go that define type &amp; includes all the validation logic that you specified on the text which you can later use on your code while serializing &amp; deserializing.</p><h3>Publishing a Message</h3><p>As you have successfully created a Proto Message. Let&#39;s use the same auto-generated code while sending messages to other services for this you need to write a way to publish messages. Follow the following steps:</p><ol><li>Create a directory pkg and a file rabbitmq.go inside pkg dir where you will make a connection with RabbitMQ. The following code the function getConnection is importing library and making a connection with RabbitMQ server and upon error function failOnError is terminating the application with an error.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2194d9c04950ae226577c17da49ae1e0/href">https://medium.com/media/2194d9c04950ae226577c17da49ae1e0/href</a></iframe><p>2. After successfully making a connection, write a function that will publish a message to RabbitMQ. The following code accepts queueName and payload as a message which will write a message to default exchange to JSON format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77c8ca1357d1b3d44ce272189ca16a7c/href">https://medium.com/media/77c8ca1357d1b3d44ce272189ca16a7c/href</a></iframe><p>3. Create publish.go which will import publish function from rabbitmq.go to send data. The following code is using a struct that was generated by the proto using the proto compiler and it is encoding them into JSON after that it is calling to publish the function that you created earlier to send data to UserRegisteredqueue.</p><p>Try running make publish to verify that your code is actually working if you see Data has been published the output that means you were successful in publishing a message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a93d04fab9e86af9ba400f58361f90f4/href">https://medium.com/media/a93d04fab9e86af9ba400f58361f90f4/href</a></iframe><h3>Consuming a Message</h3><p>Until now you defined a photo message then you created a rabbitmq.go to create a way to publish messages &amp; you used the same function publish.go to publish messages to RabbitMq. Now let&#39;s consume the message that you published earlier.</p><ol><li>Inside rabbit. go add a function that will help in consuming a message. The following code makes a connection to RabbitMq &amp; returns a channel that you can leverage to listen to incoming messages.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ae45f7a5d180d8f31215e12df2bfd92/href">https://medium.com/media/0ae45f7a5d180d8f31215e12df2bfd92/href</a></iframe><p>2. Inside consume.go listen to all the messages and then print them. Let&#39;s understand the following code :</p><ul><li>The main function is listening to message by creating a consuming client. While deserializing message it is importing UserRegistered struct from the auto-generated code to define the type of data. There might be cases where the producer might send invalid data due to various reasons so it is better to validate that data you are consuming are as per the contracts that you specified.</li><li>validateMessage accepts the JSON data and tries to validate as per the user_registered.proto definition and if the data breaks any validation rules it will throw a validation error</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/739310b3a17a7640ee5989266cf57ea1/href">https://medium.com/media/739310b3a17a7640ee5989266cf57ea1/href</a></iframe><h3>Conclusion</h3><p>Throughout this tutorial, you have learned Protobuf &amp; how to use them with GO &amp; RabbitMQ.</p><p>Protobuf is one of the ways to implement Messaging Contracts there are more options like <a href="https://docs.pact.io/">Pact</a>, <a href="https://www.asyncapi.com/">AsyncApi</a></p><p>Now with this knowledge, you can use Protobuf on any programming language to send &amp; receive the data. You have also learned that it was easier to predict the data that you are consuming or publishing.</p><p>Let me know if you have any comments /suggestions/feedback.</p><p>Source code: <a href="https://github.com/ujwaldhakal/golang-protobuf">https://github.com/ujwaldhakal/golang-protobuf</a><br>Ref: <a href="https://stackshare.io/protobuf">https://stackshare.io/protobuf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5970f950dbc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a simple automated deployment pipeline for Cloud Run (Step by step tutorial)]]></title>
            <link>https://ujwaldhakal.medium.com/build-a-simple-automated-deployment-pipeline-for-cloud-run-step-by-step-tutorial-528ff7964e7?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/528ff7964e7</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 03 May 2021 15:40:14 GMT</pubDate>
            <atom:updated>2021-05-05T02:56:33.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Automating the deployment pipeline is always a challenging thing. It requires a lot of effort in setting up the server for multiple environments, preparing the build, and deploying the same build into the server.</p><p>We will go step by on configuring simple deployment pipelines so you could build furthermore from that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*OlMfSybcMWDvVMeW_aMX6A.jpeg" /></figure><h3>Intro</h3><p>In this post, I am going to show you how easily one can make a deployment pipeline for their next app by just copying down the source code. We will be using a simple NodeJs Dockerized application to be hosted on Cloud Run. By the end of this read, you will be able to make a deployment for any language.</p><p>In this tutorial, we will be using the following stacks -:</p><ul><li><a href="https://cloud.google.com/container-registry">Container Registry</a> -: It will store all Docker Images to be used in Cloud Run</li><li><a href="https://cloud.google.com/storage">Google Storage</a> -: It will save our state of Terraform.</li><li><a href="https://cloud.google.com/run">Cloud Run</a> -: Serverless platform where our final app will be hosted</li><li><a href="https://www.terraform.io/">Terraform</a> -: It will help us to spin up Cloud Run instance and to create multiple working environments like staging and production</li><li><a href="https://golang.org/">Go</a> -: It will help us to trigger Terraform command whenever we want to with Github Actions</li><li><a href="https://docs.github.com/en/actions">Github Actions</a> -: It will help us as an entry point to trigger those Go command and Go will trigger terraform</li></ul><h3>Why Cloud Run, Go, and Terraform?</h3><h4>Cloud Run</h4><p>Cloud Run is a managed compute platform that enables you to run containers and Google Scales Containers as per the request and you pay per usage. The management of the infrastructure overhead is handled by Google itself so we can focus on building apps. Google has awesome doc at <a href="https://cloud.google.com/run">Cloud Run</a></p><h4>Go</h4><p>Go is a very popular programming language these days due to its fast, reliable, and simple architecture. With Go, we can generate binaries that will execute without installing anything so this feature is pretty handy while working with OS</p><h4>Terraform</h4><p>Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. So with Terraform, we can build the infrastructure like we build an app with Code i.e <strong>Infrastructure as Code</strong>.</p><h3>Assumptions</h3><ol><li>You are familiar with how Go works</li><li>You are familiar with how Cloud Run works i.e specifying container image. If not check this article <a href="https://ujwaldhakal.medium.com/automate-cloud-run-deployment-in-a-minute-cb85e7db9f82">https://ujwaldhakal.medium.com/automate-cloud-run-deployment-in-a-minute-cb85e7db9f82</a></li><li>You are familiar with how Terraform spins up a new server and how Terraform manages state</li><li>You are familiar with Dockerizing the application.</li></ol><h3>Deployment tutorial steps</h3><p>We will be building deployment pipelines in the following four steps-:</p><h4>1. Dockerize application</h4><p>First, we will create an application and dockerize it. Let&#39;s create a index.js the file inside the src directory and create a hello world response.</p><p>index.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a6127b7c217b721caa47bd5e7564c36/href">https://medium.com/media/4a6127b7c217b721caa47bd5e7564c36/href</a></iframe><p>Now let&#39;s Dockerize it by adding Dockerfile. This is a simple Dockerfile where there is a multi-stage build and I have added as production it so that we could use the same Docker file for local and production. The same environment will be used while building the Docker image in the coming steps where we will build and push images to Google Container Registry.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/727b26c0aeeb7bbb456ec2bd2833e86d/href">https://medium.com/media/727b26c0aeeb7bbb456ec2bd2833e86d/href</a></iframe><h4>2. Infrastructure setup with Terraform</h4><p>First, we will write a terraform file where we will tell Terraform to spin up the Cloud Run instance. Let&#39;s create a GitHub project and create a folder cicd under which there are files need for terraform to create a cloud run instance with a given image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e96e21aa434c970984bacb09fe8665aa/href">https://medium.com/media/e96e21aa434c970984bacb09fe8665aa/href</a></iframe><p>and you only need to replace dev.tfvars and credentials/dev-cred.json with your actual credentials. We could actually test by running terraform apply for this to work you need an image in a Google Container Registry</p><pre>terraform apply -var image_tag=docker_image_tag -var-file=dev.tfvars -auto-approve</pre><p>Once we are able to push the Docker image to Container Registry then we are able to use this but we want to make it more simple and automated like what if we could deploy by running ./cicd/deploy dev master where dev is environment and master is the branch name in Git. Let&#39;s work on few files to achieve this</p><h4>3. Triggering Terraform with Go</h4><p>With Go, we can create binaries that will run without installing any further dependencies. Go will build a docker image and push it to the container registry if the image does not exist in the registry and trigger Terraform to deploy a new image to Cloud Run.</p><p>I am using <a href="https://github.com/ujwaldhakal/gcp-deployment-utils">https://github.com/ujwaldhakal/gcp-deployment-utils</a> this package for all utilities in this demo. Getting a commit hash of the current branch, logging into Container Registry, and Pushing images are all done by the <strong>go-gcp-docker-utils</strong> package.</p><p>If you look at <a href="https://github.com/ujwaldhakal/gcp-deployment-utils/blob/master/docker/docker.go#LC24">https://github.com/ujwaldhakal/gcp-deployment-utils/blob/master/docker/docker.go#LC24</a> this Build function closely there is the <a href="https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target"><strong>target</strong></a> being used in Docker File because oftentimes the way build will be different in production and local environment so make sure you use <a href="https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage---target"><strong>target</strong></a> in your docker file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df36b83b78cfd0ae0c805bb5077d13c8/href">https://medium.com/media/df36b83b78cfd0ae0c805bb5077d13c8/href</a></iframe><p>Inside function initTerraform</p><pre>cmd := exec.Command(“terraform”, “init”, “-backend-config”, “bucket=tf-test-app”)</pre><p><strong>tf-test-app</strong> is the name of our bucket which one has to create manually in cloud storage</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x1GFqi8HFWxd7Y3ZLG-hjQ.png" /></figure><p>This deployer.go generates a deployerbinary by running go build deployer.go . Deploy binary expects one parameter which is the name environment and it will prepare a service account JSON dev-cred.json ,dev.tfvarsand Github Commit Hash to be used on Terraform apply. After that, it will try to try to check whether the image we are trying to build already exists or not. If it already exists, it won’t build. If not, it will build and push. And finally, it will apply to terraform with given credentials.</p><blockquote>Since it will run inside GitHub action after checking out to the branch with given branch name with./cicd/deploy dev master .We will use the same commit hash to create tag in docker image and use the same image to deploy.</blockquote><blockquote>Note-: Make sure your IAM JSON has service to read bucket , create &amp; destroy cloud run , read and add container images to Google Container Registry</blockquote><p>If you want to modify anything you could just copy the same function from utils package and paste it in your actual project and start using your own instead of using the package</p><h4>4. Glue everything with Github Action and Bash file</h4><p>Finally, these two things will run inside Github Action Container upon manual command trigger i.e deploy dev master . As we have recently created deploybash inside cicdwhich will process our deploy dev master command and triggers <a href="https://docs.github.com/en/actions/reference/events-that-trigger-workflows">Github Repository Dispatch</a> which will trigger deploy.yml with payloads i.e name of environment and branch. Github Action will checkout to the branch given at deploy command and that will trigger deployer binary with environment name and as we already discussed how `deployer. go` handles the incoming request</p><p>In order to run this, you need to obtain a <a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">Github Personal Token</a> follow the <a href="https://medium.com/r?url=https%3A%2F%2Fdocs.github.com%2Fen%2Fgithub%2Fauthenticating-to-github%2Fcreating-a-personal-access-token">link</a> to get one, and put it inside the .env file. Usually, we don&#39;t track the .env file on git so for this purpose I am pushing it to Github</p><p>Once you trigger that command ./cicd/deploy dev master ,deploy file will trigger GitHub action deploy.ymlpass those dev and master arguments where the GitHub action will checkout to that given branch i.e master and pass the name of the environment to deployer.gobinaries. Once binaries know the commit hash and environment name it will load the necessary credentials and trigger terraform apply with a new image dash and it will take minutes to get reflected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rd0pkbqlnADJtZc5asFcug.png" /></figure><p>You will see a green checkmark next to the deploy text once your deployment is successful. You can find the link to action at <a href="https://github.com/rucaHQ/yorba-nodejs/actions">https://github.com/username/reponame/actions</a></p><h3>Add More Environments</h3><p>We have only seen setting up one environment i.e <strong>dev. </strong>But with more team members we will need more environment that could be production, staging,test1, test 2 based on your preference.</p><p>To add more environments is simple as just copying config files and editing them as most of the challenging part is already done i.e making up and running with one environment. Now we just need to create separate service account credentials by making a separate project from the same account on Google Cloud and make them accessible in <strong>deployer. go </strong>as we did for dev and production and you could add more environment either with an if-else pattern or just pass the dynamic variable to the environment name i.e ${environment}.tfvars and credentials/${environment}-cred.json.</p><blockquote>Note -: If we don&#39;t want to create multiple Google Cloud Projects to handle multiple environments then we can use <a href="https://www.terraform.io/docs/language/state/workspaces.html">Terraform State</a> to handle multiple environments with the same project.</blockquote><pre>func getTfVarFileName(env string) string {</pre><pre>if env == &quot;dev&quot; {</pre><pre>return &quot;dev.tfvars&quot;</pre><pre>}</pre><pre>if env == &quot;production&quot; {</pre><pre>return &quot;prof.tfvars&quot;</pre><pre>}</pre><pre>panic(&quot;Please select correct environment only dev &amp; production available at the moment&quot;)</pre><pre>}</pre><pre>func getCredentialsFilePath(env string) string {</pre><pre>if env == &quot;dev&quot; {</pre><pre>return &quot;credentials/dev-cred.json&quot;</pre><pre>}</pre><pre>if env == &quot;production&quot; {</pre><pre>return &quot;credentials/prod-cred.json&quot;</pre><pre>}</pre><pre>panic(&quot;error on loading credentials&quot;)</pre><pre>}</pre><p>This demo does not cover any DNS automation of adding a domain &amp; verifying in Cloud Run. Since there is no encryption done for exposed credentials, please do not use this approach in Public Repositories. Only use this on Private Repositories.</p><p>If you want to encrypt the credentials, You could use <a href="https://cloud.google.com/security-key-management?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=japac-AU-all-en-dr-bkws-all-all-trial-e-dr-1009882&amp;utm_content=text-ad-none-none-DEV_c-CRE_504965081181-ADGP_Hybrid%20%7C%20BKWS%20-%20EXA%20%7C%20Txt%20~%20Security%20and%20Identity%20~%20Cloud%20Key%20Management_Key%20Management%20Service-KWID_43700062030571198-kwd-283025365818&amp;userloc_9070016-network_g&amp;utm_term=KW_google%20key%20management%20service&amp;gclsrc=ds&amp;gclid=CKGf3-i2qvACFczH1AodFx8H2g">Google Kms</a> to encrypt with a key and decrypt with a key while using it to authenticate to Google Cloud.</p><h3>Conclusion</h3><p>This is just a basic idea of how to make CI/CD with minimal tools. With this approach, one can make CI/CD for normal application in a company, attach other google services in Terraform too like Cloud SQL, Redis, etc.</p><p>Special thanks and credits to <a href="https://medium.com/u/7896e01eaa28">Ujjwal Ojha</a> for helping me understand &amp; make CI/CD</p><p>Let me know your thoughts!</p><p>Source -: <a href="https://github.com/ujwaldhakal/cloud-run-cicd-boilerplate">https://github.com/ujwaldhakal/cloud-run-cicd-boilerplate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=528ff7964e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manage Dot Files (Config Files)]]></title>
            <link>https://ujwaldhakal.medium.com/manage-dot-files-config-files-f9365a755694?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9365a755694</guid>
            <category><![CDATA[dotfiles]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Sun, 28 Feb 2021 17:40:57 GMT</pubDate>
            <atom:updated>2021-06-09T15:14:28.290Z</atom:updated>
            <content:encoded><![CDATA[<h3>Easily Manage Dot Files (Config Files)</h3><p>Whenever I migrated from an old laptop to a new laptop or re-installed the whole OS, I always ended up copying all the config files(Ide configuration, bash history, app profiles, etc) in a hard disk.</p><p>I either ended up copying all un-necessary configs(by zipping all) from the home folder or if I pick particular configs, I keep on missing things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*zTgp1DNrspzhV86avJ5pPg.jpeg" /></figure><p>Even if I manage to zip all those things, storing them was another big challenge for me. Storing data comes with a cost as one would need to preserve it by storing locally or in any cloud. Updating the configs is even harder as I have to manually repeat all these steps.</p><p>So I started using Git to track my config files, so I created a Private Repo where I could push my all config files.</p><p>At first, I created a bash script with the name <strong>`sync. sh` </strong>inside directory <strong>dotfiles</strong></p><p>sync.sh</p><pre>#<br>#!/bin/bash<br>declare -a filesToSync=(&quot;.bashrc&quot; &quot;.bash_history&quot; &quot;.zshrc&quot; &quot;.zsh_history&quot; &quot;.gitignore_global&quot; &quot;.gitconfig&quot;)</pre><pre>## now loop through the above array<br>for i in &quot;${filesToSync[@]}&quot;<br>do<br>   cp ~/$i ~/dotfiles/$i<br>   # or do whatever with individual element of the array<br>done</pre><pre>declare -a foldersToSync=(&quot;.config/Terminator&quot;,&quot;.config/JetBrains&quot;) </pre><pre>## now loop through the above array<br>for i in &quot;${foldersToSync[@]}&quot;<br>do<br>  cp -r ~/$i ~/dotfiles<br>   ## or do whatever with individual element of the array<br>done</pre><p>So after running bash sync.sh the script would copy all my local config files and folders into the directory into the folder <strong>dotfiles.</strong></p><p>Now all I need to do is run git add . git commit -m “message” git push -u origin master these commands to push to my Git Repository.</p><p>Then I again wanted to automate the above manual process on a weekly basis, so I created a file inside the same <strong>dotfiles </strong>directory with the name</p><p>cronscript.sh</p><pre>#</pre><pre>#!/bin/bash</pre><pre>cd ~/dotfiles</pre><pre>bash syncfile.sh</pre><pre>git add .</pre><pre>git commit -m “weekly changes”</pre><pre>git push -u origin master -f </pre><p>Finally, I created a weekly Cron job with crontab -e</p><pre>0 0 * * 0 bash /home/ujwal/dotfiles/cronscript.sh</pre><h3><strong>Conclusion</strong></h3><blockquote>Every week my config files are getting synced automatically and i dont need to remember at all.</blockquote><p>There are other great tools for managing dotfiles that have many more features than the above script like <a href="https://github.com/jbernard/dotfiles">https://github.com/jbernard/dotfiles</a>. I simply made my own script as I could learn bash scripting side by side too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9365a755694" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[7 Easiest Ways To Introduce Technical Debts]]></title>
            <link>https://ujwaldhakal.medium.com/7-easiest-ways-to-introduce-technical-debts-cbe2fce340f1?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbe2fce340f1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[failure]]></category>
            <category><![CDATA[failure-stories]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 03 Aug 2020 15:30:38 GMT</pubDate>
            <atom:updated>2020-08-04T03:40:10.481Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Things that are left undone for making quality software due to various circumstances. Poor management, decisions making &amp; process are major factor behind it.</blockquote><p>It is just like a financial debt the longer you keep not paying your debts, worse and worse it gets.</p><p>So in this read, I will guide you how one can introduce “Technical Debt” effectively &amp; efficiently</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1s4jyQf13u-ABb0A" /></figure><p>Here are 7quickest ways to get the job done</p><ol><li><strong>Introduce multiple languages </strong>-:</li></ol><p>Since most of the company these days follow microservices already. Introduce multiple languages in your microservices so that it would be difficult for the company to hire newcomers as well as for the existing member to collaborate.</p><p>2. <strong>Don’t follow any coding principles</strong> -:</p><p>I repeat please do not follow any coding principles or try to violate the principles like <a href="https://www.makeuseof.com/tag/basic-programming-principles/">YAGNI, SOLID, KISS, DRY etc</a>. After some time in your project, you won’t be able to extend new features easily. It would take many days to get the job done if you could manage to get the job done, be ready for more and more bugs.</p><p>3. <strong>Do not refactor &amp; cover the test</strong> -:</p><p>Keep working on more features just don’t look back to refactor the code and do not write a single test for any functionalities. Eventually, you feel like your productivity has been decreased. This will help to introduce more bugs &amp; take more time to release features.</p><p>4. <strong>Do not document a single thing </strong>-:</p><p>Whether is a complex logic you have written or a complex app you have built just don’t share a single word in any written format. Act like you are the single source of truth. Let your company &amp; colleagues suffer to find the truth.</p><p>5.<strong> Do not monitor any projects</strong> -:</p><p>Let your projects grow wild into nature. Don’t put any logs &amp; analytics into your application so with this you won’t actually know where to refactor &amp; which features to work on next. If you are a company and planning to outsource new members just don’t analyze your team strength &amp; capabilities. Let the new member do their part and let them leave without any handover.</p><p>6. <strong>Use multiple cloud services provider -:</strong></p><p>Try to use many cloud service provider as you can. Try out new provider per project until you start feeling you have really made the worst decision. Your dependency will increase with multiple providers so that you would spend most of your time figuring out the things among providers.</p><p>7.<strong> Always rush -:</strong></p><p>If a feature takes 3 weeks to build. Try to build it within 1.5weeks with all shortcuts, hack fix you know and don’t refactor later on. This way the complexity of code will increase and increase so that you will feel difficult to work with that project i.e (taking a long time to push new features, more time to fix bugs, bugs mating with bugs &amp; more bugs)</p><p>Don’t take ownership of any work you do and don’t be responsible for any mistakes you made so that you won’t feel like there is a room for improvement. This way the fire can keep burning.</p><h3>Conclusion</h3><p>There are other indirect ways you could eventually introduce <strong>Technical Debt </strong>like demotivating your employees, mental burnout, lack of freedom, Micro-Management etc.</p><figure><img alt="Happy Burning" src="https://cdn-images-1.medium.com/max/480/0*GId8Q0Fj6okpG_VM.jpg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbe2fce340f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fast Prototyping  with Lighthouse Laravel]]></title>
            <link>https://ujwaldhakal.medium.com/fast-prototyping-with-lighthouse-laravel-86f4562ef3b9?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/86f4562ef3b9</guid>
            <category><![CDATA[lighthouse]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Fri, 24 Jul 2020 03:21:14 GMT</pubDate>
            <atom:updated>2020-07-24T03:21:14.682Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fast Prototyping with Lighthouse Laravel</h3><p><a href="https://laravel.com/">Laravel</a> is a full-fledged framework which is suitable for any kind of application from small, medium to large. And what so special about Laravel is the development process, they claim about rapid web development with it and there is no doubt.</p><p>What if I told, you can create an app a lot faster than before by using <a href="https://lighthouse-php.com/master/api-reference/directives.html#all">Lighthouse</a> on Laravel. <a href="https://lighthouse-php.com/master/api-reference/directives.html#all">Lighthouse</a> is a Graphql wrapper for Laravel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*516sp8efFuC8244h.jpg" /></figure><p>I have used this on a side project <a href="http://www.daani.life/">DAANI</a> API. <a href="https://daani.life/">DAANI</a> is a crowdsourcing app build on <a href="https://svelte.dev/">Svelte</a> &amp; <a href="https://laravel.com/">Laravel</a>, <a href="https://lighthouse-php.com/">Lighthouse</a>.</p><p>Building on Graphql was easy than the normal REST approach. Here are some points why I felt that this could speed up the development process -:</p><ul><li>Let&#39;s say if you want to create a record, just define a schema and action in the same line as this and it will create a model no need to create separate routes, controllers, requests for this.</li></ul><pre>type Mutation {<br>  createPost(title: String!): Post @create<br>}</pre><p>and if you want to read the data this could be simple as</p><pre>type Query {<br>  posts: [Post!]! @paginate<br>}</pre><blockquote>Note -: Mutation are for write part where (you would do update,create,delete)as Query are for read</blockquote><p>Most of the CRUD actions are handled with default <a href="https://lighthouse-php.com/master/api-reference/directives.html#all">Directives</a> provided by Lighthouse.</p><ul><li>Most of the time we spend time documenting the Apis. With Lighthouse they provide default Playground for testing your API along with the documentation of yours schemas.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smx1rgyXalIWb_YbTLdrtg.png" /></figure><ul><li>If you feel like you need a custom way around for your requirements. Extending is easy all you need to do is create a <a href="https://lighthouse-php.com/master/api-reference/resolvers.html#resolver-function-signature">Resolve</a>r i.e (mutation or query) it acts as a controller like we used to do.</li></ul><h3><strong>Conclusion</strong></h3><p>If you haven&#39;t worked with Graphql yet this could be a fun approach to know the Graphql mechanism. And if you have already tried it let me know your thoughts!</p><p>Happy Coding!</p><p><a href="https://github.com/ujwaldhakal/daani-api">Daani Source Code</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86f4562ef3b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Sapper on Google Cloud Run]]></title>
            <link>https://medium.com/hackernoon/deploy-sapper-on-google-cloud-run-1c21650fc06b?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c21650fc06b</guid>
            <category><![CDATA[sveltejs]]></category>
            <category><![CDATA[svelte]]></category>
            <category><![CDATA[sapper]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Sun, 17 May 2020 17:33:53 GMT</pubDate>
            <atom:updated>2020-05-17T17:44:51.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8rbENeM6VIecriTpMrpkQ.jpeg" /></figure><p><a href="https://svelte.dev/">Svelte</a> is the next cool thing for frontend if you don&#39;t believe me just try it out and feel the experience of developing web applications with minimal efforts.</p><p>So I have tried <a href="https://sapper.svelte.dev/">Sapper</a> which is built on top of Svelte with SSR (which is just like nuxt or next) support for my pet project. This blog post will be about how to deploy apps built with sapper on Google Cloud Run as I have faced issues while deploying.</p><p>This post assumes you are already familiar with <a href="https://sapper.svelte.dev/">Sapper</a>, <a href="https://cloud.google.com/run">Google Cloud Run</a>, <a href="https://github.com/features/actions">Github Actions</a>, and <a href="https://www.docker.com/">Docker</a>.</p><p>There are two ways of deploying the Sapper apps</p><ul><li><a href="https://sapper.svelte.dev/docs#Exporting">Exporting</a> -: By running npm export on the root, it will generate a bunch of static files and now upload those to any web server, link domain and it will run.</li><li><a href="https://sapper.svelte.dev/docs#Deployment">Running Server</a> -: By running npm run buildit will generate production build and then run npm run startwhich will start serving those build files you made. So we will be doing same thing on our Cloud Run and serve them. Here are some steps we will be doing -:</li></ul><ol><li><strong>Dockerization</strong> -: As we will deploying docker container so we need to dockerize our app so create a file called Dockerfile in root.</li></ol><pre><em># Use the official lightweight Node.js 12 image.</em></pre><pre><em># https://hub.docker.com/_/node</em></pre><pre><em>FROM</em> node:12-slim</pre><pre><em># Create and change to the app directory.</em></pre><pre><em>WORKDIR</em> /usr/src/app</pre><pre><em># Copy application dependency manifests to the container image.</em></pre><pre><em># A wildcard is used to ensure both package.json AND package-lock.json are copied.</em></pre><pre><em># Copying this separately prevents re-running npm install on every code change.</em></pre><pre><em>COPY</em> / ./</pre><pre><em># Install dependencies.</em></pre><pre><em>RUN</em> npm install</pre><pre># Compile to production</pre><pre><em>RUN</em> npm run build</pre><pre><em>EXPOSE</em> 8080</pre><pre><em># Run the web service on container startup.</em></pre><pre><em>CMD</em> [ &quot;npm&quot;, &quot;start&quot; ]</pre><p>It will set up an environment with node js pre-installed, set up your app, and serve with the desired port number.</p><p>2. Github Action &amp; Cloud Run Setup -: Create a folder inside root with the name .github and inside that create workflows and then create a YML file name deploy.yml(You can use any name but you should strictly follow the directory convention) with configs and now the path and content should look like .github/workflows/deploy.yml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e62674e41dbce6796e238953f854816/href">https://medium.com/media/4e62674e41dbce6796e238953f854816/href</a></iframe><p>It will log in to your Google account, build the image, and deploy it to the cloud run. Three variables are used on Github Secrets</p><p>GCLOUD_AUTH -: This should be a 64baseEncoded string of your JSON credentials. You can use base64 path/to/jsonFile it to convert to JSON on Linux. Ref <a href="https://cloud.google.com/docs/authentication/getting-started">https://cloud.google.com/docs/authentication/getting-started</a></p><p>GCLOUD_PROJECT_ID- : Project id of your Google Account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDnUZIAsCLXCrIUGMCd5bw.png" /></figure><p>CLOUD_RUN_SERVICE_NAME -: Create a cloud with the same name you have added on Github Secrets.</p><p>Make sure you have added your Github repo on Cloud</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2vYJ4Xsd2Nb3dnjdENBjg.png" /></figure><p>On every push, it will build the image and deploy code to the Cloud Run.</p><p>Link for Github repo -: <a href="https://github.com/ujwaldhakal/sapper-on-cloud-run">https://github.com/ujwaldhakal/sapper-on-cloud-run</a></p><p>Conclusion -:</p><p>In my opinion, I found out working with Svelte easy, comparing to React and Angular which I have worked with. Just give it a try for your next pet projects.</p><p>Keep Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c21650fc06b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/deploy-sapper-on-google-cloud-run-1c21650fc06b">Deploy Sapper on Google Cloud Run</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why do we microservice?]]></title>
            <link>https://medium.com/hackernoon/why-do-we-microservice-18abeca240b6?source=rss-c5a8eaa9345a------2</link>
            <guid isPermaLink="false">https://medium.com/p/18abeca240b6</guid>
            <category><![CDATA[monolith]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[ujwal dhakal]]></dc:creator>
            <pubDate>Mon, 17 Feb 2020 18:44:35 GMT</pubDate>
            <atom:updated>2020-02-17T18:44:35.848Z</atom:updated>
            <content:encoded><![CDATA[<p>Well Microservice word itself explains micro + service which is the breaking down of services into individual independent one. It&#39;s an architectural pattern on designing the system and its flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00Z-XBAFDiVKkr3M4xTwaA.png" /></figure><p>But why do we need to microservice? Well let me explain with an example</p><p>Let&#39;s say someone wants to build an eCommerce application for a single country with no shipping. Initially, he wants to launch eCommerce store with limited 100+ products only with, stripe &amp; cash on delivery payment method. He wants to build an eCommerce app so fast with less money &amp; time so that he wants to know whether this business idea is going to work or not.</p><p>Note that resources are limited Time, Money, Quality. If you focus on quality you need more money and time. If you want to finish in less time with less money, the quality will be less.</p><p>After 1 month of hard-working eCommerce, the app was ready where people could buy listed products with limited payment gateway for a single country. The developer has made an application keeping in mind that the site will only handle 1000 users per second or less than 1000 users since the owner wanted to build his MVP so fast. Now the eCommerce seems booming, each and every people are loving this idea and using in their daily life. Now more people using means more traffic means your limited computing resource has to serve many people now. As this business is booming now the owner wants to build further, he wants to make it global with a variety of payment gateways, shipping, inventory management to work on. As the traffic starts to increases-:</p><ol><li>The site seems extremely slow people had to wait for more time to choose products.</li><li>Adding a new payment gateway, shipping method etc was taking so much time.</li><li>A bug in one feature was taking a whole system down which was reported by the customer.</li><li>Deploying was taking so much time than it used to.</li><li>The server was from the US region and people from Asia are facing some latency issues.</li><li>Since they were using PHP everywhere and they wanted to use languages like go, the node for concurrency, parallelism for more efficient computation. But it was difficult for them to implement a new stack.</li></ol><p>Now he wants his tech team to solve these problems and tech team has one thing in mind, an idea of restructuring them into microservices (Product listing service, payment service, order processing service, inventory management service, Automation testing service, etc) and after they have successfully implemented microservices</p><ol><li>Scaling site was easy for them they could rewrite site into the latest stack.</li><li>Adding a new payment gateway, shipping method, features was easy for them as code base was splitted it was easy for multiple developers to work autonomously.</li><li>Now a downtime of one service won&#39;t affect the downtime of others</li><li>Deploying was so much easier for them as they had used Kubernetes/ EKS and they could easily deploy/revert specific services they have worked on</li><li>Due to their flexibility, they were able to implement dedicated DevOps for multi-region network serve and they have been implementing Kubernetes and scaling their services according to traffic.</li><li>Now their frontend relies on on react js, whereas they have been using PHP for some for product listed &amp; checkout. Where was order processing was done by Golang leveraging concurrency and they have been using cypress for UI Automation</li></ol><p>Like everything comes off with tradeoff surely microservice is no different it has its own tradeoffs like the specialized team to handle multiple services, hard to trace / monitor, hard to maintain consistency, etc which I will describe in a future post. So decide which one will you really need. Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18abeca240b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/why-do-we-microservice-18abeca240b6">Why do we microservice?</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>