-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-entrypoint.bash
104 lines (64 loc) · 2.38 KB
/
docker-entrypoint.bash
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
set -u
set -e
set -x
exec 2>&1
log()
{
local msg="$@"
local dd=$(date +"%F-%H-%M-%S")
echo "[$dd] $msg"
}
### script begins here ###
me=$(readlink -f "$0")
me_dir=$(dirname $me)
log "me [$me] me_dir [$me_dir]"
cd $me_dir || { echo "unable to chdir to [$me_dir] "; sleep 180; exit 1; }
### you need to map in the file ~/.aws/config with the correct "profile" settings per account
AWS_ACCOUNT_LIST=${AWS_ACCOUNT_LIST:-"undefined"}
log "AWS_ACCOUNT_LIST [$AWS_ACCOUNT_LIST]"
AWS_REGION_LIST=${AWS_REGION_LIST:-"all"}
if [[ "$AWS_REGION_LIST" == "all" ]]; then
AWS_REGION_LIST=$(aws ec2 --region us-west-2 describe-regions | jq -r '.Regions[].RegionName' | xargs)
fi
log "AWS_REGION_LIST [$AWS_REGION_LIST]"
DELAY=${DELAY:-"300"}
log "DELAY [$DELAY]"
OUTPUT_DIR="/data"
log "OUTPUT_DIR [$OUTPUT_DIR]"
tar oxmf html.tar.xz --strip=1 -C /data
log_base_dir="/logs"
fname_ami_list="/tmp/ami_list.txt"
while (( 1 )); do
cur_date=$(date +"%F-%H-%M-%S")
base_data_dir="${log_base_dir}/${cur_date}"
for account in ${AWS_ACCOUNT_LIST}; do
for region in ${AWS_REGION_LIST}; do
out_dir="${base_data_dir}/${account}/${region}"
mkdir -pv ${out_dir}
fname_instances="${out_dir}/instances.json"
fname_images="${out_dir}/images.json"
# parallelize the fetches
aws ec2 --profile $account --region $region describe-instances > ${fname_instances}
cat "${fname_instances}" | jq -r '.Reservations[].Instances[].ImageId' | sort -u | tr '\n' ' ' > ${fname_ami_list}
echo '{ "Images": [] }' > "${fname_images}"
ls -l "${out_dir}/"
ls -l ${fname_ami_list}
if [[ -s ${fname_ami_list} ]]; then
aws ec2 --profile "${account}" --region "${region}" describe-images --image-ids $(cat ${fname_ami_list}) > "${fname_images}"
fi
### aws ec2 --profile $account --region $region describe-images --owners self > ${fname_images} &
#wait
sync
done
done
python /generate_html.py --data-dir ${base_data_dir} --outfile ${OUTPUT_DIR}/index.html
log "removing [${base_data_dir}]"
rm -rfv ${base_data_dir}
log "Sleeping [$DELAY] ..."
sleep $DELAY
done
log "ERROR: YOU SHOULD NEVER SEE THIS MESSAGE"
sleep 10
exit 1