Skip to content

Instantly share code, notes, and snippets.

@liusheng
Last active November 24, 2018 09:26
Show Gist options
  • Save liusheng/ad3da6ead5f0d78205da03c3e52627c6 to your computer and use it in GitHub Desktop.
Save liusheng/ad3da6ead5f0d78205da03c3e52627c6 to your computer and use it in GitHub Desktop.
PoC of testing packer against huaweicloud
#######################################################
# Need to ensure following net, subnet, vpc, security group and testing image existed
# openstack network create packer-poc-net
# openstack subnet create --network packer-poc-net --subnet-range 10.0.20.0/24 packer-poc-subnet
# openstack router create packer-poc-vpc
# openstack router add subnet packer-poc-vpc packer-poc-subnet
# openstack security group create packer-poc-sg
# openstack security group rule create --ingress --protocol tcp --dst-port 22 packer-poc-sg
#
# curl -O http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
# openstack image create --file ./cirros-0.4.0-x86_64-disk.img --min-disk 1 --container-format bare --disk-format raw cirros-0.4.0-x86_64-disk -f value -c id
#######################################################
# 1. Query Huaweicloud account credentials from portal
export OS_AUTH_TYPE="password"
export OS_AUTH_URL="https://iam.cn-north-1.myhuaweicloud.com/v3"
export OS_DOMAIN_NAME="yangyuan01"
export OS_IDENTITY_API_VERSION="3"
export OS_PASSWORD="*****"
export OS_PROJECT_NAME="cn-north-1"
export OS_REGION_NAME="cn-north-1"
export OS_TENANT_NAME="cn-north-1"
export OS_USERNAME="yangyuan01"
# 2. Install openstackclient CLI tools
pip install python-openstackclient
# 3. Configure golang
wget -c https://storage.googleapis.com/golang/go1.11.1.linux-amd64.tar.gz
sudo tar -C /usr/local/ -xvzf go1.11.1.linux-amd64.tar.gz
rm go1.10.2.linux-amd64.tar.gz
mkdir -p /root/go
export GOPATH=/root/go
export PATH=/usr/local/go/bin:$GOPATH/bin:$PATH:
export GOBIN=$GOPATH/bin
# 4. Build packer binary
go get github.com/hashicorp/packer
cd $GOPATH/src/github.com/hashicorp/packer
make dev
packer version
# 5. prepare a file to validate packer funcitonality
cat << EOF >> welcome.txt
WELCOME TO PACKER!
EOF
# 6. Create packer template file
cat << EOF >> os-template.json
{
"builders": [
{
"type": "openstack",
"flavor": "c3.large.2",
"image_name": "packer-poc-img",
"source_image_name": "Ubuntu 16.04 server 64bit",
"ssh_username": "root",
"networks": "fa8bcffd-1826-4409-99c2-72ada676f3b3",
"security_groups": ["packer-poc-sg"],
"floating_ip_pool": "admin_external_net",
"availability_zone": "cn-north-1a"
}
],
"provisioners": [
{
"type": "file",
"source": "./welcome.txt",
"destination": "/root/"
},
{
"type": "shell",
"inline":[
"ls -al /root",
"cat /root/welcome.txt"
]
}
]
}
EOF
# 7. Run packer validation for the template file and build image with packer
packer validate os-template.json
packer build os-template.json
# 8. checker che image build by packer
openstack image show packer-poc-img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment