Skip to content

Latest commit

 

History

History
182 lines (122 loc) · 9.63 KB

README.md

File metadata and controls

182 lines (122 loc) · 9.63 KB

dromedary 🐪

Sample app to demonstrate a working pipeline using AWS Code Services

Infrastructure as Code

Dromedary was featured by Paul Duvall, Stelligent's Chief Technology Officer, during the ARC307: Infrastructure as Code breakout session at 2015 AWS re:Invent.

You can view the recording of that breakout session at https://www.youtube.com/watch?v=WL2xSMVXy5w.

The Demo App 🐪

The Dromedary demo app is a simple nodejs application that displays a pie chart to users. The data that describes the pie chart (i.e. the colors and their values) is served by the application.

If a user clicks on a particular color segment in the chart, the frontend will send a request to the backend to increment the value for that color and update the chart with the new value.

The frontend will also poll the backend for changes to values of the colors of the pie chart and update the chart appropriately. If it detects that a new version of the app has been deployed, it will reload the page.

Directions are provided to run this demo in AWS and locally.

Core Demo Requirements

Given a version-control repository, the bootstrapping and the application must be capable of launching from a single CloudFormation command and a CloudFormation button click - assuming that an EC2 Key Pair and Route 53 Hosted Zone has been configured. The demo should not be required to run from a local environment.

An application pipeline in CodePipeline must go from commit to production in less than 10 minutes.

It should be capable of running on a new AWS account without any additional setup.

Feature Backlog 🐪

We plan to add additional features in the coming months. Check the issues and Feature Backlog for more information.

Running in AWS 🐪

DISCLAIMER: Executing the following will create billable AWS resources in your account. Be sure to clean up Dromedary resources after you are done to minimize charges

PLEASE NOTE: This demo is an exercise in Infrastructure as Code, and is meant to demonstrate neither best practices in highly available nor highly secure deployments in AWS.

CloudFormation Bootstrapping (e.g. for AWS Test Drive)

You'll need the AWS CLI tools installed and configured to start.

You'll also need to create a hosted zone in Route53. This hosted zone does not necessarily need to be publicly available and a registered domain.

You can either use the AWS CLI or the AWS web console to launch a new CloudFormation stack. To launch from the console, click the button below (you'll need to login to your AWS account if you have not already done so).

Launch CFN stack

To launch from the CLI, see this example:

aws cloudformation create-stack \
--stack-name DromedaryStack  \ 
--template-body https://raw.githubusercontent.com/stelligent/dromedary/master/pipeline/cfn/dromedary-master.json \ 
--region us-east-1 \
--disable-rollback --capabilities="CAPABILITY_IAM" \
--parameters ParameterKey=KeyName,ParameterValue=YOURKEYPAIR \
	ParameterKey=Branch,ParameterValue=master \
	ParameterKey=BaseTemplateURL,ParameterValue=https://s3.amazonaws.com/stelligent-training-public/master/ \
	ParameterKey=GitHubUser,ParameterValue=YOURGITHUBUSER \
	ParameterKey=GitHubToken,ParameterValue=YOURGITHUBTOKEN \ 
	ParameterKey=DDBTableName,ParameterValue=YOURUNIQUEDDBTABLENAME \
	ParameterKey=ProdHostedZone,ParameterValue=.YOURHOSTEDZONE

In the above example, you'll need to set the YOURHOSTEDZONE value to your Route53 hosted zone. See Hosted Zones for the hosted zones configured in your AWS account.

To integrate with GitHub, AWS CodePipeline uses OAuth tokens. Generate your token at GitHub and ensure you enable the following two scopes:

  • admin:repo_hook, which is used to detect when you have committed and pushed changes to the repository
  • repo, which is used to read and pull artifacts from public and private repositories into a pipeline
Parameters Description
KeyName The EC2 keypair name to use for ssh access to the bootstrapping instance.
GitHubUser GitHub UserName. This username must be the owner of the Repo.
GitHubToken Secret. OAuthToken with access to Repo. Go to https://github.com/settings/tokens.
BaseTemplateURL S3 Base URL of all the CloudFormation templated used in Dromedary (without the file names)
DDBTableName Unique TableName for the Dromedary DynamoDB database.
ProdHostedZone Route53 Hosted Zone. You must precede YOURHOSTEDZONE with a . See Hosted Zones for the hosted zones configured in your AWS account.

As part of the bootstrapping process, it will automatically launch the Dromedary application stack via CodePipeline.

Outputs

A few of the most relevant CloudFormation outputs from the master stack are listed in the table below.

Output Description
CodePipelineURL The URL to the instantiated pipeline
JenkinsURL The URL to Jenkins server that runs the execution of jobs for CodePipeline
DromedaryAppURL Link to the working application once the application pipeline is complete

Post-bootstrap steps

IMPORTANT: You will need to manually delete the CloudFormation stack once you've completed usage. You will be charged for AWS resource usage.

Bootstrapping Tests View the outputs in CloudFormation for links to test reports uploaded to your Dromedary S3 bucket.

Upon completion of a successful pipeline execution, Dromedary will be available by going to the Outputs tab on the master CloudFormation stack and clicking on the value for the DromedaryAppURL Output. If that hosted zone is not a publicly registered domain, you can access Dromedary via IP address. The IP address can be queried by viewing the EIP output of the ENI CloudFormation stack.

Every time changes are pushed to Github, CodePipeline will build, test, deploy and release those changes.

Configure Jenkins Security

IMPORTANT: It's very important that you enable Jenkins security.

From CodePipeline, click on any of the Actions to launch Jenkins. From Jenkins, perform the following steps to configure security:

  1. Manage Jenkins > Configure Global Security
  2. Check Enable Security
  3. Click Jenkins’ own user database
  4. Check Allow users to sign up
  5. Check Logged in users can do anything
  6. Click the Save button
  7. Click Sign Up in the top right to create an account
  8. Save and login as that user
  9. Manage Jenkins > Configure Global Security
  10. Check Matrix Based Security
  11. Add a line for the user you just created
  12. Check the Administer box
  13. Click the Save button

Cleanup

To delete (nearly) all Dromedary resources, delete any Dromedary application stacks and delete the master CloudFormation stack. The only resources that remain and require manual deletion is the Dromedary S3 bucket.

Running Locally 🐪

Install Prerequisites

  1. Ensure nodejs and npm are installed
  • On Mac OS X, this can be done via Homebrew: brew install node
  • On Amazon Linux, packages are available via the EPEL yum repo: yum install -y nodejs npm --enablerepo=epel
  1. Java must be installed so that DynamoDB Local can run
  2. Install dependencies: npm install

NOTE: Dromedary relies on gulp for local development and build tasks. You may need to install gulp globally: npm install -g gulp

If gulp is not globally installed, ensure ./node_modules/.bin/ is in your PATH.

Local Server

The default task will start dynamodb-local on port 8079 and a node server listening on port 8080:

  1. Run gulp - this downloads and starts DynamoDB Local and starts Node
  2. Point your webbrowser to http://localhost:8080

Executing Unit Tests

Unit tests located in test/ were written using Mocha and Chai, and can be executed using the test task:

  1. Run gulp test

Executing Acceptance Tests

Acceptance tests located in tests-functional/ require Dromedary to be running (eg: gulp), and can be executed using the test-functional task:

  1. Run gulp test-functional

These tests (which, at this time are closer to integration tests than functional tests) exercise the API endpoints defined in app.js.

Building a Distributable Archive

The dist task copies relevant files to dist/ and installs only dependencies required to run the standalone app:

  1. Run gulp dist

dist/archive.tar.gz will be created if this task run successfully.