Pipelines for Applications

Introduction

In this tutorial, we will walk through the steps to configure an EC2 instance for MEAN-stack development, and set up automatic deployments with Pipelines.

MongoDB, ExpressJS, AngularJS, and NodeJs (MEAN) is a full-stack web framework. Each layer in the stack works effortless with one another. MEAN stack is operating system-independent, and it’s optimized for I/O usages.

Before you begin, ensure you have the following:

Step 1. Create Key Pairs

Key Pairs are used to securely log into AWS services. We will create a Key Pair to access our EC2 instance.

  1. To create new Key Pairs, navigate to the AWS Console, then click EC2.
  2. AWS EC2
  3. On the left pane, click Key Pairs, then click Create Key Pair
  4. EC2 Key Pairs
  5. Enter a name for your key, then click Create Key Pair. The Key Pair will be automatically downloaded. You should move this key to a different directory.

Important You will need to change the permissions of this key to read-only, refer the following code: chmod 400 youKeyName.pem

Step 2. Launch an EC2 instance with Bitnami

In this step, we will launch an EC2 instance from an Amazon Machine Image (AMI). With AMI, you can spin up an EC2 instance that is ready for development without much configuration.

Bitnami provides a preconfigred MEAN image, which we will use to get set up.

  1. First, navigate to AWS console, click on AWS Marketplace.
  2. EC2 Key Pairs
  3. Search for MEAN powered by Bitnami, then select the 64-bit AMI to continue.
  4. EC2 Key Pairs
  5. Under Pricing Details, to get the best delivery speed, pick a region that is closest to you, then click Continue.
  6. EC2 Key Pairs
  7. For the Security Group choose Create new based on seller settings
  8. Ensure you have the following Connection Methods:
  • SSH, My IP
  • HTTP, Anywhere
  • HTTPS, Anywhere
EC2 Key Pairs
  • Under Key Pair, select the Key Pair you created in Step 1.
  • EC2 Key Pairs
  • Finally, click Launch with 1-click, to launch the instance.
  • Step 3. Connect to Your EC2

    To SSH to your instance, you will need your instance Public IP and the Key Pair you created. First, let’s retrieve your Public IP for your instance.

    1. Inside EC2, click Instances, select the newly launched instance from previous step, then click Connect.
    2. On the popup, copy the code under Example, as shown in the picture below:
    3. EC2 Key Pairs
    4. In your terminal, navigate to the directory where your Key Pair is saved, then paste the code last step. Here is what a successful connection looks like:
    5. AWS Bitnami Successful Connection

    Step 4. Install Pipelines Agent to Instance

    Nicely done! Now that you have have access to your instance, let’s install the Pipelines Agent. Use the following syntaxes:

    curl -sSL https://pipelines.puppet.com/download/client | sh
    

    Complete the Install

      sudo /usr/local/bin/distelli agent install
    

    Verify the Install

    To validate the agent is installed and working use the agent status command.

     sudo /usr/local/bin/distelli agent status
    

    Step 5. Fork the Sample App from GitHub

    If you already have a MEAN application, create a GitHub repository for your application, and push your code to the repository. Then, move to Step 6 of this tutorial.

    To Fork a repository, ensure you are logged into your GitHub account.

    1. Fork the sample application from the Pipelines GitHub repository.
    2. Click Fork.
    3. (Forking copies this reposity to your collection of repositories without having to start a new repository.) Git Fork
    4. In your terminal, navigate to a directory where you'd like to store the codebase. Then, clone the repository with following syntax:
    5. git clone https://github.com/YOUR_GITHUB_USERNAME/nodejsbuilddeploy.git


    Next, we will link the GitHub repository with Pipelines. From there, Pipelines will be notified each time you git push and initicate your automated processeses.

    Step 6. Create an Application in Pipelines

    1. Log into your Pipelines account. Click Get Started, and follow the steps to create your app. In Step 4, under PkgInclude, add an asterisk. This will include all the files generated from the build, and send them to the server. Note you can also specifies only certain files to be sent to the server.
    2. Application Configurations
    3. In the final step, under Build Image select Pipelines JavaScript(Docker). Then click Start Build to finish adding an app.
    4. Next, click Go to build. There you will be able to see your builds. </ol> ## Step 7. Deploy to Server Let's recap what we have done so far:
        • Installed & configured Pipelines Agent on your EC2 instance, Step 4.
        • Connected your GitHub account to Pipelines, Step 6.
        • Set up automatic deployment, Step 7.
      1. Login to your Pipelines account. At the top menu, click Applications.
      2. To edit the settings for an app, click on the application name. Click the application you just added.
      3. Application Button
      4. In your application settings, click Environments, then click Create Environment
      5. Create Environments
      6. For this tutoral, name your environment Test_Env. Click Create Environment. Here is an example:
      7. Add Environment
      8. To add a server to this environment, click the Plus Button.
      9. When you first added your application, a Release should be generated if the build succeeds. If you successfully generated a Release, click Deploy to start the deployment process.
      10. Deploy Release </ol> Great! After you have added your application. Pipelines will be notified each time you `git push` and trigger any of the automation process. In the next step, we will enable auto deployment. ## Step 8. Enable Auto Build & Deploy To enable auto build and auto deploy, login to your Pipelines account.
        1. In Pipelines, at the top menu, click Applications.
        2. In the application list, click your new application.
        3. Application Button
        4. Under the Overview tab, ensure Auto Build is toggled-on.
        5. Click Add Step, select Test_Env, then click Add.
        6. To enable auto deploy, check the Auto Deploy box and select If the Build succeeds
        7. Auto Deploy
        ## Step 9. Start & Configure MongoDB On starting a new EC2 instance, Binami starts all its services. Let's terminate all, and run only the services we need. Connect to your instance (Step 3), and enter the following commands: ~~~ sh ~/stack/ctlscript.sh stop sh ~/stack/ctlscript.sh start mongodb ~~~ With Mongo daemon running in background, let's log into it to set up our database for the application. You need to use the password Bitnami created for you. 1. To get the password, click Connection, hover on Instance Settings, then click Get System Log, refer to the pictures below: AWS Bitnami Console Log 1. Search for the password in the System Log popup. AWS Bitnami Password 1. The defalt username is root. Connect to your instance, enter the following commands with your password obtained from previous step: ~~~ mongo admin -u "root" -p "" use appDB db.createUser( { user: "app", pwd: "myPassword", roles: [{ role: "readWrite", db: "appDB" }] }) ~~~ You will need to reroute external requests to your running NodeJS port. 1. Log into your instance (Step 3), enter the following commands: ~~~ iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080 ~~~ 1. Run your app with the following commands: ~~~ cd /distelli/_apps/YOUR_APP_NAME sudo node server.js ~~~ 1. To view your app, navigate to your EC2 instance and locate the public DNS. EC2 Instance DNS 1. Finally, enter the DNS address in your web browser. Here is what the sample app looks like: App Successful Deploy ## Step 10. Trigger Auto Build & Deploy To ensure auto build and deploy is cofingured correctly, let's make a small change to the codebase, push the changes to GitHub and observe the automation process on Pipelines. 1. Open up the application, and motify the landing page, home.html (refer to image below). Refer to the file structure below: Sample MEAN File Structure 1. To observe auto build, log into your Pipelines account. At the top menu, click BUILDS. 1. Orient your terminal next to your browser to see both windows (browser and terminal). Make a code push to GitHub, enter the following commands in your terminal: ~~~ git add config.js git commit -m "Testing Pipelines auto build" git push ~~~ You should notice a new build initiate at this point. If you don't, verified that you have auto build toggled on. Once the build is complete, visit your public DNS to ensure the new version is deployed. It could be cumbersome to configure each server like we did here. [Pipelines Manifest](./manifest.html) allows you to create a configuration one time, and apply it to multiple servers automatically.
    Back to top
    The page rank or the 1 our of 5 rating a user has given the page.
    The email address of the user submitting feedback.
    The URL of the page being ranked/rated.