3
我用封隔器來構建亞馬遜AMI和我跑進問題是:帕克EC2_HOME:無論EC2_AMITOOL_HOME或EC2_HOME環境變量的設置
- 基礎AMI(
ami-a4bdd194
)沒有ec2-ami-tools
安裝,所以我寫了一個小腳本使用條件屬性來安裝它。 - 它成功安裝到
/usr/local/bin
但我仍然在構建AMI時遇到以下錯誤。
任何幫助將非常感激!謝謝!
//控制檯錯誤日誌
amazon-instance: /usr/local/bin/ec2-bundle-vol: line 3: EC2_HOME: Neither of EC2_AMITOOL_HOME or EC2_HOME environment variables are set
amazon-instance:
amazon-instance:
amazon-instance:
amazon-instance:
amazon-instance:
==> amazon-instance: Volume bundling failed. Please see the output above for more
==> amazon-instance: details on what went wrong.
// packer.json
{
"variables": {
"access_key": "",
"secret_key": "",
"x509_cert_path": "",
"x509_key_path": ""
},
"builders": [
{
"access_key": "{{user `access_key`}}",
"secret_key": "{{user `secret_key`}}",
"x509_cert_path": "{{user `x509_cert_path`}}",
"x509_key_path": "{{user `x509_key_path`}}",
"account_id": "123456789012",
"ami_name": "my-packer-example {{timestamp}}",
"instance_type": "i2.xlarge",
"region": "us-west-2",
"s3_bucket": "my_bucket/my_folder",
"source_ami": "ami-a4bdd194",
"ssh_username": "ubuntu",
"type": "amazon-instance"
}
],
"provisioners": [
{
"type": "shell",
"scripts": [
"../tools/install-ec2-ami-tools.bash"
]
}
]
}
//安裝-EC2-AMI-tools.bash
#!/bin/bash
function trimString()
{
echo "${1}" | sed -e 's/^ *//g' -e 's/ *$//g'
}
function isEmptyString()
{
if [[ "$(trimString ${1})" = '' ]]
then
echo 'true'
else
echo 'false'
fi
}
function installEC2AMITools()
{
if [[ "$(isEmptyString ${EC2_HOME})" = 'true' || "$(which 'ec2-bundle-vol')" = '' ]]
then
sleep 10 &&
sudo apt-get update &&
sudo apt-get install -y 'unzip' 'wget' &&
rm -rf 'ec2-ami-tools' &&
rm -f 'ec2-ami-tools.zip' &&
wget -q 'http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.zip' &&
unzip -q 'ec2-ami-tools.zip' &&
mv ec2-ami-tools-* 'ec2-ami-tools' &&
sudo rsync -a --no-o --no-g 'ec2-ami-tools/' '/usr/local' &&
rm -rf 'ec2-ami-tools' &&
rm -f 'ec2-ami-tools.zip'
else
echo -e "\033[1;32mec2-ami-tools has already been installed!\033[0m"
fi
}
function main()
{
installEC2AMITools
}
main
感謝,我說的對,這是你如何重寫:'「bundle_vol_command」:「命令-n EC2_HOME =在/ usr /本地EC2束-vol --no-filter -k {{.KeyPath}} -u {{.AccountId}} -c {{.CertPath}} -r {{.Architecture}} -e {{.PrivatePath}}/* - d {{.Destination}} -p {{.Prefix}} --batch「, 」bundle_upload_command「:」sudo -n EC2_HOME =/usr/local ec2-upload-bundle -b {{.BucketName}} -m {{.ManifestPath}} -a {{.AccessKey}} -s {{.SecretKey}} -d {{.BundleDirectory}} --batch --location EU --retry「' –
是的,'bundle_vol_command'和' bundle_upload_command'是你需要覆蓋的。另見:http://www.packer.io/docs/builders/amazon-instance.html – JeanMertz
賓果,謝謝@JeanMertz –