Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
example aws playbook
Browse files Browse the repository at this point in the history
Signed-off-by: David Chung <[email protected]>
  • Loading branch information
David Chung committed Jan 7, 2018
1 parent 46d0977 commit 599ee8b
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/playbooks/aws/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Example Playbook for AWS
========================

This playbook contains example of working with AWS. There are commands for
starting up infrakit (which assumes you have used AWS CLI on your local computer and
the `.aws/credentials` file exists) and commands for spinning up an on-demand or
spot instance configured with Docker, Git and Go compiler.

## Adding this playbook

Adding files locally:

```
infrakit playbook add aws file://$(pwd)/index.yml
```

Adding the playbook from Github:

```
infrakit playbook add aws https://raw.githubusercontent.com/docker/infrakit/master/examples/playbooks/aws/index.yml
```
9 changes: 9 additions & 0 deletions examples/playbooks/aws/index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Start infrakit
start : start.sh

# Create a single instance
ondemand : provision-instance.yml

# Create a spot instance
spot : provision-spot-instance.yml
56 changes: 56 additions & 0 deletions examples/playbooks/aws/provision-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{/* Input to create instance using the AWS instance plugin */}}
{{/* =% instanceProvision `aws/ec2-instance` %= */}}

{{ $user := flag "user" "string" "username" | prompt "Please enter your user name:" "string" (env "USER")}}
{{ $project := flag "project" "string" "project" | prompt "Project?" "string" "myproject" }}
{{ $imageId := flag "image-id" "string" "Image ID" | prompt "AMI?" "string" "ami-df8406b0" }}
{{ $instanceType := flag "instance-type" "string" "instance type" | prompt "Instance type?" "string" "t2.micro" }}
{{ $privateIp := flag "private-ip" "string" "Private IP" | prompt "Private IP address (IPv4)?" "string" "172.31.20.100" }}


{{ $keyName := flag "key" "string" "ssh key name" | prompt "SSH key?" "string" "infrakit"}}
{{ $az := flag "az" "string" "availability zone" | prompt "Availability zone?" "string" "eu-central-1b"}}
{{ $subnetId := flag "subnet" "string" "subnet id" | prompt "Subnet ID?" "string" "subnet-11b8376a" }}
{{ $securityGroupId := flag "security-group-id" "string" "security group id" | prompt "Security group ID?" "string" "sg-975500fe" }}

Tags:
infrakit.scope: {{ $project }}
infrakit.created: {{ now | htmlDate }}
infrakit.user: {{ $user }}

Init: |
#!/bin/bash
sudo add-apt-repository ppa:gophers/archive
sudo apt-get update -y
sudo apt-get install -y wget curl git golang-1.9-go
wget -qO- https://get.docker.com | sh
ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go
Properties:
RunInstancesInput:
BlockDeviceMappings: null
DisableApiTermination: null
EbsOptimized: null
IamInstanceProfile: null
ImageId: {{ $imageId }}
InstanceInitiatedShutdownBehavior: null
InstanceType: {{ $instanceType }}
KeyName: {{ $keyName }}
NetworkInterfaces:
- AssociatePublicIpAddress: true
PrivateIpAddress: {{ $privateIp }}
DeleteOnTermination: true
DeviceIndex: 0
Groups:
- {{ $securityGroupId }}
NetworkInterfaceId: null
SubnetId: {{ $subnetId }}
Placement:
Affinity: null
AvailabilityZone: {{ $az }}
Tenancy: null
RamdiskId: null
SubnetId: null
UserData: null
Tags:
infrakit.user: {{ $user }}
49 changes: 49 additions & 0 deletions examples/playbooks/aws/provision-spot-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{/* Input to create a spot instance using the AWS instance plugin */}}
{{/* =% instanceProvision `aws/ec2-spot-instance` %= */}}

{{ $user := flag "user" "string" "username" | prompt "Please enter your user name:" "string" (env "USER")}}
{{ $project := flag "project" "string" "project" | prompt "Project?" "string" "myproject" }}
{{ $imageId := flag "image-id" "string" "Image ID" | prompt "AMI?" "string" "ami-df8406b0" }}
{{ $instanceType := flag "instance-type" "string" "instance type" | prompt "Instance type?" "string" "t2.micro" }}
{{ $privateIp := flag "private-ip" "string" "Private IP" | prompt "Private IP address (IPv4)?" "string" "172.31.20.100" }}
{{ $spotPrice := flag "spot-price" "string" "Spot price" | prompt "Spot price?" "string" "0.03" }}

{{ $keyName := flag "key" "string" "ssh key name" | prompt "SSH key?" "string" "infrakit"}}
{{ $az := flag "az" "string" "availability zone" | prompt "Availability zone?" "string" "eu-central-1b"}}
{{ $subnetId := flag "subnet" "string" "subnet id" | prompt "Subnet ID?" "string" "subnet-11b8376a" }}
{{ $securityGroupId := flag "security-group-id" "string" "security group id" | prompt "Security group ID?" "string" "sg-975500fe" }}

Tags:
infrakit.scope: {{ $project }}
infrakit.created: {{ now | htmlDate }}
infrakit.user: {{ $user }}

Init: |
#!/bin/bash
sudo add-apt-repository ppa:gophers/archive
sudo apt-get update -y
sudo apt-get install -y wget curl git golang-1.9-go
wget -qO- https://get.docker.com | sh
ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go
Properties:
RequestSpotInstancesInput:
LaunchSpecification:
ImageId: {{ $imageId }}
InstanceType: {{ $instanceType }}
KeyName: infrakit
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeleteOnTermination: true
DeviceIndex: 0
Groups:
- {{ $securityGroupId }}
NetworkInterfaceId: null
PrivateIpAddress: {{ $privateIp }}
PrivateIpAddresses: null
SecondaryPrivateIpAddressCount: null
SubnetId: {{ $subnetId }}
Placement:
AvailabilityZone: {{ $az }}
SpotPrice: "{{ $spotPrice }}"
Type: one-time
26 changes: 26 additions & 0 deletions examples/playbooks/aws/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{/* =% sh %= */}}

{{ $profile := flag "aws-cred-profile" "string" "Profile name" | prompt "Profile for your .aws/credentials?" "string" "default" }}
{{ $region := flag "region" "string" "aws region" | prompt "Region?" "string" "eu-central-1"}}
{{ $project := flag "project" "string" "project name" | prompt "Project?" "string" "myproject" }}

echo "Starting infrakit with aws plugin..."

{{/* Pick a credential from the local user's ~/.aws folder. You should have this if you use awscli. */}}
{{ $creds := (source (cat "file://" (env "HOME") "/.aws/credentials" | nospace) | iniDecode | k $profile ) }}
FOUND="{{ not (empty $creds) }}"
if [ $FOUND = "false" ]; then
echo "no credentials found. bye"
exit 1
fi
{{ echo "Found your credential for profile" $profile }}
AWS_ACCESS_KEY_ID={{ $creds.aws_access_key_id }} \
AWS_SECRET_ACCESS_KEY={{ $creds.aws_secret_access_key }} \
INFRAKIT_AWS_REGION={{ $region }} \
INFRAKIT_AWS_STACK_NAME={{ $project }} \
INFRAKIT_AWS_NAMESPACE_TAGS="infrakit.scope={{ $project }}" \
INFRAKIT_AWS_MONITOR_POLL_INTERVAL=5s \
infrakit plugin start aws

0 comments on commit 599ee8b

Please sign in to comment.