-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild_ami
More file actions
executable file
·68 lines (57 loc) · 1.93 KB
/
build_ami
File metadata and controls
executable file
·68 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
set -eu
build_timestamp="$(date +%s)"
centos_version='7.3.1611'
packer_opts=''
s3_bucket=''
s3_prefix=''
function usage {
cat <<EOF
Usage: ${0##*/} -b s3_bucket [-d s3_prefix] [-p packer_options] [-v centos_version]
-b The name of the S3 bucket. Required.
-d path An optional prefix for the S3 key.
-p options Additional packer options. Ex: '--var foo=bar --var bar=foo'
-v version The version of CentOS to build. Default is ${centos_version}.
EOF
}
while getopts "b:d:hp:v:" opt; do
case ${opt} in
b)
s3_bucket="${OPTARG}"
;;
d)
s3_prefix="${OPTARG}"
;;
h)
usage
exit 0
;;
p)
packer_opts="${OPTARG}"
;;
v)
centos_version="${OPTARG}"
;;
*)
echo
usage >&2
exit 1
;;
esac
done
shift $(( OPTIND - 1 ))
if [ -z "${s3_bucket}" ]; then
usage >&2
exit 1
fi
if [ -z "${centos_version}" ]; then
echo 'CentOS version cannot be blank' >&2
exit 1
fi
if [ -n "${s3_prefix}" ]; then
s3_prefix="$(echo "${s3_prefix}" | sed -e '/[^/]$/s;$;/;')"
fi
packer build --only=vbox4ami --var build_number="${build_timestamp}" ${packer_opts} centos-x86_64-updates.json
VBoxManage clonehd "/tmp/packer-centos-${centos_version}-x86_64-updates-AMI-${build_timestamp}/packer-centos-${centos_version}-x86_64-updates-AMI-${build_timestamp}-disk1.vmdk" "/tmp/packer-centos-${centos_version}-x86_64-updates-${build_timestamp}.vhd" --format vhd
aws s3 cp "/tmp/packer-centos-${centos_version}-x86_64-updates-${build_timestamp}.vhd" "s3://${s3_bucket}/${s3_prefix}packer-centos-${centos_version}-x86_64-updates-${build_timestamp}.vhd"
aws ec2 import-image --cli-input-json "{\"Description\": \"packer-centos-${centos_version}-x86_64-updates-${build_timestamp}\",\"DiskContainers\": [{\"Description\": \"packer-centos-${centos_version}-x86_64-updates-${build_timestamp}\",\"UserBucket\": {\"S3Bucket\": \"${s3_bucket}\",\"S3Key\": \"${s3_prefix}packer-centos-${centos_version}-x86_64-updates-${build_timestamp}.vhd\"}}]}"