Last active
September 5, 2017 14:31
-
-
Save darron/ed7b2587a3415773f26a to your computer and use it in GitHub Desktop.
Ubuntu 14.04 AWS Instance Store HVM build - actually worked - built and booted. Much thanks to: https://github.com/Lumida/packer/wiki/Building-Ubuntu-12.04-and-14.04-HVM-Instance-Store-AMIs
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
#!/bin/bash | |
# server-jre-8u5-linux-x64.tar.gz | |
DEBIAN_FRONTEND=noninteractive | |
UCF_FORCE_CONFFNEW=true | |
export UCF_FORCE_CONFFNEW DEBIAN_FRONTEND | |
apt-get update | |
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" dist-upgrade | |
apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install ruby1.9.3 | |
apt-get clean | |
# ec2-bundle-vol requires legacy grub and there should be no console setting | |
apt-get -y install grub | |
sed -i 's/console=hvc0/console=ttyS0/' /boot/grub/menu.lst | |
# the above is sufficient to fix 12.04 but 14.04 also needs the following | |
sed -i 's/LABEL=UEFI.*//' /etc/fstab | |
mkdir /var/tmp | |
cd /var/tmp | |
mkdir ami_tools java api_tools ec2 | |
mkdir ec2/bin ec2/lib ec2/etc | |
export EC2_HOME=/var/tmp/ec2/bin | |
export JAVA_HOME=/var/tmp/java/jdk1.8.0_25/bin | |
export PATH=$PATH:$EC2_HOME:$JAVA_HOME | |
apt-get -y install unzip kpartx | |
cd java | |
wget -q https://supply.your.own.url/server-jre-8u25-linux-x64.gz | |
tar -xzf server-jre-8u25-linux-x64.gz | |
cd ../ami_tools | |
wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools-1.5.3.zip | |
unzip ec2-ami-tools-1.5.3.zip | |
cd ../api_tools | |
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip | |
unzip ec2-api-tools.zip | |
cd .. | |
mv ami_tools/ec2-ami-tools*/bin/* api_tools/ec2-api-tools*/bin/* ec2/bin/ | |
mv ami_tools/ec2-ami-tools*/lib/* api_tools/ec2-api-tools*/lib/* ec2/lib/ | |
mv ami_tools/ec2-ami-tools*/etc/* api_tools/ec2-api-tools*/etc/* ec2/etc/ | |
passwd -d ubuntu | |
rm /home/ubuntu/.ssh/authorized_keys | |
exit 0 |
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
{ | |
"variables": { | |
"aws_access_key": "", | |
"aws_secret_key": "", | |
"aws_account_id": "{{env `AWS_ACCOUNT_ID`}}", | |
"aws_x509_cert": "{{env `AWS_X509_CERT`}}", | |
"aws_x509_key": "{{env `AWS_X509_KEY`}}", | |
"chef_validation_key": "{{env `CHEF_VALIDATION_KEY`}}", | |
"chef_server_url": "{{env `CHEF_SERVER_URL`}}", | |
"chef_version": "{{env `CHEF_VERSION`}}" | |
}, | |
"builders": [{ | |
"type": "amazon-instance", | |
"access_key": "{{user `aws_access_key`}}", | |
"secret_key": "{{user `aws_secret_key` }}", | |
"account_id": "{{user `aws_account_id` }}", | |
"region": "us-east-1", | |
"source_ami": "ami-cc5229a4", | |
"instance_type": "c3.large", | |
"ssh_username": "ubuntu", | |
"ami_name": "image-{{timestamp}}", | |
"bundle_prefix": "image-{{timestamp}}", | |
"s3_bucket": "baked-ami-storage", | |
"x509_cert_path": "{{user `aws_x509_cert`}}", | |
"x509_key_path": "{{user `aws_x509_key`}}", | |
"ami_virtualization_type": "hvm", | |
"bundle_vol_command": "sudo -n bash -c 'export EC2_HOME=/var/tmp/ec2 ; export JAVA_HOME=/var/tmp/java/jdk1.8.0_25 ; export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:$EC2_HOME/bin:$JAVA_HOME/bin ; ec2-bundle-vol -P mbr -k {{.KeyPath}} -u {{.AccountId}} -c {{.CertPath}} -r x86_64 -e /var/tmp/*,/tmp/* -p {{.Prefix}} --no-filter --no-filter --batch'", | |
"bundle_upload_command": "sudo -n bash -c 'export EC2_HOME=/var/tmp/ec2 ; export JAVA_HOME=/var/tmp/java/jdk1.8.0_25 ; export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin:$EC2_HOME/bin:$JAVA_HOME/bin ; ec2-upload-bundle -b {{.BucketName}} -m {{.ManifestPath}} -a {{.AccessKey}} -s {{.SecretKey}} -d {{.BundleDirectory}} --batch --retry'" | |
}], | |
"provisioners": [ | |
{ | |
"type": "shell", | |
"script": "./packer/default_ami_setup.sh", | |
"execute_command": "{{ .Vars }} sudo -E /bin/bash '{{ .Path }}'" | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment