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:
- Installed git in your local machine.
- A GitHub account. Register for a GitHub account here.
- A Pipelines account. Register for a Pipelines account here.
- A running AWS EC2 instance, and installed Pipelines Agent
- NPM and NodeJS installed.
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.
- To create new Key Pairs, navigate to the AWS Console, then click EC2.
- On the left pane, click Key Pairs, then click Create Key Pair
- 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.
- First, navigate to AWS console, click on AWS Marketplace.
- Search for MEAN powered by Bitnami, then select the 64-bit AMI to continue.
- Under Pricing Details, to get the best delivery speed, pick a region that is closest to you, then click Continue.
- For the Security Group choose Create new based on seller settings
- Ensure you have the following Connection Methods:
- SSH, My IP
- HTTP, Anywhere
- HTTPS, Anywhere
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.
- Inside EC2, click Instances, select the newly launched instance from previous step, then click Connect.
- On the popup, copy the code under Example, as shown in the picture below:
- 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:
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.
- Fork the sample application from the Pipelines GitHub repository.
- Click Fork.
- In your terminal, navigate to a directory where you'd like to store the codebase. Then, clone the repository with following syntax:
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
- 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.
- Next, click Go to build. There you will be able to see your builds.
## 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.
- Login to your Pipelines account. At the top menu, click Applications.
- To edit the settings for an app, click on the application name. Click the application you just added.
- In your application settings, click Environments, then click Create Environment
- For this tutoral, name your environment Test_Env. Click Create Environment. Here is an example:
- To add a server to this environment, click the Plus Button.
- 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.
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.
- In Pipelines, at the top menu, click Applications.
- In the application list, click your new application.
- Under the Overview tab, ensure Auto Build is toggled-on.
- Click Add Step, select Test_Env, then click Add.
- To enable auto deploy, check the Auto Deploy box and select If the Build succeeds