-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre-build AWS ami with Packer to minimise EC2 bootstrapping time #260
Open
surf-rbood
wants to merge
1
commit into
openml:master
Choose a base branch
from
surf-rbood:aws_pre_build_ami
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Auto-ML AWS AMI | ||
|
||
This directory contains the instructions and configuration files to build a custom automl AWS Amazon machine image (AMI). | ||
|
||
Note, the current configuration only works in the eu-central-1 region of AWS. | ||
Since, the base ami is hard coded to match an AMI that's only available in this region. | ||
|
||
|
||
## Prerequisites | ||
|
||
### Install Packer | ||
|
||
[Packer](https://learn.hashicorp.com/packer) is the command line tool that's used by this module to build a custom AWS AMI. | ||
To build the image, the packer cmd tool must be installed on your local machine. | ||
For more install information, [how to install packer](https://learn.hashicorp.com/tutorials/packer/getting-started-install) | ||
|
||
### AWS credentials setup | ||
Before building a new automl AMI, the AWS credentials must be configured to allow for programmatic access | ||
- configure AWS credentials | ||
- create AWS profile (e.g. automl) | ||
- set profile name (2 options) | ||
- update profile name in packer config file (i.e. ami-automl.pkr.hcl) | ||
- set profile environment variable (e.g. 'export AWS_PROFILE=automl') | ||
|
||
|
||
## Validate and Build | ||
|
||
Before building the automl AMI, the packer config file should be validated. | ||
To validate, run the following command. | ||
|
||
```sh | ||
packer validate ./config/ami-automl.pkr.hcl | ||
``` | ||
|
||
If the validation step has succeeded, run the following command to build the ami. | ||
|
||
```sh | ||
packer build ./config/ami-automl.pkr.hcl | ||
``` | ||
|
||
## AMI steps | ||
build steps: | ||
- install: curl wget unzip git | ||
- install: software-properties-common | ||
- add repository ppa:deadsnakes/ppa | ||
- update packages | ||
- install python3 (pip3, pyvenv, pydev, python) | ||
- install awscli, wheel | ||
- create directories | ||
- git clone stable branche automl | ||
- create python environment | ||
- install python packages | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
variable "source_ami" { | ||
type = string | ||
description = "Ubuntu Server 18.04 LTS (HVM), EBS General Purpose (SSD) VolumeType" | ||
default = "ami-0bdf93799014acdc4" | ||
# Optional: define a filter to automatically pick the latest version of an ami as source ami. | ||
// source_ami_filter { | ||
// filters = { | ||
// name = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*" | ||
// root-device-type = "ebs" | ||
// virtualization-type = "hvm" | ||
// } | ||
// most_recent = true | ||
// owners = ["099720109477"] | ||
// } | ||
} | ||
|
||
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } | ||
|
||
# source blocks configure your builder plugins; your source is then used inside | ||
# build blocks to create resources. A build block runs provisioners and | ||
# post-processors on an instance created by the source. | ||
source "amazon-ebs" "automl-ami" { | ||
# the profile to use in the shared credentials file for AWS. | ||
// profile = "default" | ||
|
||
ami_name = "ami-automl-${local.timestamp}" | ||
ami_description = "AMI for the AutoML benchmark project" | ||
|
||
# uncomment following line to create a public ami, default a private ami is created | ||
// ami_groups = ["all"] | ||
|
||
instance_type = "t2.micro" | ||
sebhrusen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
source_ami = var.source_ami | ||
|
||
ssh_username = "ubuntu" | ||
} | ||
|
||
# a build block invokes sources and runs provisioning steps on them. | ||
build { | ||
sources = ["source.amazon-ebs.automl-ami"] | ||
|
||
provisioner "shell" { | ||
execute_command = "echo 'packer' | sudo -S env {{ .Vars }} {{ .Path }}" | ||
environment_vars = [ | ||
"BRANCH=stable", | ||
"GITREPO=https://github.com/openml/automlbenchmark", | ||
"PYV=3" | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can those be turned into variables? |
||
] | ||
script = "./scripts/configure-ami.sh" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
echo "*** start ami configuration ***" | ||
|
||
apt-get update | ||
|
||
echo "*** install: curl, wget, unzip, git ***" | ||
# Skip restart prompt of 'libssl1.1' by running following command | ||
echo '* libraries/restart-without-asking boolean true' | debconf-set-selections | ||
apt-get -y install curl wget unzip git | ||
apt-get -y install software-properties-common | ||
add-apt-repository -y ppa:deadsnakes/ppa | ||
apt-get update | ||
|
||
echo "*** install python${PYV} ***" | ||
apt-get -y install python$PYV python$PYV-venv python$PYV-dev python3-pip | ||
|
||
echo "*** install awscli ***" | ||
pip3 install -U wheel awscli --no-cache-dir | ||
|
||
echo "make automl directory structure" | ||
mkdir -p /s3bucket/input | ||
mkdir -p /s3bucket/output | ||
mkdir -p /s3bucket/user | ||
mkdir /repo | ||
|
||
echo "clone repo" | ||
cd /repo | ||
git clone --depth 1 --single-branch --branch $BRANCH $GITREPO . | ||
|
||
echo "create python environment" | ||
python3 -m venv venv | ||
|
||
echo "install python packages" | ||
/repo/venv/bin/pip3 install -U pip | ||
xargs -L 1 /repo/venv/bin/pip3 install --no-cache-dir < requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,6 +116,10 @@ aws: | |
root_key: ec2/ | ||
delete_resources: false | ||
|
||
use_packer_ami: false # if true, the EC2 instance will be started with the AMI ID of the pre build packer AMI. | ||
# Note, make sure to enter the AMI ID of your packer build image in the packer_ami field (i.e. ec2.regions.[region].packer_ami). | ||
# For more information, see the aws_ami directory. | ||
|
||
Comment on lines
+119
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather move this config under the |
||
ec2: | ||
key_name: # the name of the key pair passed to EC2 instances (if not set, user can't ssh the running instances) | ||
security_groups: [] # the optional additional security groups to set on the instances | ||
|
@@ -150,14 +154,18 @@ aws: | |
us-east-1: | ||
ami: ami-0ac019f4fcb7cb7e6 | ||
description: Ubuntu Server 18.04 LTS (HVM), EBS General Purpose (SSD) VolumeType | ||
packer_ami: | ||
us-west-1: | ||
ami: ami-063aa838bd7631e0b | ||
description: Ubuntu Server 18.04 LTS (HVM), EBS General Purpose (SSD) VolumeType | ||
packer_ami: | ||
eu-west-1: | ||
ami: ami-00035f41c82244dab | ||
description: Ubuntu Server 18.04 LTS (HVM), EBS General Purpose (SSD) VolumeType | ||
packer_ami: | ||
eu-central-1: | ||
ami: ami-0bdf93799014acdc4 | ||
packer_ami: | ||
description: Ubuntu Server 18.04 LTS (HVM), EBS General Purpose (SSD) VolumeType | ||
spot: | ||
enabled: false # if enabled, aws mode will try to obtain a spot instance instead of on-demand. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this defaults to an ami available only in
eu-central-1
: would be nice to have a way to automatically default to the ami defined associated to the selected region inconfig.yaml
.Until then, I suggest: