<?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 Tran Quoc Viet on Medium]]></title>
        <description><![CDATA[Stories by Tran Quoc Viet on Medium]]></description>
        <link>https://medium.com/@tranquocviet?source=rss-819f2838692a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GBZ5y05EHSNdJlAs</url>
            <title>Stories by Tran Quoc Viet on Medium</title>
            <link>https://medium.com/@tranquocviet?source=rss-819f2838692a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:15:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tranquocviet/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[Hacking on the cloud: An effective and cost optimization approach]]></title>
            <link>https://medium.com/altitudehq/hacking-on-the-cloud-an-effective-and-cost-optimization-approach-8e5a943d1e6c?source=rss-819f2838692a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e5a943d1e6c</guid>
            <category><![CDATA[solution-architect]]></category>
            <category><![CDATA[cloud-system]]></category>
            <category><![CDATA[altitude]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Tran Quoc Viet]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 04:06:39 GMT</pubDate>
            <atom:updated>2022-02-07T04:06:39.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*xQfBMjSANDZcB_jEgrRqsQ.jpeg" /></figure><p>A few words before we start: this article isn’t about Hacking so you don’t have to worry about not having security-relate skills to continue reading. This article only take Recon and Scanning phases of Hacking, which usually very time consuming, as a model for the main subject: <em>Design an effectively Cloud Solution while keeping the cost optimized.</em></p><p>Also Hacking without permission is illegal. The only purpose of hacking is to secure networks, and think like a hacker to be able to secure networks.</p><p>In case you didn’t know, Altitude is a fully cloud integrated platform to simplify the process of building a smarter accommodation, and as we deal with both our partners and customers data, security is one of our fore most concerns. Here at Altitude we always remind ourselves this:</p><blockquote>A breached system is a dead system</blockquote><p>to keep remind ourselves of how much important our customer data is, as they put their trust into us, we must response in kind.</p><h3>Who am i?</h3><p>My name is Tran Quoc Viet, currently working as Technical Advisor at Altitude. Since Altitude most concern is the safety of its customer data, we have built a security team from the early day and i had the honor of being one of the team first members.</p><p>During the time with the team, i have developed a strong interest in Security, and since then have been working as ethical security hacker for Altitude and her partners during my spare time. My task is to look for vulnerabilities in our networks, and <strong>report it</strong>.</p><p>With all the security skillsets and tools built over the years , and as Altitude cloud solution architect, one day i decided to move all those tools into the cloud as my machine started to take <strong>weeks</strong> to finish its given task. My choice is of course <strong>AWS cloud services </strong>as Altitude also using this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*aAaruYL9YZ8rdMBfgyrIzg.gif" /><figcaption>AWS cloud services</figcaption></figure><h3>Problems with cloud base hacking tools</h3><p>My naive old self back then thought that the solution was simply to get some AWS EC2 instances, move my tools over (dockerized and ready to run anywhere) and call it a day. But reality isn’t that simple, my tools needs a lots of CPU and RAM, either one or both, so after finished my math, a few high tier EC2 instances were required, and even with reserved instances it costed me around 250$/month. And that was just the cost for EC2 instances only, so as poor as i were, i gave up on that solution.</p><blockquote>Cloud solution cost a lots if you don’t pay attention to what you use</blockquote><p>There was something else i noticed: the inconsistent usage. Below are the usage charts of Altitude and my tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TwZnyANeF9sOEaUqI1uTOw.png" /><figcaption>My Tools CPU utilization chart</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TIhA71O5qt3dzPsi4TwrcA.png" /><figcaption>Altitude CPU utilization chart</figcaption></figure><p>The problem is pretty obvious, Altitude is a huge system used by a lots of users across the world so it must have high availability and the usage always remain high. My tools, on other hand, mostly in idle state, except for when i run it again a target.</p><p>Noticed such different, i gave up on trying to imitate Altitude Cloud Structure, and instead design a completely different approach.</p><p>Before a cloud solution architect can design a solution, they must first understand the <strong>problem </strong>and<strong> </strong>the <strong>goal </strong>of the target system. That is what we will try to do in this section.</p><h3>The 5 steps of ethical hacking</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6jfFcuGBHLxOnBE07zQjTQ.jpeg" /><figcaption>5 steps of ethical hacking (credit: itperfection.com)</figcaption></figure><p>These are a lots of models for ethical hacking but the 5 steps model is probably one of the most popular. Since hacking isn’t our article main subject, let quickly go over all five.</p><p><strong>Reconnaissance</strong></p><p>In this phase hackers will try to gather information about the target, as many as they can. This is the most important phase out of all five.</p><blockquote>If you know the enemy and know yourself, you need not fear the result of a hundred battles.<br>-<strong>Sun Tzu-</strong></blockquote><p>The more information hacker can gather, the better change of success they have. There is no “too much information” for this phase, they will try to gather everything, no matter how trivial. I can list a few examples:</p><ul><li>IP ranges, information relate to IP such as whois</li><li>Domains, subdomains, domain owner information</li><li>Domain records such as A, TXT, CNAME, DKIM,…</li><li>Email, phone number, name, address, key words, …</li><li>TCP and UDP services</li><li>and a lots more</li></ul><p><strong>Scanning</strong></p><p>With the information gather during Reconnaissance phase, the hacker will scan the network for specific information. For example with the collected IPs, they can scan for open ports, vulnerabilities,… associate with said IPs.</p><p>From my experience, most of the scanning phase is all about running the scanning tools with the input from Reconnaissance phase. Of course to have good result, you must know to run which tools on which data. A good hacker also have their own or personal-tuned tools, which set them apart from the rest.</p><p>One important thing to note: Scanning phase usually take VERY LONG TIME, even after narrowing down the target surface.</p><blockquote>Scanning might take DAYS to finish</blockquote><p><strong>Gaining Access</strong></p><p>This phase is when the attack actually start. With all the information from Recon and Scanning phase, hacker will be able to draft an attack plan and excuse it.</p><p><strong>Maintaining Access</strong></p><p>Once successfully gained the access into network, hacker will want to keep that access for future exploitation and attacks. These can be so many ways, like creating a backdoor, or take over an Administration account inside the network, …</p><p><strong>Clearning Tracks</strong></p><p>Remove anything that might indicate that the network have been breached, or anything might lead back to the hacker. It might be logs, sent emails, files generated, bash history,…</p><h3>The goal: an automation hacking toolbox</h3><p>It was pretty fun at first, then i realize i pretty much repeated doing the same stuffs over and over with each new target, especially during the Recon and Scanning phases. So i decided to automate the process.</p><p>My aim is to build a cloud hacking toolbox which, after accept the target information, and my attacking scenario config as input, can automatically perform the Reconnaissance and Scanning phase using all my tools. The time consuming steps will be automatically ran, while i can go live my life until the notification come.</p><p>And that is the <strong>Goal</strong> we want to archive.</p><h3>The problems</h3><p>The inconsistent usage: i already mentioned this above so i wont go over it again. But the objective is cut the cloud cost when the toolbox is in idle state.</p><p>Long running process: some tools take hours, or even days to finish.</p><p>Highly customization: No hacker run all his tools again any target. He must pick which one to run depend on the target characteristic. For example it make no sense running WPScan again a non Wordpress target. The toolbox must be flexible to fit on any attacking plan. <br>And as a hacker continue with his work, he will employ more tools, so the process of adding new tool should also be easy.</p><h3>Design a solution</h3><p>Now with the Goal and Problem identified, time to get our hand dirty. The first task is to design the automation flow for the Recon and Scanning phases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kow_6whXd_QRmLCwtjICSA.png" /><figcaption>Automation recon + scanning flow</figcaption></figure><p>As two of our main problems are long running process and customization, a queue-base architecture is highly favor. Event-driven architect is also a very good option, but <strong>AWS Kafka</strong> price is too expensive for our project.</p><p>First let go over all the actors we see in the image first:</p><ul><li><strong>Command center</strong>: accept/log command from user, and generate the <strong>action stages</strong> for that command.</li><li><strong>Action stages</strong>: each stage represent a hacking action. For example, the recon phase consist of the following stages: scan for subdomains, probe sub domains,…. Each stage have its corresponding tool.</li><li><strong>Action queue</strong>: You can think of it as a message box, where you put in a message, and later someone will take out the message, read it and do what it said. ActiveMQ, RabbitMQ,… are a few popular examples.</li><li><strong>Artifact</strong>: a ZIP/RAR file contains all the files, documents, reports generated by a tool. Since some tools generate A LOTS of files, it is better to have a center storage for them, and i call it <strong>Artifact Storage.</strong></li><li><strong>Recon and Scan services</strong>: the recon and scan phases are actually consisted of many services, but to keep thing simple let assume they are just a single service.</li></ul><p>With the actors in place, our automation flow will be as follows:</p><ul><li>The hacker will trigger the flow by sending a command to <strong>command center</strong>.</li><li>The <strong>command center</strong> will generate the <strong>action stages</strong> , and then send the first one to <strong>action queue</strong>.</li><li>After a message are put into the queue, the recon and scan service will pick up the message, parse the message to get the stage information and use corresponding tools to process the stage action. After the tools finished its job, an <strong>artifact</strong> will be generated and upload to <strong>Artifact Storage</strong>.</li><li>Once the tool finish its task, the stage is consider done, and the service will inform the <strong>command center</strong>. The next <strong>action stage</strong> will be generated and put to queue, and be processed by recon and scan service. This will continue until the <strong>command center</strong> decided that there is no more <strong>action stage </strong>left.</li><li>Once all the action stages are finished, user will be notified via email/sms. Since the recon and scan usually take lots of time, a notification is required (you don’t want to check the status every few hours, do you?)</li></ul><p>This queue-base architecture help us resolves two of our problems:</p><ul><li>Long running process: by using queue-base solution, no service have to wait for a response from another. For example command center don’t have to open a processing thread to call <em>Nmap</em> service, then keep that thread open for 2 hours (or more) until <em>Nmap</em> finish its task. Instead command center simply drop a message into the queue, and call it a day until Nmap contact it later with the scan result. No more waste resource!</li><li>Highly customization: each action stage accept a Queue message as <em>input</em>, and product an Artifact as <em>output</em> , so there is almost no dependency between stages (except if the artifact will be used by another stage, but this is just a matter of order). This way you can easily add new action stage in the future without worrying it might break the flow.</li></ul><h3>Final problem: The inconsistent in usage</h3><p>If you ask 100 system architects how to deal with the inconsistent in usage, all of them will give you the same answer: <strong>scalability</strong> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKsF6B1lskVY_kyiRnDhUQ.png" /><figcaption>Sample of scalability</figcaption></figure><p>In short, it is the measure of a system’s ability to increase or decrease in performance and cost in response to changes in application and system processing.</p><p>Take Altitude as an example, during normal period, we have ten instances to host all our services. But during holiday period, the number of requests spikes, either 2 or 3 times more than normal. Thank to Altitude scalability ability, our system will automatically increase the number of instances to match the high demand without us have to do anything.</p><p>As for our toolbox, the different between low demand and high demand period are even more distinctive. Because when you don’t perform any hacking task, the system does almost nothing.</p><p>So how can we archive Scalability for our solution?</p><h4>Two categories of services</h4><p>The hard part of the Scalability is to select which target for the scaling. Thanks to the queue-base architecture we employed, it wont be too hard.</p><p>Our hacking toolbox consisted of many services, but in general, you can divide them into 2 categories:</p><ul><li>High processing services: tools which consume a lots of CPU and RAM, and took very long time to finish. For example: Nmap service which scan for working ports. Except for when these are tasks for them in Action Queue, they do absolutely nothing.</li><li>API-relate services: Command center, artifact storage and notification service belong to this category. They don’t require much resource, but should always in ready state, waiting for request from user or other services. These services should have short response time.</li></ul><p><strong>Our scalability strategy</strong></p><p>With our services perfectly divided like that, it is quite easy to decide a scalability strategy.</p><p>High processing services will be put into scalable instances, which will be boot up whenever there is a new task in the Job Queue, and terminate when there is no more task. Amazon have a perfect solution for this: <strong>AWS Auto Scaling</strong> service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*-jzH23UOLC5Mzt2q_WL78g.png" /><figcaption>Aws Auto Scaling</figcaption></figure><p>For API relate services, there are 2 options:</p><ul><li>Option 1: put them into EC2 instances which always in ready state. This approach allow the api to response quickly without delay, since there is no boot-up time required. But you will have to pay monthly fee for these instance. If the api are called frequently, this is the prefer option. But in our case it isn’t.</li><li>Option 2: Convert the API services into <strong>serverless</strong> services with <strong>AWS Serverless</strong>. The advantage of serverless services is that you only have to pay for what you use, in short, the cost depend on the number of requests you make that month. In our case the number of requests are quite low, so this is the approach that we will select. <strong>A side note</strong>: serverless services have a boot-up delay(change from terminated state to ready state) so it is a bit slower than the first approach, but in our case it isnt a problem.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSpka7p_co37fgcEBnnxow.png" /><figcaption>AWS Serverless Computing (Credit: Xenonstack)</figcaption></figure><p>And that is it folks, we have our solution to build the hacking toolbox. All that left is to design the Infrastructure , and that is what we will do next.</p><p>With the solution figured out, design the infrastructure is quite straight forward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSnHasTRl98bErnzqY-Rng.png" /><figcaption>The toolbox infrastructure</figcaption></figure><ul><li>A <strong>VPC</strong> with one private <strong>subnet</strong>, one public <strong>subnet</strong> span across 2 <strong>Availability Zones</strong>. With this design, even if by some reasons, a zone is inaccessible, our services can still be deployed in another one.</li><li>An <strong>internet gateway</strong> attaches to the VPC so our services can access the internet.</li><li>An <strong>Amazon MQ</strong> deployed in public subnet to act as our Action Queue. NOTE: the Amazon MQ brokers belong to same <strong>security group</strong>, which only allow access from our lambdas and private services.</li><li>A <strong>Cloudwatch Event</strong> which monitor the Amazon MQ status, will inform our <strong>AWS</strong> <strong>Auto Scaling</strong> whenever new message arrived.</li><li><strong>AWS Auto Scaling</strong> will do the following:<br>- If a topic dont have any new message for a period of time (let say 2 hours), terminate the <strong>auto scaling group</strong> associate with that topic. For example, if the topic for Scanning Service dont have any message for 2 hours, turn off all the Scanning tool services.<br>- If a new message arrived at a topic, boot up the services inside the <strong>auto scaling group</strong> associate with that topic.</li><li><strong>The lambda functions</strong>, each corresponding with one of our API endpoints.</li><li>The <strong>API gateway</strong>: Since we cannot access the lambda functions directly, all the https call must go through the API gateway. For example the following request<br>GET <a href="https://gatewaydomain.com/command/getCommandStatus">https://gatewaydomain.com/command/getCommandStatus</a><br>will be sent to API gateway, then the gateway will route the request to the <em>CommandCenter.getCommandStatus</em> lambda function.</li></ul><p>With this infrastructure, whenever your toolbox isn’t in use (idle for more than 2 hours), all the high processing (and expensive) tools are turned off. Also all the lambda functions are only charged when you call them, so you are pretty much don’t have to pay any money during the idle period (not counting the storage fee).</p><h3>Conclusion</h3><p>This infrastructure is exactly what i am using right now, and it help me save a lots of money and time while get the job done.</p><p>I hope this article show you the important of designing a suitable solution base on the system and its usage. Please look forward for our next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e5a943d1e6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altitudehq/hacking-on-the-cloud-an-effective-and-cost-optimization-approach-8e5a943d1e6c">Hacking on the cloud: An effective and cost optimization approach</a> was originally published in <a href="https://medium.com/altitudehq">Altitude</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling an effective CI/CD pipeline for micro-services]]></title>
            <link>https://medium.com/altitudehq/enabling-an-effective-ci-cd-pipeline-for-micro-services-fe3ae76edcc0?source=rss-819f2838692a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe3ae76edcc0</guid>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Tran Quoc Viet]]></dc:creator>
            <pubDate>Wed, 02 Feb 2022 06:59:33 GMT</pubDate>
            <atom:updated>2022-02-02T07:06:17.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*lLko1uApoWelFy7ZUA-Tpg.jpeg" /><figcaption>CI/CD flow</figcaption></figure><p>Altitude is a platform to simplify the process of building smarter accommodation, as our slogan is “Making things simple”. Well, to be honest, I always think it should be “Making things simple for our customers” because the technology behind our system is anything but simple. Altitude offers a wide range of smart app and cloud-based platforms, from plug and play to an all-encompassing guest platform. So yeah, the slogan probably should include our development platform.</p><p>Joking aside, the system which fuels Altitude is constructed by applying the micro-service architecture, and at present, the total number of services are in the hundreds, with the counter showing no sign of stopping anytime soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gRg1F-kfo8nC2zsVAhROdw.png" /><figcaption>A snapshot of an early micro-services map, each connection is service-to-service communication, or later links via a-sync messaging such as Kakfa or a MQ. Each node is clickable opening up service details, versions, releases and more.</figcaption></figure><p>As you might already know, a system such as Altitude should have multiple development stages (production, development, user testing, demo, etc) and we are no exception. We actually have more development stages as we need to make absolutely sure our customers will never have to experience any technical issues or downtime that could impact their business. But this leads to one issue: Money.</p><p>Cloud-based system are amazing, I wholeheartedly agree, but not so much when you get the bill at the end of each month. Of course we spare no expense when it come to any environment which affect our customers such as PROD, PRE-PROD,… But what about development? The development environment are only used by our developers so we don’t really need the High Availability with 100% uptime, that our PROD environment has. The most important thing is the CI/CD model which provide the seamless deployment process. Is there any way we can keep it as cheap as possible while still able to archive the CI/CD standard?</p><p>The answer is yes we did, and how we archive that is what this article is about. In this article i will show you how to automate the deployment process of services in a development environment while keeping the cost as low as possible.</p><h3>The goals</h3><p>To make it easier to follow, let us go over the results which we wish to achieve for our development environment:</p><ul><li>Automatic deployments for each commit — developers across our environments work closely so each deploy needs to be considered across apps and web</li><li>Alerts to team — let them know something has happened, a new deploy and what changes has happened</li><li>Simple to setup — single configuration and metadata files</li><li>Automatic testing triggers — trigger tests from unit test, postman and more to ensure we’re still operational</li><li>Security and dependency reviews — ensure we’re not releasing anything with any known vulnerabilities</li><li>Data driven analytics — metadata files which contain dependent services, environment variables, and enable our custom service map and service management service</li><li>Save the cloud cost at much as possible.</li></ul><p>Lets dive in.</p><h3>Hundred of micro-services, one poor operator</h3><p>Sound pretty bad, right? But only if you try to manually do everything. Even if we want to save some money, this is never an option as in the long run it actually create much more problems than just money.</p><p>But for this part, to make a point of how much work required to deploy a single micro service , let us assume that our Operator for some reason want to manually deploy a service in our Development Stage.</p><p><em>So Anthony</em> — Altitude’s most promising Developer — has finished his new service called “<em>SMS Sending</em>” service. Of course as good a developer as he is, the service is <strong><em>stateless</em></strong>, <strong><em>Docker-ready</em></strong>, and accompanied by <strong>unit</strong> <strong>test scripts</strong>. Now with such service ready to be deployed, and the Operator want to manually deploy this service to Development environment, here is what he will do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Zj0WajJrG5DmMokMdbF7Xw.png" /><figcaption>AltitudeHQ Deployment Process Diagram</figcaption></figure><p>First, pull the source code of “<em>SMS Sending</em>” to his work machine</p><p>Second, make sure the service is working as intended:</p><ul><li>Deploy the service inside Docker.</li><li>Run the unit tests. All tests must pass.</li></ul><p>Third, check source code quality:</p><ul><li>We make use of <strong><em>SonarQube</em></strong> to rate our source code, and unless the result reach a certain threshold, it is time for <em>Anthony</em> to check his code again.</li><li>Check any dependencies for known vulnerabilities.</li></ul><p>After passing all the steps above, it is time to deploy “<em>SMS Sending</em>” service:</p><ul><li>Build a Docker Image for the service, let call it “<em>SMS-Sending-Service” </em>then push it to a Docker Registry.</li><li>Access the server, pull “<em>SMS-Sending-Service”</em> image and start a container using that image and name it “<em>SMS-Sending-Service-Container”.</em></li><li>Config the reverse proxy or load balancer to work with “<em>SMS-Sending-Service-Container”. </em>In Development environment, we use the ever popular <strong>Nginx</strong>.</li></ul><p>As the service is deployed and ready to be used, there are a few more tasks he need to do in our CI/CD flow:</p><ul><li>Inform the developers via Slack that their service is ready</li><li>Note down the technical detail of the service into our custom services management service.</li></ul><p>And our Operator has successfully deployed the service to the Development environment, what a joyful moment, except there are 99 or more services to go. Time to automate this process.</p><h3>Altitude’s CI/CD solution for our Development Environment</h3><p>Why do I keep emphasizing “<em>Development Environment</em>”? Because as I already mentioned above, we have multiple stages, and the <em>Development</em> stage are the only stage different from the rest.</p><p>While the <em>Production</em> environments are much more polished, make use of the AWS Cloud latest technologies, with top quality architecture, security, high availability (100% uptime) and responsiveness. The <em>Development</em> environment, on other hand, is only used by our development team, so we keep the infrastructure as simple as possible for easy debugging, and to save money.</p><p>But just because we want to save money doesn’t mean we exchange the automation for some money back, far from it. What we did is to save money by using free solutions instead of <strong>AWS Cloud Services</strong> as you might already know, those services, as good as they are, but cost a lot. The <em>Development</em> environment still have everything an automation development process should have, and it take care of everything after developer commit his/her code.</p><p>So what solution/s did we pick? Well there are a lots of options, but the one which can cover most of our needs, and best of all, open source and completely free is Jenkins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*ANbJ0MtkactHNin9BzSxrA.jpeg" /><figcaption>The best butler</figcaption></figure><p>Before I go into details of how Jenkins can help us archive our goal, lets go over a few terms we will encounter in our next sections:</p><ul><li><strong>Bitbucket</strong>: Git-based source code repository hosting service. This is where we store our source code.</li><li><strong>AWS</strong>: Our system are running on AWS Cloud.</li><li><strong>AWS ECR</strong>: aka Amazon Elastic Container Registry. This is where we store our docker images.</li><li><strong>Jenkins</strong>: free and open source automation server. We will deploy Jenkins as our automation control center.</li><li><strong>Jenkinsfile</strong>: Jenkins task script written in Groovy.</li><li><strong>AWS EC2</strong> : Amazon Elastic Compute Cloud. In development environment, our micro services are deployed in Ubuntu-based EC2 instance.</li><li><strong>NGINX</strong>: Web server that can also be used as a reverse proxy, load balancer. We use Nginx instead of AWS Load balancer in development because it is free.</li><li><strong>Ansible Playbook: a blueprint of automation tasks</strong> — which are complex IT actions executed with limited or no human involvement. Most of our manually task will be converted to <strong>Ansible</strong> script and triggered by <strong>Jenkins</strong></li><li><strong>Services management service</strong>: Altitude’s number of services continue to grow, and with more than a hundred services, we need an effective way to manage the information of each service, its technology, documents, tests API schemas and the relation between services. At first we tried to use Google Docs, as well as some map drawing tools, but to no avail. So we decided to make our own solution, and this service is the result of that. <strong>Services management service</strong> is integrated into our CI/CD flow and will automatically pull the service information, relations using the metadata included in each service, then display the data in human-friendly UI, as well as provides lots of relation maps,…</li></ul><h3>Continuous Integration with Jenkins</h3><p>Simply put, Jenkins allows us to automate all the manual tasks (as mentioned above) except for the part where the developer pushes their commit to repository.</p><p>With Jenkins acting as our main automation center, our CI/CD model will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lXHdT6wgMc1MPvtoc2eisQ.png" /><figcaption>CI/CD Model — High level view</figcaption></figure><p>In reality there can be a lot more steps in our pipeline, but for the sake of keeping the article simple, I simply leaved them out and only keep <strong>Sonarqube</strong> and <strong>Services management</strong> as an example.</p><p>Now let us go over each section</p><h4>Repository: where everything starts</h4><p>This step is the only step which require human interaction in our CI/CD model. Whenever developer commit push to a certain branch, the whole CI/CD flow will start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*lAZAunDTziv1vq2GmDpJ1w.png" /></figure><ul><li>Developer commit a push to build branch of the service repository. Let call it <strong>dev-deploy.</strong></li><li>Bitbucket send a request to the webhook which is set in the service repository configuration.</li><li><strong>Jenkins pipeline job</strong> catch the <strong>webhook</strong> request, check if it match the branch inside the job configuration and if it is, pull the source code into <strong>Jenkins</strong> local storage, then trigger the <strong>Jenkinsfile </strong>to perform all the remain steps.</li></ul><h4>Inspection: (bad) code shall not pass</h4><p>The inspection step verifies two things:</p><ul><li>The source code quality: check for memory leak, bad coding convention, etc…</li><li>The dependent libraries: check for high and critical security vulnerabilities in all dependencies</li></ul><p>If the quality pass a certain threshold the inspection will be considered a success.</p><p>As mentioned above, we will make use of <strong>Sonarqube</strong> for this task. I wont go into detail of how we setup <strong>Sonarqube</strong> as it is out of this article scope but you can simply install it into an EC2 instance using Docker.</p><p>It is to no surprise that Jenkins already has plugins to support Sonarqube given how popular it is. The detail to setup said plugin can be found here: <a href="https://docs.sonarqube.org/latest/analysis/jenkins/"><strong><em>Sonarqube Jenkins Integration</em></strong></a></p><p><em>Fun story: The amount of “</em><a href="https://docs.sonarqube.org/latest/user-guide/concepts/"><em>code smells</em></a><em>” Sonarqube reports will also get a equivalent amount of </em>💩<em>emojis in Slack!</em></p><h4>Build: deploy and test</h4><p>This step will wind-up a version of the service inside a <strong>Docker</strong> container (at Altitude, all services <strong>must</strong> be dockerized) and perform all the unit tests on it. Note that during the testing, <strong>Jenkins</strong> still keep the previous version of that service running, the new version is deployed into a different container.</p><p>Once all the test passed with “<em>success”</em> status, the new version will be release to Development Environment.</p><h4>Release</h4><p>Continue from the previous step, <strong>Jenkins</strong> will point the <strong>Nginx</strong> to the new version, and tear down the previous one.</p><p>As mention in the previous section, each of our service when commit is accompanied with a metadata file, written by our developer in JSON format. This file is included in the source code, and provides extra information about the services such as which technologies the service uses, the list of dependent services, list of 3rd party services it required,… <strong>Jenkins</strong> will pickup this metadata , parse it and call our <strong>Service Management Service</strong> to update the current service record. This help us keep track of all the services in our system and alert the required parties or systems about any major changes.</p><p>After that depend on your configuration, Jenkins will inform the developer that the whole process finished. There is multi ways to do this like email, sms,… but our favorite method is to send a message to <strong>Slack</strong>.</p><p>The chart below shows the full deployment flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*mXA9rvvARCenmsXENLgbSg.png" /><figcaption>Deployment process with Jenkins at its core</figcaption></figure><h3>Verdict</h3><p><strong>Jenkins</strong> make the whole deployment process seamlessly and the Operator will have a much easier time now as each service can now be deployed by the developer in charge of it. He/she only need to work on each service the first time it was deployed (write the <strong>Jenkinsfile</strong> configuration).</p><h3>BONUS: Altitude Infrastructure for development stage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITzNv9JI2mDQK3iiwlWCbg.png" /></figure><p>In case you wondering, here is an overview of our infrastructure for our development environment:</p><ul><li>A <strong>VPC</strong> : Amazon Virtual Private Cloud</li><li>A single <strong>Availability Zone</strong>: for other stages we recommend having more than 2</li><li>2 <strong>Subnets</strong>: 1 private, 1 public</li><li>An <strong>EC2</strong> which host <strong>Nginx</strong> inside public <strong>subnet</strong>: Instead of using aws load balance which cost money, instead we use a <strong>Nginx</strong> (free) to act as a load balancer. Since AWS micro instance is pretty cheap (even cheaper if you use reserved instance), this save you a bit of money. This instance can be accessed from anywhere if need since it is in public subnet, but we only allow access from our office.</li><li>An <strong>EC2</strong> which host <strong>Jenkins</strong>: In our case we categories <strong>Jenkins</strong> tasks into two groups:<br>- <em>Normal tasks</em>: Task which wont need much processing power, for example a task to push and pull, deploy a service.<br>- <em>Heavy tasks</em>: Task which require a lots of CPU or RAM. For example: build our CMS web UI. <br>Normally you will need a strong instance type to deal with both types, but that isn&#39;t cost effective as heavy tasks are rarely called. So here is our solution:<br>- Use t2.medium to host <strong>Jenkin</strong>, all <em>normal tasks</em> will be performed here<br>- Use <strong>EC2 Spot </strong>instance to handle <em>heavy tasks</em>: which allow us to quickly boot up a instance to handle heavy task, then turn off when task finished.</li><li>Multiple <strong>EC2</strong> to host our services: The number and size of each instance depend on how many services you have and how much ram they use. Make sure to always limit the service docker instance max ram, and then do the math to decide which <strong>EC2</strong> instance you need. For example, 100 services, each use around maximum 128 mb ram will require you to have a at least 12G ram , so a t2.large and a t2.medium will do the trick.</li><li><strong>Jenkin</strong> <strong>EC2 </strong>and<strong> Micro Service EC2 </strong>are put into private subnet: They can’t be accessed from anywhere except from inside the VPC. As you can see in the diagram, there is absolutely no reason to access them directly in the first place</li></ul><p>I hope you have a good understand how our infrastructure work. If you have any question or notice any part which need correction, please leave a comment. Thank you for reading our article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe3ae76edcc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/altitudehq/enabling-an-effective-ci-cd-pipeline-for-micro-services-fe3ae76edcc0">Enabling an effective CI/CD pipeline for micro-services</a> was originally published in <a href="https://medium.com/altitudehq">Altitude</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>