<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Billy Kong</title>
    <description>The latest articles on Forem by Billy Kong (@billykong).</description>
    <link>https://forem.com/billykong</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F408578%2F14e207ff-ea1c-4788-9654-e9a8ea4c9062.png</url>
      <title>Forem: Billy Kong</title>
      <link>https://forem.com/billykong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/billykong"/>
    <language>en</language>
    <item>
      <title>What is libv8 and Why its Installation Fails</title>
      <dc:creator>Billy Kong</dc:creator>
      <pubDate>Sun, 14 Jun 2020 05:38:09 +0000</pubDate>
      <link>https://forem.com/billykong/what-is-libv8-and-why-its-installation-fails-1k6n</link>
      <guid>https://forem.com/billykong/what-is-libv8-and-why-its-installation-fails-1k6n</guid>
      <description>&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;When I cloned a project and tried to run &lt;code&gt;bundle install&lt;/code&gt;, I receive the error&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR: Failed to build gem native extension.
...
fatal error: 'climits' file not found #include &amp;lt;climits&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The error is raised when &lt;code&gt;bundler&lt;/code&gt; tries to require &lt;code&gt;libv8&lt;/code&gt;, which is in turn required by &lt;code&gt;therubyracer&lt;/code&gt;.   &lt;/p&gt;

&lt;p&gt;If you are reading this article, I believe I can assume that you are having a similar problem. I am going to share my findings here.&lt;/p&gt;

&lt;h3&gt;
  
  
  In this blog, we will try to answer the following questions:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
Why do we need &lt;code&gt;libv8&lt;/code&gt;?

&lt;ul&gt;
&lt;li&gt;a. How is it related to &lt;code&gt;therubyracer&lt;/code&gt;?
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Why does installation through &lt;code&gt;bundle install&lt;/code&gt; fails?&lt;/li&gt;
&lt;li&gt;How do we fix it?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Why do we need &lt;code&gt;libv8&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Before we talk about &lt;code&gt;libv8&lt;/code&gt;, let's first take a look what is &lt;a href="https://v8.dev/"&gt;V8&lt;/a&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, basically, V8 is the Javascript engine in Chrome. And &lt;code&gt;libv8&lt;/code&gt; is the ruby interface for the V8 engine used by &lt;code&gt;therubyracer&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  How is it related to &lt;code&gt;therubyracer&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;therubyracer&lt;/code&gt; gem &lt;a href="https://github.com/rubyjs/therubyracer"&gt;embeds the V8 Javascript Interpreter into ruby&lt;/a&gt;. With it, we can call Javascript functions or use Javascript objects directly in ruby runtime.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does installation through &lt;code&gt;bundle install&lt;/code&gt; fails?
&lt;/h3&gt;

&lt;p&gt;The installation failed as &lt;code&gt;therubyracer&lt;/code&gt; gem calls the &lt;code&gt;libv8&lt;/code&gt; gem, and it fails to build a native extension, i.e. &lt;code&gt;v8&lt;/code&gt;. I am able to repeat the same bug with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;therubyracer
Building native extensions. This could take a &lt;span class="k"&gt;while&lt;/span&gt;...
ERROR:  Error installing therubyracer:
    ERROR: Failed to build gem native extension.

    current directory: /Users/billykong/.rvm/gems/ruby-2.6.5/gems/libv8-3.16.14.19/ext/libv8
...
Compiling v8 &lt;span class="k"&gt;for &lt;/span&gt;x64
Using python 2.7.16
Using compiler: c++ &lt;span class="o"&gt;(&lt;/span&gt;clang version 11.0.0&lt;span class="o"&gt;)&lt;/span&gt;
Unable to find a compiler officially supported by v8.
It is recommended to use GCC v4.4 or higher
Beginning compilation. This will take some time.
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The error in your case may be different but still there is one interesting finding here. &lt;strong&gt;The &lt;code&gt;therubyracer&lt;/code&gt; gem installation script is trying to compile &lt;code&gt;v8&lt;/code&gt; from source!&lt;/strong&gt; I am not saying it is impossible, but I got a feeling that the compilation is the cause of issues for many of us. Just the first few posts I found when I google "libv8 error":    &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/19673714/error-installing-libv8-error-failed-to-build-gem-native-extension"&gt;https://stackoverflow.com/questions/19673714/error-installing-libv8-error-failed-to-build-gem-native-extension&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/simonqian/f67c862d06c94fe315d0ba97b711571f"&gt;https://gist.github.com/simonqian/f67c862d06c94fe315d0ba97b711571f&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/19577759/installing-libv8-gem-on-os-x-10-9?noredirect=1&amp;amp;lq=1"&gt;https://stackoverflow.com/questions/19577759/installing-libv8-gem-on-os-x-10-9?noredirect=1&amp;amp;lq=1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Compiling something requires all the dependencies to be present. Since &lt;code&gt;v8&lt;/code&gt; is written in C++ and probably many of us don't have a C++ development environment setup ready for use. Perhaps it is easier just to download a suitable binary of v8 instead of building it from source.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do we fix it?
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Install v8 ourselves&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;v8-315
&lt;span class="c"&gt;# 2. Install libv8 using the v8 binary we just installed&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;libv8 &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="s1"&gt;'3.16.14.19'&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--with-system-v8&lt;/span&gt;
&lt;span class="c"&gt;# 3. Install therubyracer using the v8 binary we just installed&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;therubyracer &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--with-v8-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/opt/v8@315
&lt;span class="c"&gt;# 4. Install the remaining dependencies&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;bundle &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: The &lt;code&gt;--&lt;/code&gt; before the &lt;code&gt;--with-system-v8&lt;/code&gt; and &lt;code&gt;--with-v8-dir=/usr/local/opt/v8@315&lt;/code&gt; is necessary when we supply library paths for native extensions, i.e. using specified libraries/binaries instead of building them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;therubyracer&lt;/code&gt; or some other gems may requires native extensions to function properly. While some tries to build the extension from source code, it often fails because the dependencies required by the native extensions are not readily installed. We may solve the issues by supplying our own binaries.  &lt;/p&gt;

&lt;p&gt;Hope that you have find the information useful. If you find any error or mistake in the above content, please do feel free to leave a comment below.&lt;/p&gt;

&lt;p&gt;This blog is also published in &lt;a href="https://billykong.github.io/ruby/2020/03/17/fixing-libv8-in-osx-catalina.html"&gt;billykong.github.io&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://v8.dev/docs"&gt;https://v8.dev/docs&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rubyjs/li%20bv8"&gt;https://github.com/rubyjs/libv8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rubyjs/therubyracer"&gt;https://github.com/rubyjs/therubyracer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca"&gt;https://gist.github.com/fernandoaleman/868b64cd60ab2d51ab24e7bf384da1ca&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guides.rubygems.org/command-reference/"&gt;https://guides.rubygems.org/command-reference/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/19673714/error-installing-libv8-error-failed-to-build-gem-native-extension"&gt;https://stackoverflow.com/questions/19673714/error-installing-libv8-error-failed-to-build-gem-native-extension&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gist.github.com/simonqian/f67c862d06c94fe315d0ba97b711571f"&gt;https://gist.github.com/simonqian/f67c862d06c94fe315d0ba97b711571f&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/19577759/installing-libv8-gem-on-os-x-10-9?noredirect=1&amp;amp;lq=1"&gt;https://stackoverflow.com/questions/19577759/installing-libv8-gem-on-os-x-10-9?noredirect=1&amp;amp;lq=1&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>bundler</category>
      <category>libv8</category>
    </item>
    <item>
      <title>Remote Team Git-based Communication</title>
      <dc:creator>Billy Kong</dc:creator>
      <pubDate>Sun, 14 Jun 2020 05:33:25 +0000</pubDate>
      <link>https://forem.com/billykong/remote-team-git-based-communication-3ccb</link>
      <guid>https://forem.com/billykong/remote-team-git-based-communication-3ccb</guid>
      <description>&lt;h3&gt;
  
  
  Motivation
&lt;/h3&gt;

&lt;p&gt;The COVID-19 pandemic has brought many changes to our lives, one of them being many people are working from home now. It is not necessarily a hinterance of communication, but we do need to adapt. Many things that used to be communicated verbally, needs to be communicated textually.&lt;/p&gt;

&lt;p&gt;We have switched to remote working since January 2020. During the time, we have natually developed a git-based communication workflow. If you are working in the software industry, you will see that it is not unlike the pull request workflow most of us used for source code. The precise and asynchronous communication model for source code works just as well for software design, schedule planning, and team administration discussion.&lt;/p&gt;

&lt;p&gt;So far the efficiency is even better than before COVID-19 in addition of better transparency. I would like to share our approach here with some details. For anyone who may be looking for a way to build and run a remote team, I hope this is useful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;We call our way &lt;strong&gt;document-based communication&lt;/strong&gt;(or git-based communication). It is inspired by the handbook-based communication shared by &lt;a href="https://gitlab.com"&gt;GitLab&lt;/a&gt;. Since our team is much smaller, 4 developers only, our handbook is much simpler.  &lt;/p&gt;

&lt;p&gt;The handbook is a git repository of markdown files organised into directories. Really, not much difference with your local drive or share drive. But using &lt;code&gt;git&lt;/code&gt; helps to iterate ideas much faster. Here is the overall directory strcuture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.
|--engineering-team
|  |--README.md
|  |--merge-request-flow.md
|  `--recruitment-process.md
|--features
|  |--README.md
|  |--feature-1.md
|  `--feature-2.md
|--technical-documentation
|  |--README.md
|  |--investigations
|  |  |--2020-04-01-dummy-issue-1-investigation-report.md
|  |  `--2020-05-20-dummy-issue-2-investigation-report.md
|  |--architecture-diagram.md
|  `--analytics-etl.md
`--README.md
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  What kind of document is needed for the day-to-day operations?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Team SOP guidelines

&lt;ul&gt;
&lt;li&gt;This directory holds the day-to-day workflow descriptions.&lt;/li&gt;
&lt;li&gt;E.g. merge-request-flow.md

&lt;ul&gt;
&lt;li&gt;Simple description of how to do merge request/pull request since not all teammates may be familiar with open source software workflow&lt;/li&gt;
&lt;li&gt;Define who should be assigned reviewers and criteria for a review to pass&lt;/li&gt;
&lt;li&gt;Define who is responsible for merging and what to do it there is code conflict&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Once written, contents in this directory rarely changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Features

&lt;ul&gt;
&lt;li&gt;This directory holds all the new features or features updates requirements&lt;/li&gt;
&lt;li&gt;If your team has the wonderful practice of writing design doc, here is where it should be kept.&lt;/li&gt;
&lt;li&gt;For our case, we put the followings guidelines in &lt;code&gt;/features/README.md&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;What should be included in a feature doc?

&lt;ul&gt;
&lt;li&gt;textual description of user flow with links to graphic assets&lt;/li&gt;
&lt;li&gt;technical design description&lt;/li&gt;
&lt;li&gt;contentious points&lt;/li&gt;
&lt;li&gt;estimation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If your features is complicated, feel free to open subfolders inside &lt;code&gt;features/&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Technical notes

&lt;ul&gt;
&lt;li&gt;This directory is for long-term documentations and technical knowledge sharing, a bit like a wiki or knowledge base.&lt;/li&gt;
&lt;li&gt;When our teammates consider certain new tech to be added to our services, we require each other to write down what we have: read, opinions, and experience on trying out things here, such that we can learn from each other more easily, and we can monitor the quality of "research" tasks so management can be more comfortable assigning such tasks.&lt;/li&gt;
&lt;li&gt;The output is very similar to blogs such as this one.&lt;/li&gt;
&lt;li&gt;We have an &lt;code&gt;investigation&lt;/code&gt; subfolder here as well

&lt;ul&gt;
&lt;li&gt;When there are tricky bugs or issues, we write down what happened and how we solve them.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why use &lt;code&gt;markdown&lt;/code&gt;?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Easy to write 

&lt;ul&gt;
&lt;li&gt;It takes 30sec to learn for generic document like this one, seriously.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Easy for source code control

&lt;ul&gt;
&lt;li&gt;It makes the merge/pull request flow possible as elaborated below.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;This blog is written in markdown, you can find the source &lt;a href="https://github.com/billykong/billykong.github.io"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to communicate?
&lt;/h3&gt;

&lt;p&gt;We use the &lt;a href="https://docs.gitlab.com/ee/user/project/merge_requests/"&gt;merge request flow&lt;/a&gt;. We didn't invent this workflow, it is the common practice used in open source softwares. If you are using &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt; it is the &lt;a href="https://guides.github.com/introduction/flow/"&gt;pull request flow&lt;/a&gt;. The similar flow is called merge request flow in &lt;a href="https://gitlab.com"&gt;GitLab&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Bascially, you do the followings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create new branch&lt;/li&gt;
&lt;li&gt;Make changes&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git push&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Create merge request in gitlab.com&lt;/li&gt;
&lt;li&gt;Assign reviewer(i.e. Assignee)&lt;/li&gt;
&lt;li&gt;Done! The reviewer will be notified and be able to comment on your request.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CJ4P6Ywd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jyrnd385i6aru7qgwwwd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CJ4P6Ywd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jyrnd385i6aru7qgwwwd.png" alt="feature merge request flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is gained?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Efficiency: for our team of 4, we have about 10 threads of communication per day, each is precisely scoped to a line in a document.&lt;/li&gt;
&lt;li&gt;Constructive disagreement: as teammates has more time to contemplate each comment before dashing it out. Here &lt;a href="https://www.webfx.com/tools/emoji-cheat-sheet/"&gt;emoji&lt;/a&gt; helps.&lt;/li&gt;
&lt;li&gt;Sunshine factor: as all comments are recorded and accessible to all teammates. It really encourage the best of behaviour from our experience.&lt;/li&gt;
&lt;li&gt;Async communication: teammates can check their notification periodically and continue discussion without losing context. And the developers are not interrupted neither! Big win here!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What needs to be changed?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Write it down instead of speak it out

&lt;ul&gt;
&lt;li&gt;Not everyone is comfortable with it on Day 1.&lt;/li&gt;
&lt;li&gt;It takes us about a week to get used to writing doc instead of Zoom calling or Slack chatting.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sending links of doc, along with some copy and paste

&lt;ul&gt;
&lt;li&gt;Other teams may still prefer more traditional email communication.&lt;/li&gt;
&lt;li&gt;No hard feeling. Just send them the link along with some content of the doc copy and pasted into the email. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Higher throughput, but more latency

&lt;ul&gt;
&lt;li&gt;The async nature of merge request flow means we won't get response as fast as tapping one's shoulder in office.&lt;/li&gt;
&lt;li&gt;But the upside is higher quality communication and easier to discuss mutliple things without getting the context mixed up. Communication threads in merge requests are precise to a single line.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;It is an efficient, impartial, system.&lt;br&gt;
It requires some technical capability, but really not much.&lt;br&gt;
You may encounter resistence, but even if you can only successfully promote it within your team. The benefit is still worths it.&lt;/p&gt;

&lt;p&gt;By the way, the &lt;a href="https://about.gitlab.com/handbook/"&gt;GitLab Handbook&lt;/a&gt; is really a valuable reference to how to run different departments of a software company there. I am so happy that they are able to condense their valuable experience into a single document and open source it.&lt;/p&gt;

&lt;p&gt;This blog is also published in &lt;a href="https://billykong.github.io/remote-team/2020/05/22/remote-team-document-based-communication.html"&gt;billykong.github.io&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://ben.balter.com/2012/10/19/we-ve-been-trained-to-make-paper/"&gt;We’ve been trained to make paper&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://about.gitlab.com/handbook/"&gt;GitLab Handbook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.webfx.com/tools/emoji-cheat-sheet/"&gt;Markdown Emoji&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/billykong/billykong.github.io"&gt;Source code of this blog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.gitlab.com/ee/user/project/merge_requests/"&gt;GitLab Merge Request Flow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guides.github.com/introduction/flow/"&gt;GitHub Pull Request Flow&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;



</description>
      <category>management</category>
      <category>git</category>
      <category>remote</category>
    </item>
    <item>
      <title>Deploying a Classic 3-tiers Application using aws-cdk</title>
      <dc:creator>Billy Kong</dc:creator>
      <pubDate>Sun, 14 Jun 2020 05:23:49 +0000</pubDate>
      <link>https://forem.com/billykong/deploying-a-classic-3-tiers-application-using-aws-cdk-3k30</link>
      <guid>https://forem.com/billykong/deploying-a-classic-3-tiers-application-using-aws-cdk-3k30</guid>
      <description>&lt;h3&gt;
  
  
  Background
&lt;/h3&gt;

&lt;p&gt;I have been looking for ways to adapt infrastructure-as-code with my team. But the initial complexity is a big deterant. Remember we not only have to output the initial configuration, but to maintain it as well.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws-cdk&lt;/code&gt; is released on &lt;a href="https://aws.amazon.com/about-aws/whats-new/2019/07/the-aws-cloud-development-kit-aws-cdk-is-now-generally-available1/"&gt;2019-07-11&lt;/a&gt;.&lt;br&gt;
It is simpler than writing a CloudFromation template from scratch.&lt;br&gt;
Perhaps it is a good entry point for teams that want to adapt infrastructure-as-code.&lt;/p&gt;
&lt;h3&gt;
  
  
  A Classic 3-Tiers Application
&lt;/h3&gt;

&lt;p&gt;With load-balancer tier, stateless application logic tier, and database tier.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tier&lt;/th&gt;
&lt;th&gt;Componenet&lt;/th&gt;
&lt;th&gt;AWS Service&lt;/th&gt;
&lt;th&gt;Subnet&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Load-balancer&lt;/td&gt;
&lt;td&gt;AWS ELB&lt;/td&gt;
&lt;td&gt;Public&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Application Logic&lt;/td&gt;
&lt;td&gt;AWS ECS Fargate&lt;/td&gt;
&lt;td&gt;Private&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;AWS RDS Aurora&lt;/td&gt;
&lt;td&gt;Isolated&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Following the &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html#vpc-subnet-basics"&gt;security practice of separating subnets for different tiers&lt;/a&gt;, the application will be deployed into:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a public subnet(with two-way Internet access), &lt;/li&gt;
&lt;li&gt;a private subnet(with out-going Internet access only), and &lt;/li&gt;
&lt;li&gt;a isolated subnet(no Internet access either way).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We are also using environment variable to pass database credentials as it is easier to reuse existing docker image.&lt;/p&gt;

&lt;p&gt;Here is the &lt;code&gt;aws-cdk&lt;/code&gt; stack that I managed to get working:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Deploy
&lt;/h3&gt;

&lt;p&gt;If you want to deploy it and poke around, you can checkout the &lt;a href="https://github.com/billykong/aws-cdk-fargate-rds-stack"&gt;GitHub repository here&lt;/a&gt;. The deployment instruction is written in &lt;code&gt;README.md&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;Note that we should install the &lt;strong&gt;same version&lt;/strong&gt; of &lt;code&gt;aws-cdk&lt;/code&gt; and other &lt;code&gt;@aws-cdk/*&lt;/code&gt; dependencies. It seems even minor version difference may be incompatible. I used &lt;code&gt;v1.38.0&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some Rooms for Improvements
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Use separate route tables for each subnet.&lt;/li&gt;
&lt;li&gt;Database security group should allow traffic from the private subnet only.&lt;/li&gt;
&lt;li&gt;Calling AWS Secret Manager API from application code for database credential is probably more secure, but it will require some custom code. If you expect to reuse the same Docker image in, say, Kubernetes, it may cause problems.&lt;/li&gt;
&lt;li&gt;I couldn't quite get the &lt;code&gt;DatabaseCluster&lt;/code&gt; construct to work. So I used the CloudFormation verions &lt;code&gt;CfnDBCluster&lt;/code&gt;. If you managed to use &lt;code&gt;DatabaseCluster&lt;/code&gt;, please feel free to leave a comment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This blog is also published in &lt;a href="https://billykong.github.io/devops/aws/2020/05/27/classic-3-tier-application-deployment-using-aws-cdk.html"&gt;billykong.github.io&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.html"&gt;AWS CDK API Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/cjjenkinson/how-to-create-an-aurora-serverless-rds-instance-on-aws-with-cdk-5bb0"&gt;How to create an Aurora serverless RDS instance on AWS with CDK&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/bind-almir/cdk-aurora-serverless/blob/master/lib/cdk-aurora-serverless-stack.ts"&gt;bind-almir/cdk-aurora-serverless&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Subnets.html#vpc-subnet-basics"&gt;AWS VPC Subnet Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/billykong/aws-cdk-fargate-rds-stack"&gt;Source Code of aws-cdk-fargate-rds-stack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/billykong/express-database-checker"&gt;Source Code for express-database-checker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/about-aws/whats-new/2019/07/the-aws-cloud-development-kit-aws-cdk-is-now-generally-available1/"&gt;aws-cdk is now generally available&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>typescript</category>
      <category>devops</category>
      <category>awscdk</category>
    </item>
  </channel>
</rss>
