|
| 1 | +.. _ami_development: |
| 2 | + |
| 3 | +######################################### |
| 4 | +Setting Up an AMI Development Environment |
| 5 | +######################################### |
| 6 | + |
| 7 | +.. warning:: |
| 8 | + Building a custom AMI is not the recomended approach for customizing CfnCluster. |
| 9 | + |
| 10 | + Once you build your own AMI, you will no longer receive updates or bug fixes with future releases of CfnCluster. You will need to repeat the steps used to create your custom AMI with each new CfnCluster release. |
| 11 | + |
| 12 | +Before reading any further, take a look at the :doc:`pre_post_install` section of the documentation to determine if the modifications you wish to make can be scripted and supported with future CfnCluster releases. |
| 13 | + |
| 14 | +Steps |
| 15 | +===== |
| 16 | + |
| 17 | +This guide is written assuming your OS is Ubuntu 14.04. If you don't have an Ubuntu machine you can easily get an `EC2 instance <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html>`_ running Ubuntu. |
| 18 | + |
| 19 | +#. :code:`sudo apt-get install build-essential` |
| 20 | +#. Go to https://downloads.chef.io/chef-dk, grab the latest version for your OS and install. |
| 21 | + |
| 22 | + For example: |
| 23 | + :: |
| 24 | + |
| 25 | + wget https://packages.chef.io/stable/ubuntu/12.04/chefdk_0.17.17-1_amd64.deb |
| 26 | + sudo dpkg -i chefdk_0.17.17-1_amd64.deb |
| 27 | + |
| 28 | +#. :code:`git clone https://github.com/awslabs/cfncluster-cookbook` |
| 29 | +#. Grab the latest go-lang link from https://golang.org/dl/ |
| 30 | +#. Run the following: |
| 31 | + |
| 32 | + :: |
| 33 | + |
| 34 | + wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz |
| 35 | + cd /usr/local |
| 36 | + tar -xz ~/go1.7.linux-amd64.tar.gz |
| 37 | + echo 'export GOPATH=~/work' >> ~/.bashrc |
| 38 | + echo 'export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH' >> ~/.bashrc |
| 39 | + |
| 40 | +#. Install packer from source |
| 41 | + |
| 42 | + :: |
| 43 | + |
| 44 | + go get github.com/mitchellh/packer |
| 45 | + |
| 46 | + |
| 47 | +The next part of setting up your environment involves setting a lot of environment variables, you can either set them as I explain what they are or use the script provided at the bottom. |
| 48 | + |
| 49 | +#. Set your aws key pair name and path, if you don't have a key pair `create one <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#having-ec2-create-your-key-pair>`_. |
| 50 | + |
| 51 | + :: |
| 52 | + |
| 53 | + export AWS_KEYPAIR_NAME=your-aws-keypair # Name of your key pair |
| 54 | + export EC2_SSH_KEY_PATH=~/.ssh/your-aws-keypair # Path to your key pair |
| 55 | + |
| 56 | +#. Set the AWS `instance type <https://aws.amazon.com/ec2/instance-types/>`_ you'd like to launch. |
| 57 | + |
| 58 | + :: |
| 59 | + |
| 60 | + export AWS_FLAVOR_ID=c3.4xlarge |
| 61 | + |
| 62 | +#. Set the availibility zone and region: |
| 63 | + :: |
| 64 | + |
| 65 | + export AWS_AVAILABILITY_ZONE=us-east-1c |
| 66 | + export AWS_DEFAULT_REGION=us-east-1 |
| 67 | + |
| 68 | +#. Create a AWS VPC in that region: |
| 69 | + |
| 70 | + :: |
| 71 | + |
| 72 | + export AWS_VPC_ID=vpc-XXXXXXXXX |
| 73 | + |
| 74 | +#. Create a subnet in that region and set it below: |
| 75 | + |
| 76 | + :: |
| 77 | + |
| 78 | + export AWS_SUBNET_ID=subnet-XXXXXXXX |
| 79 | + |
| 80 | +#. Create a security group and set it: |
| 81 | + |
| 82 | + :: |
| 83 | + |
| 84 | + export AWS_SECURITY_GROUP_ID=sg-XXXXXXXX |
| 85 | + |
| 86 | +#. Create an IAM Profile from the template `here <http://cfncluster.readthedocs.io/en/latest/iam.html>`_. |
| 87 | + |
| 88 | + :: |
| 89 | + |
| 90 | + export AWS_IAM_PROFILE=CfnClusterEC2IAMRole # IAM Role name |
| 91 | + |
| 92 | +#. Set the path to your kitchen yaml file. Note that this comes in CfnClusterCookbook. |
| 93 | + |
| 94 | + :: |
| 95 | + |
| 96 | + export KITCHEN_LOCAL_YAML=.kitchen.cloud.yml |
| 97 | + |
| 98 | +#. Create a 10G ebs backed volumne in the same availibity zone: |
| 99 | + |
| 100 | + :: |
| 101 | + |
| 102 | + export CFN_VOLUME=vol-XXXXXXXX # create 10G EBS volume in same AZ |
| 103 | + |
| 104 | +#. Set the stack name. |
| 105 | + |
| 106 | + :: |
| 107 | + |
| 108 | + export AWS_STACK_NAME=cfncluster-test-kitchen |
| 109 | + |
| 110 | +#. Create an sqs queue: |
| 111 | + |
| 112 | + :: |
| 113 | + |
| 114 | + export CFN_SQS_QUEUE=cfncluster-chef # create an SQS queue |
| 115 | + |
| 116 | +#. Create a dynamoDB table with hash key :code:`instanceId` type String and name it :code:`cfncluster-chef` then export the following: |
| 117 | + |
| 118 | + :: |
| 119 | + |
| 120 | + export CFN_DDB_TABLE=cfncluster-chef # setup table as cfncluster-chef |
| 121 | + |
| 122 | +#. You should now be able to run the following: |
| 123 | + |
| 124 | + :: |
| 125 | + |
| 126 | + kitchen list |
| 127 | + |
| 128 | +#. If something isn't working you can run: |
| 129 | + |
| 130 | + :: |
| 131 | + |
| 132 | + kitchen diagnose all |
| 133 | + |
| 134 | + |
| 135 | +Here's a script to do all of the above, just fill out and the fields and source it like: :code:`. ~/path/to/script` |
| 136 | + |
| 137 | +:: |
| 138 | + |
| 139 | + export AWS_KEYPAIR_NAME=your-aws-keypair # Name of your key pair |
| 140 | + export EC2_SSH_KEY_PATH=~/.ssh/your-aws-keypair.pem # Path to your key pair |
| 141 | + export AWS_FLAVOR_ID=c3.4xlarge |
| 142 | + export AWS_DEFAULT_REGION=us-east-1 |
| 143 | + export AWS_AVAILABILITY_ZONE=us-east-1c |
| 144 | + export AWS_VPC_ID=vpc-XXXXXXXX |
| 145 | + export AWS_SUBNET_ID=subnet-XXXXXXXX |
| 146 | + export AWS_SECURITY_GROUP_ID=sg-XXXXXXXX |
| 147 | + export AWS_IAM_PROFILE=CfnClusterEC2IAMRole # create role using IAM docs for CfnCluster |
| 148 | + export KITCHEN_LOCAL_YAML=.kitchen.cloud.yml |
| 149 | + export CFN_VOLUME=vol-XXXXXXXX # create 10G EBS volume in same AZ |
| 150 | + export AWS_STACK_NAME=cfncluster-test-kitchen |
| 151 | + export CFN_SQS_QUEUE=cfncluster-chef # create an SQS queue |
| 152 | + export CFN_DDB_TABLE=cfncluster-chef # setup table as cfncluster-chef |
0 commit comments