-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-build-worker-image.sh
executable file
·72 lines (57 loc) · 1.62 KB
/
01-build-worker-image.sh
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
69
70
71
72
#!/bin/bash
if [ ! -f source.me ]; then
echo "Missing file: source.me"
exit
fi
source source.me
if [ -z $AWS_PROFILE ]; then
echo "Missing environment variable: AWS_PROFILE"
exit
fi
grep -A 1 $AWS_PROFILE ~/.aws/credentials >/dev/null
if [ $? != 0 ]; then
echo "AWS Profile not found in ~/.aws/credentials file."
exit
fi
if [ -z $PACKER_BUILDER_INSTANCE_PROFILE ]; then
echo "Missing environment variable: PACKER_BUILDER_INSTANCE_PROFILE"
exit
fi
if [ ! -f s3fs-bucket.txt ]; then
echo "Missing configuration file: s3fs-bucket.txt"
exit
fi
# I don't know which order the keys are in. But we do know the key lengths.
KEY1=$(grep -A 1 $AWS_PROFILE ~/.aws/credentials | tail -n 1 | tr -d ' ' | cut -d'=' -f2)
KEY2=$(grep -A 2 $AWS_PROFILE ~/.aws/credentials | tail -n 1 | tr -d ' ' | cut -d'=' -f2)
if [ "${#KEY1}" == "20" ]; then
export AWS_ACCESS_KEY_ID=$KEY1
else
if [ "${#KEY1}" == "40" ]; then
export AWS_SECRET_ACCESS_KEY=$KEY1
fi
fi
if [ "${#KEY2}" == "20" ]; then
export AWS_ACCESS_KEY_ID=$KEY2
else
if [ "${#KEY2}" == "40" ]; then
export AWS_SECRET_ACCESS_KEY=$KEY2
fi
fi
#
# Make sure the S3FS bucket exists.
#
echo "If the bucket exists, you will see an Access Denied message."
aws s3 mb s3://$(cat s3fs-bucket.txt)
PACKER_FILE="packer-centos.json"
packer validate $PACKER_FILE
if [ $? != 0 ]; then
echo "Fix errors in $PACKER_FILE."
exit
fi
packer build $PACKER_FILE | tee /tmp/$PACKER_FILE.log
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
echo "---------------------------"
echo "| /tmp/packer.log"
echo "---------------------------"