<?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 Yosua Surojo on Medium]]></title>
        <description><![CDATA[Stories by Yosua Surojo on Medium]]></description>
        <link>https://medium.com/@yosua.surojo?source=rss-f4531af7e62c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RugRjutfwFgLhDZbKJLoFQ.jpeg</url>
            <title>Stories by Yosua Surojo on Medium</title>
            <link>https://medium.com/@yosua.surojo?source=rss-f4531af7e62c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:14:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yosua.surojo/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[Jenkins for Node.js App on AWS EC2 Part 3: Jenkins — Node.js App Integration]]></title>
            <link>https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-3-jenkins-node-js-app-integration-1fa9d1306d25?source=rss-f4531af7e62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fa9d1306d25</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Yosua Surojo]]></dc:creator>
            <pubDate>Mon, 15 Oct 2018 05:01:02 GMT</pubDate>
            <atom:updated>2018-10-15T05:01:02.556Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jenkins for Node.js App on AWS EC2 Part 3: Jenkins — Node.js App Integration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wCqhy3j6othEze-oel_N4Q.png" /></figure><h3>What are we going to build?</h3><p>In this article series, we will build a simple Node.js app that hosted on AWS EC2 instance. Furthermore, we are going to configure automation server and host Jenkins on a separate AWS EC2 instance. Jenkins will help us to automate the CI/CD process. For every code change from our Node.js app repository, Jenkins will get notified and it will pull the changes into our Jenkins server, install dependencies and run the integration test. If all tests pass, Jenkins is going to deploy the app to the node server. If it fails, developer will be notified.</p><h3>In this article?</h3><ul><li>Install NodeJS Plugin on Jenkins</li><li>Create and configure a New Jenkins Job</li><li>Add Git Webhook</li><li>EC2 SSH Authentication</li><li>Automatic Deployment Setup</li><li>Commit and Push Test</li></ul><h3>Prerequisites:</h3><p>Before we start there are some assumed preconditioned technological setups:</p><ul><li>You have read Part 1</li><li>You have read Part 2</li></ul><h3>Install NodeJS Plugin on Jenkins</h3><ul><li>Login to your Jenkins IP Address</li><li>Go to sidebar menu and select <strong>Manage Jenkins</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*GEMINsn9s1ft_pSrcnrBsA.png" /></figure><ul><li>Go to <strong>Manage Plugins</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10u_IeZ6_6sPIawF_Ts26Q.png" /></figure><ul><li>Select <strong>Available </strong>tab</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-E45su0mg8GdufNKBYLdg.png" /></figure><ul><li>Type <strong>NodeJS </strong>on searchbox</li><li>Check the checkbox of <strong>NodeJS </strong>plugin and click <strong>Download now and install after restart</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*853XDnBDoD0V8jF15moIhw.png" /></figure><ul><li>When the plugin is downloaded successfully, check <strong>Restart Jenkins when installation is complete and no jobs are running</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUCYpDpVKRec4IjtDcqpBQ.png" /></figure><ul><li>Just wait until Jenkins finish restarting</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDQ7KDbQ9BaGHmnymVmutA.png" /></figure><ul><li>Usually after restarting, Jenkins will ask you to login again</li><li>After login, go to <strong>Manage Jenkins</strong></li><li>Now, choose <strong>Global Tool Configuration</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ieKy04I_hGYgVK9eO8r4A.png" /></figure><ul><li>Go to NodeJS section</li><li>Click <strong>Add NodeJS </strong>to add NodeJS installation options that we want to provide to project which will use it. For now, we will add the latest version of NodeJS provided by Jenkins and another version</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpzBA6tP4eeNh08_PFWNHQ.png" /></figure><ul><li>Click <strong>Save</strong></li></ul><h3>Create a new Jenkins Job</h3><ul><li>Select <strong>New Item </strong>sidebar menu on Jenkins</li><li>Type “node-app” for the Jenkins Job’s name</li><li>Select <strong>Freestyle project</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ts7_JG43CzeTVQPgJemF9w.png" /></figure><ul><li>Click <strong>OK</strong></li><li>On <strong>Source Code Management </strong>section, paste “node-app” GitHub repository url to <strong>Repository URL </strong>field. You could specify which branch of the repository you want to use to build your project. Now, we will select master branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bYzYecK6DluDLveZ9sGQbg.png" /></figure><ul><li>On <strong>Build Triggers</strong>, check <strong>GitHub hook trigger for GITScm polling</strong>. So, for every git push on the master branch, it will trigger Jenkins job to start</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9T7kt7QL8c7--yDNNg7Bsw.png" /></figure><ul><li>On <strong>Build Environment </strong>section, check <strong>Provide Node &amp; npm bin/ folder to PATH</strong>. From that, you could choose which NodeJS Installation that you want to use</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zoxrml0UPgekjOdhMR8-8g.png" /></figure><ul><li>On <strong>Build </strong>section, click <strong>Add build step</strong> and select <strong>Execute shell</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*LRKBS6l5azNKUWGpRCJtzA.png" /></figure><ul><li>Copy paste this into <strong>Command </strong>field</li></ul><pre>npm install<br>./script/test</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bafvQtG8D5fHDz9whna4-w.png" /></figure><ul><li>Click <strong>Save </strong>to save your Jenkins job configuration</li></ul><h3>Add Git Webhook</h3><ul><li>Go to your “node-app” GitHub</li><li>Click on the <strong>Settings</strong> tab</li><li>Select <strong>Webhooks </strong>from the left menu</li><li>Click on the <strong>Add Webhooks</strong> button</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*fmdRwuR35VM2EEfZVP0KOw.png" /></figure><ul><li>If you are prompted, type your GitHub account password</li><li>Enter your Jenkins webhook URL into <strong>Payload URL </strong>field</li></ul><pre>http://JENKINS.SERVER.IP:8080/github-webhook/</pre><ul><li>Select <strong>Just the Push Event </strong>option</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ECHsNtOYrbfqSChh3asEw.png" /></figure><ul><li>Click <strong>Add webhook </strong>button</li></ul><h3>EC2 SSH Authentication</h3><p>To take care the authentication process, Jenkins server will need to ssh into the node-app server, clone the repo, install dependencies and restart the server.</p><ul><li>SSH into Jenkins server</li><li>Switch to Jenkins user</li></ul><pre>sudo su - jenkins</pre><ul><li>Generate SSH key</li></ul><pre>ssh-keygen -t rsa</pre><ul><li>Save the generated key in /var/lib/jenkins/.ssh/id_rsa</li><li>Leave the passphrase empty</li><li>Print the SSH key you just created</li></ul><pre>cat ~/.ssh/id_rsa.pub</pre><ul><li>Copy the output to your clipboard so you could put the public key on the node-app server to complete the authentication between Jenkins server and node-app server</li><li>SSH into node-app server</li><li>Open the file where authorized keys are stored</li></ul><pre>vim ~/.ssh/authorized_keys</pre><ul><li>Press <strong>i </strong>key on your keyboard to enter <strong>INSERT </strong>mode</li><li>Go to the end of the existing key and press <strong>enter </strong>key<strong> </strong>to enter new line</li><li>Copy paste the Jenkins public key we just created into that file</li><li>Save by pressing the <strong>esc </strong>button and type <strong>:x </strong>and press<strong> enter</strong></li><li>Set the correct permission on the .ssh folder</li></ul><pre>chmod 700 ~/.ssh<br>chmod 600 ~/.ssh/*</pre><ul><li>To check whether your Jenkins server already has SSH access to node-app server without entering a password. Run these command:</li></ul><pre>ssh ubuntu@JENKINS.SERVER.IP<br>sudo su - jenkins<br>ssh ubuntu@NODE.APP.SERVER.IP</pre><p>If you could access node-app server from Jenkins server through SSH then your SSH set up is done.</p><h3>Automatic Deployment Setup</h3><p>We need to create another shell script that responsible for the deployment.</p><ul><li>Create a file under <strong>script</strong> called deploy and add the following script</li></ul><pre>#!/bin/sh<br></pre><pre>ssh ubuntu@NODE.APP.SERVER.IP &lt;&lt;EOF</pre><pre>    cd ~/node-app</pre><pre>    git pull origin master</pre><pre>    curl -o-   https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh    | bash</pre><pre>    . ~/.nvm/nvm.sh</pre><pre>    nvm install v10.11.0</pre><pre>    npm install</pre><pre>    npm install -g nodemon pm2</pre><pre>    pm2 restart ecosystem.config.js</pre><pre>    exit</pre><pre>EOF</pre><p>This script will SSH to node-app server, go to node-app directory, pull changes from GitHub, install dependencies and restart server.</p><ul><li>Make our new script file executeable</li></ul><pre>chmod +x script/deploy</pre><ul><li>Now, we need to add <strong>ecosystem.config.js </strong>on node-app root directory with this content</li></ul><pre>module.exports = { <br>  apps: [{<br>    name    : &quot;node-app&quot;,<br>    script  : &quot;npm&quot;,<br>    args    : &quot;start&quot;<br>  }]<br>}</pre><p>Here is the final folder structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*uTotJYnVuzIXU12xdrlbpw.png" /></figure><ul><li>Before we commit our changes lets add the deployment step to our Jenkins job. Go to Jenkins and go to node-app project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yI_cbDNtGk1cTZE99QIRmQ.png" /></figure><ul><li>Go to <strong>Configure </strong>on the sidebar menu on node-app project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*1YfWnHtUnzk3EwqLvQq-8Q.png" /></figure><ul><li>Add this line to <strong>Build</strong> section, <strong>Execute Shell</strong> <strong>Command</strong> field</li></ul><pre>./script/deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nx7J1rCbLAllWIBsmTHNJw.png" /></figure><ul><li>Click <strong>Save</strong></li></ul><h3>Commit and Push Test</h3><p>Now, we will test everything we built.</p><ul><li>Commit and Push</li></ul><pre>git add .<br>git commit -m &#39;add deployment script&#39;<br>git push origin master</pre><ul><li>After you push, you could see Jenkins job starts in Jenkins dashboard</li><li>If your build is success now you could visit your node-app ip with port 3000 to check the respond</li></ul><pre>http://NODE.APP.SERVER.IP:3000</pre><ul><li>Now to check the CI/CD. Go to node-app project and edit index.js file to respond with “hello awesome”.</li><li>Don’t forget to change your test/test.js to test for that string as well</li><li>Commit and Push</li></ul><pre>git add .<br>git commit -m &#39;change the respond&#39;<br>git push origin master</pre><ul><li>After you push you should see Jenkins job starts and when it is complete, you should see your changes</li><li>If you want to do the <strong>Build </strong>manually you could click on <strong>Build Now </strong>which is on the sidebar menu of your node-app project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*1YfWnHtUnzk3EwqLvQq-8Q.png" /></figure><h3>AND WE ARE DONE! CONGRATULATIONS!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fa9d1306d25" width="1" height="1" alt=""><hr><p><a href="https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-3-jenkins-node-js-app-integration-1fa9d1306d25">Jenkins for Node.js App on AWS EC2 Part 3: Jenkins — Node.js App Integration</a> was originally published in <a href="https://medium.com/konvergen">Konvergen.AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins for Node.js App on AWS EC2 Part 2: Creating a Node.js App]]></title>
            <link>https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-2-creating-a-node-js-app-3a0fb6b63bc7?source=rss-f4531af7e62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a0fb6b63bc7</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yosua Surojo]]></dc:creator>
            <pubDate>Tue, 09 Oct 2018 05:01:02 GMT</pubDate>
            <atom:updated>2018-10-16T02:31:33.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJBYMYwgEYaC9W1Qffihfw.png" /></figure><h3>What are we going to build?</h3><p>In this article series, we will build a simple Node.js app that hosted on AWS EC2 instance. Furthermore, we are going to configure automation server and host Jenkins on a separate AWS EC2 instance. Jenkins will help us to automate the CI/CD process. For every code change from our Node.js app repository, Jenkins will get notified and it will pull the changes into our Jenkins server, install dependencies and run the integration test. If all tests pass, Jenkins is going to deploy the app to the node server. If it fails, developer will be notified.</p><h3>In this article?</h3><ul><li>Set GitHub Repository</li><li>Create Node.js App</li><li>Writing Test</li><li>Serve Node App</li><li>Setup GitHub SSH Configuration</li><li>Adding a New SSH Key to your GitHub account</li><li>Clone the repository</li></ul><h3>Prerequisites:</h3><p>Before we start there are some assumed preconditioned technological setups:</p><ul><li>You have an GitHub account, if not please sign up.</li><li>You’ve already install the latest Node.js and Node Package Manager on your local, if not please install them first.</li></ul><h3>Set GitHub Repository</h3><p>Create new repository under your GitHub account and name it “<strong>node-app</strong>”</p><ul><li>You can choose <strong>public </strong>or <strong>private repo</strong></li><li>Check the <strong>Initialize this repository with a README </strong>checkbox</li><li>Select <strong>Node</strong> in the <strong>Add .gitignore </strong>dropdown menu</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pno2NjDoQq8K3x5ybQutVQ.png" /></figure><p>Now let’s clone our “node-app” repository to our local computer and navigate to it. Right now i’m using HTTPS method to clone the repository.</p><pre>git clone <a href="https://github.com/Yosua1011/node-app.git">https://github.com/</a>&lt;github username&gt;<a href="https://github.com/Yosua1011/node-app.git">/node-app.git</a><br>cd node-app</pre><h3>Create Node.js App</h3><p>For the start, you must create package.json file in your project root. In this file, it will filled with list of the application dependencies. Copy paste the following content into it:</p><pre>{<br> “name”: “node-app”,<br> “description”: “hello my node-app”,<br> “version”: “0.0.1”,<br> “private”: true,<br> “scripts”: {<br>    “start”: “nodemon index.js”<br> },<br> “dependencies”: {<br>    “express”: “3.12.0”<br> },<br> “devDependencies”: {<br>    “mocha”: “1.20.1”,<br>    “supertest”: “0.13.0”<br> }<br>}</pre><ul><li><strong>express</strong>: Node.js framework</li><li><strong>mocha</strong>: Test framework for node (You can choose other testing framework if you wish like Jasmin, Jest, Tape, etc)</li><li><strong>supertest</strong>: Provide a high-level abstraction for testing HTTP</li></ul><p>After we defined our dependencies in package.json file, we are ready to install them:</p><pre>npm install</pre><p>Great! Now, create a new file in the project root called index.js and copy paste the following code:</p><pre>//importing node framework<br>var express = require(‘express’);<br> <br>var app = express();</pre><pre>//Respond with &quot;hello world&quot; for requests that hit our root &quot;/&quot;<br>app.get(‘/’, function (req, res) {<br> res.send(‘hello world’);<br>});</pre><pre>//listen to port 3000 by default<br>app.listen(process.env.PORT || 3000);<br> <br>module.exports = app;</pre><p>The app is going to respond with “hello world” when requests hitting our root URL (“/”).</p><p>Here is the final folder structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*slTW30oYxN2tNuwvt_sVZw.png" /></figure><p>To run your app, run this command:</p><pre>node index.js</pre><p>To view your app on your browser, try to navigate to <a href="http://localhost:3000/">http://localhost:3000</a></p><h3>Writing Test</h3><p>Our test is going to navigate to the site root (“/”) and verify that the page will responds with “hello world” text.</p><p>Under a new directory <strong>/test/</strong> create <strong>test.js. </strong>Copy and paste the following code:</p><pre>var request = require(‘supertest’);<br>var app = require(‘../index.js’);</pre><pre>describe(‘GET /’, function() {<br> it(‘respond with hello world’, function(done) {</pre><pre>  //navigate to root and check the response is &quot;hello world&quot;<br>  request(app).get(‘/’).expect(‘hello world’, done);<br> });<br>});</pre><p>We are going to use <strong>Mocha </strong>to run our test. We installed Mocha as part of our devDependencies in package.json file. To run the test we need to pass Mocha our /test/test.js file as an argument.</p><pre>./node_modules/.bin/mocha ./test/test.js</pre><p>If you run this command from your project root you will see your test run and pass.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfBxJB069KKumLrKGtxoIA.png" /></figure><p>We would like Jenkins to execute our integration test after it builds. To achieve that we need to create a shell script in our project that trigger our test.</p><p>Make new /<strong>script/</strong> folder and a file name <strong>test </strong>without the file extension. Copy paste the following code into the <strong>test</strong> file:</p><pre>#!/bin/sh</pre><pre>./node_modules/.bin/mocha ./test/test.js</pre><p>Grant the script executable permissions:</p><pre>chmod +x script/test</pre><p>Test it by executing the shell script from the project root:</p><pre>./script/test</pre><p>The test result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbpCIQk_TrSFmTWCRtIZkw.png" /></figure><p>Integration test is ready and now we ready to push our code to GitHub:</p><pre>git add .<br>git commit -m ‘simple node app with test’<br>git push origin master</pre><h3>Serve Node App</h3><p>We are going to host our Node.js app on AWS EC2 instance. Follow these steps:</p><ul><li>Log into your AWS console search for and select EC2</li><li>Select <strong>Launch Instance</strong></li><li><strong>Step 1: Choose an Amazon Machine Image (AMI) </strong>Select the free tiered Ubuntu Server 16.04 LTS</li><li>Accept the defaults for <strong>Step 2: Choose an Instance Type </strong>and choose Next</li><li>Accept the defaults for <strong>Step 3: Configure Instance Details</strong></li><li>Once completed select <strong>Add Storage </strong>and<strong> a</strong>ccept the defaults for <strong>Step 4: Add Storage</strong></li><li>Accept the defaults for <strong>Step 5: Add Tags</strong></li><li><strong>Step 6: Configure Security Group </strong>and choose <strong>Create a new security group</strong></li><li>Confirm that port 22 is configured to allow access to your VM</li><li>Click <strong>Add Rule </strong>and make sure it is Custom TCP</li><li>Fill the Port Range field with 3000 since our node app is run on port 3000</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0i9_8CKFRVLJTeN80515g.png" /></figure><ul><li>Finally select <strong>Review and Launch</strong></li><li><strong>Step 7: Review Instance Launch</strong></li></ul><p>After you select <strong>Launch </strong>you will be prompted to <strong>Select an existing key pair or to create one</strong></p><p>I have previously set up a key pair and I will select <strong>Choose an existing key pair</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UyyTcUyq7Kv0Es8zlPZWg.png" /></figure><p>Now, try to connect to your EC2 instance using SSH</p><h3>Setup GitHub SSH Configuration</h3><p>For now, we will just pull our <strong>node-app</strong> repository into our ec2 instance. For convenience, we will setup GitHub SSH configuration starting from:</p><p><strong>Generating a new SSH key</strong></p><ul><li>Make sure in your terminal, you are already connect with your EC2 instance</li><li>Paste the text below, substituting in your GitHub email address</li></ul><pre>ssh-keygen -t rsa -b 4096 -C &quot;<em>your_email@example.com</em>&quot;</pre><ul><li>This creates a new ssh key, using the provided email as a label with respond like this</li></ul><pre>Generating public/private rsa key pair.</pre><ul><li>When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location</li></ul><pre>Enter a file in which to save the key (/Users/<em>you</em>/.ssh/id_rsa): <em>[Press enter]</em></pre><ul><li>At the prompt, type a secure passphrase. But, if you don’t want to use any passphrase you could just press Enter</li></ul><pre>Enter passphrase (empty for no passphrase): <em>[Type a passphrase]</em><br>Enter same passphrase again: <em>[Type passphrase again]</em></pre><h3>Adding a new SSH key to your GitHub account</h3><ul><li>Check your SSH key<br>If your SSH key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don’t add any newlines or whitespace. Run this command to check your SSH key</li></ul><pre>cat ~/.ssh/id_rsa.pub</pre><ul><li>Copy your SSH key</li><li>Go to <a href="https://github.com/">GitHub</a></li><li>In the upper-right corner of the page, click your profile photo, then click <strong>Settings</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*tlLEkFxGr753ckgxHUg8iw.png" /></figure><ul><li>In the user settings sidebar, click <strong>SSH and GPG keys</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*A-hZW6-oJ6oYrPWB775dDw.png" /></figure><ul><li>Click <strong>New SSH key</strong> or <strong>Add SSH key</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvkV5BwXMUT02KR0Egb6YA.png" /></figure><ul><li>In the “Title” field, add a descriptive label for the new key. For this project, you might call this key “Node-app EC2”</li><li>Paste your key into the “Key” field</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRhDhQ3k13sL3zkaJve4yg.png" /></figure><ul><li>Click <strong>Add SSH key</strong></li><li>If prompted, confirm your GitHub password</li></ul><h3>Clone the repository</h3><p>After we complete SSH configuration setup, we could continue to clone our repository into our EC2 instance</p><pre>git clone <a href="/service/mailto:git@github.com">git@github.com</a>:&lt;github username&gt;/node-app.git</pre><h3>Your repository has been successfully clone into EC2 instance but it hasn’t served yet</h3><p>Nice! You’ve just finish with the part 2. Now, let’s continue to the next part which will talk about integrate your Node.js App with Jenkins.</p><p><a href="https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-3-jenkins-node-js-app-integration-1fa9d1306d25">Jenkins for Node.js App on AWS EC2 Part 3: Jenkins — Node.js App Integration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a0fb6b63bc7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-2-creating-a-node-js-app-3a0fb6b63bc7">Jenkins for Node.js App on AWS EC2 Part 2: Creating a Node.js App</a> was originally published in <a href="https://medium.com/konvergen">Konvergen.AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins for Node.js App on AWS EC2 Part 1: Installing Jenkins on EC2]]></title>
            <link>https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-1-installing-jenkins-on-ec2-24675cc08998?source=rss-f4531af7e62c------2</link>
            <guid isPermaLink="false">https://medium.com/p/24675cc08998</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[Yosua Surojo]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 11:01:01 GMT</pubDate>
            <atom:updated>2018-10-12T02:09:35.785Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What are we going to build?</strong></h3><p>In this article series, we will build a simple Node.js app that hosted on AWS EC2 instance. Furthermore, we are going to configure automation server and host Jenkins on a separate AWS EC2 instance. Jenkins will help us to automate the CI/CD process. For every code change from our Node.js app repository, Jenkins will get notified and it will pull the changes into our Jenkins server, install dependencies and run the integration test. If all tests pass, Jenkins is going to deploy the app to the node server. If it fails, developer will be notified.</p><h3>In this article?</h3><ul><li>EC2 Setup</li><li>Installing Jenkins</li><li>Configuring Firewall Settings</li><li>Setting up EC2 Security Groups</li><li>Complete Jenkins First Setup</li></ul><h3>Prerequisites:</h3><p>Before we start there are some assumed preconditioned technological setups:</p><ul><li>You have an Amazon Web Services account, if not please sign up, and for first time users you will be eligible for the free tier. The AWS Free Tier enables you to gain free, hands-on experience with AWS.</li><li>Your Amazon EC2 Key Pairs are set up, if not please <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">click here</a> to follow Amazon’s walkthrough on Creating a Key Pair Using Amazon EC2.</li></ul><h3>EC2 Setup</h3><ul><li>Log into your AWS console search for and select EC2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*dJUoDO8fkIJtfPj2S2c9RQ.png" /></figure><ul><li>Select <strong>Launch Instance</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*w43zoPRPBdK-DnxqUPcUww.png" /></figure><ul><li><strong>Step 1: Choose an Amazon Machine Image (AMI) </strong>Select the free tiered Ubuntu Server 16.04 LTS</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2sctsuqlnBt3DOxOIAqa5Q.png" /></figure><ul><li>Accept the defaults for <strong>Step 2: Choose an Instance Type </strong>and choose Next</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uF7KWsxtUz9A6CXZ9DEnA.png" /></figure><ul><li>Accept the defaults for <strong>Step 3: Configure Instance Details</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UekTB7DaOQHvHdOKz0phxA.png" /></figure><ul><li>Once completed select <strong>Add Storage </strong>and<strong> a</strong>ccept the defaults for <strong>Step 4: Add Storage</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jhu5XRuLyEw4VKhLU6bplg.png" /></figure><ul><li>Accept the defaults for <strong>Step 5: Add Tags</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CFvLiVjEwuRqqZ3qSvv4FA.png" /></figure><ul><li><strong>Step 6: Configure Security Group </strong>and choose <strong>Create a new security group</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NDbOEKboxEDktr2W6b71mw.png" /></figure><ul><li>Confirm that port 22 is configured to allow access to your VM</li><li>Finally select <strong>Review and Launch</strong></li><li><strong>Step 7: Review Instance Launch</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqxg0Ue7LsC3gTxXr002WQ.png" /></figure><p>After you select <strong>Launch </strong>you will be prompted to <strong>Select an existing key pair or to create one</strong></p><p>I have previously set up a key pair and I will select <strong>Choose an existing key pair</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UyyTcUyq7Kv0Es8zlPZWg.png" /></figure><p>After you’ve launched your instance you can scroll to the bottom of the page and view your instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XnCm_NdBABWiECgxdMX3gg.png" /></figure><p>If you are unfamiliar with how to connect to your instance AWS gives you a brief tutorial on how to do so. In your EC2 console view select <strong>Connect</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*qsSVCNxQdidZxtGdN7GsnQ.png" /></figure><p>You will be presented with the below guide on how to connect over SSH, please take notice of your IP address</p><p>The IP address of your virtual server can also be found in the EC2 console page</p><h3>Installing Jenkins</h3><p>Try to connect to your instance over SSH and then follow this steps below</p><p><strong>Step 1: Install Java</strong></p><pre>sudo add-apt-repository ppa:webupd8team/java</pre><p><strong>Step 2: Download Oracle Java 8 Installer</strong></p><pre>sudo apt update<br>sudo apt install oracle-java8-installer</pre><p>When you run the commands above you will be prompted to access the license terms of the software. Accept and continue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYoyuhTPHiMJi3K4bnFzJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SGdqZorGYem7SU05f8lqKw.png" /></figure><p><strong>Step 3: Configure Oracle JDK8 As Default</strong></p><pre>sudo apt install oracle-java8-set-default</pre><p>you could check your java version by running following command</p><pre>javac -version</pre><p><strong>Step 4: Install Jenkins</strong></p><p>Run the commands below to add Jenkins repository to your system. First add the repository key</p><pre>cd /tmp &amp;&amp; wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -</pre><p>Then run the commands below to add the repository</p><pre>echo &#39;deb https://pkg.jenkins.io/debian-stable binary/&#39; | sudo tee -a /etc/apt/sources.list.d/jenkins.list</pre><p>After that, run the commands below to install Jenkins</p><pre>cd<br>sudo apt update<br>sudo apt install jenkins</pre><p>After installing Jenkins, the commands below can be used to stop, start and enable Jenkins to always start up when the server boots</p><pre>sudo systemctl stop jenkins.service<br>sudo systemctl start jenkins.service<br>sudo systemctl enable jenkins.service</pre><p>Lets verify that Jenkins has started successfully with the below command</p><pre>sudo systemctl status jenkins</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2spGaUcXPLCL8-mhX37CPg.png" /></figure><h3>Configuring Firewall Settings</h3><p>Jenkins runs on port 8080 by default, lets allow access to the port 8080 and also 22 to keep ssh access</p><pre>sudo ufw allow 8080<br>sudo ufw allow 22</pre><p>Now, lets check our firewall status</p><pre>sudo ufw status</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*1EnTkfMlREt9ElRzuAwiYg.png" /></figure><p>If you receive an inactive status after running the above command, run the below command to fix it</p><pre>sudo ufw enable</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*t9iLEZlnVXVt9aXaewLgjA.png" /></figure><h3>Setting up EC2 Security Groups</h3><p>Because our Jenkins server is on AWS, we will need to expose port :8080 in our security group</p><p>Lets jump back into the EC2 console view, select <strong>Security Groups </strong>from the left side scroll bar and choose <strong>Create Security Group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*yzmEBi6zmPKxYL2GBIXtmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*rqpSWuSrqkRrISMKxaAc0g.png" /></figure><p>We will now add two <strong>Inbound </strong>rules to access our Jenkins service from the web browser (port :8080) and through the command line (SSH)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*nFCtDEs3DvEQzBux8adwYA.png" /></figure><p>Return to the EC2 console and change your VM’s security group to the newly created Security Group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EUhP7-ItlcBUzoebxn6Afw.png" /></figure><p>Uncheck the old security group (default) and assign the newly created one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BU94k5xXY_-2ud59KmcXTQ.png" /></figure><p><strong>Note</strong>: there is a possibility that your terminal session will be disconnected while changing security groups, if this occurs please reconnect via ssh</p><h3>Complete Jenkins First Setup</h3><p>Visit Jenkins on its default port 8080, using the server IP address <a href="http://ec2_instance_ip_address:8080/">http://ec2_instance_ip_address:8080</a></p><p>The IP address of your VM can be found in the EC2 console page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IiEpHTe-rY4GEjPa2toH6w.png" /></figure><p>Once you have successfully navigated to your VM’s public IP address in your web browser you will be prompted to Unlock Jenkins. So, jump back into your terminal session and run the below command for the initial password</p><pre>sudo cat /var/lib/jenkins/secrets/initialAdminPassword</pre><p>Copy the password from your terminal and paste the password into the password field in your web browser and then select <strong>Continue</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q__9MFx3QTjG2MeGqj4pIA.png" /></figure><p>Select <strong>Install suggested plugins</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7INQrWz84hfGBjhgsIlwyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdISZysAjxJF3WJP1YW79w.png" /></figure><p>When the installation is complete, you’ll be prompted to set up the first admin user. Go ahead and create the user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBkS_Cn2LdET-iDypJoj-A.png" /></figure><p>For <strong>Instance Configuration</strong>, if you don’t want to set the Jenkins URL, you could select <strong>Not now</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-odd18hfRbOFzlnyCWwmjQ.png" /></figure><p>Select <strong>Save and Finish</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0_S_48gV69VsiZdMNzVHVw.png" /></figure><p><strong>Note</strong>: If it’s just a blank page after you click <strong>Start using Jenkins</strong>. I suggest you accessing Jenkins with /restart to restart your Jenkins</p><pre>http://JENKINS.SERVER.IP:8080/restart</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*E8zQYPKEgLuHw3W48ZSfOA.png" /></figure><h3>Jenkins has been successfully installed!!!</h3><p>What a good step for us. In next article we will start the Node.js app project to develop.</p><h3>Next Part: Part 2</h3><p><a href="https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-2-creating-a-node-js-app-3a0fb6b63bc7">Jenkins for Node.js App on AWS EC2 Part 2: Creating a Node.js App</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24675cc08998" width="1" height="1" alt=""><hr><p><a href="https://medium.com/konvergen/jenkins-for-node-js-app-on-aws-ec2-part-1-installing-jenkins-on-ec2-24675cc08998">Jenkins for Node.js App on AWS EC2 Part 1: Installing Jenkins on EC2</a> was originally published in <a href="https://medium.com/konvergen">Konvergen.AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>