-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_custom_amis.sh
executable file
·140 lines (98 loc) · 4.2 KB
/
load_custom_amis.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Note, this script is no longer used and can probably be removed from the baseline
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${SCRIPT_DIR}/env.sh"
BOOTSTRAP_IMG='/opt/openshift/bootstrap.img'
MASTER_IMG='/opt/openshift/master.img'
# Detach all loop devices
sudo losetup -D
rm -f "${BOOTSTRAP_IMG}" "${MASTER_IMG}"
fallocate -l 16GB "${BOOTSTRAP_IMG}"
fallocate -l 16GB "${MASTER_IMG}"
#######################
sudo losetup -f -P "${BOOTSTRAP_IMG}"
sudo /usr/local/bin/coreos-installer install --firstboot-args=console=tty0 --insecure --insecure-ignition \
--preserve-on-error --platform "metal" --offline \
--image-file '/opt/openshift/rhcos/rhcos-4.13.10-x86_64-metal.x86_64.raw.gz' \
--ignition-file "/opt/openshift/cluster/bootstrap.ign" /dev/loop0
sudo sync
sudo losetup -D
#######################
sudo losetup -f -P "${MASTER_IMG}"
sudo /usr/local/bin/coreos-installer install --firstboot-args=console=tty0 --insecure --insecure-ignition \
--preserve-on-error --platform "metal" --offline \
--image-file '/opt/openshift/rhcos/rhcos-4.13.10-x86_64-metal.x86_64.raw.gz' \
--ignition-file "/opt/openshift/cluster/master.ign" /dev/loop0
sudo sync
sudo losetup -D
##############################
${S3} rm "s3://${S3_BUCKET}/${BOOTSTRAP_IMG}"
${S3} rm "s3://${S3_BUCKET}/${MASTER_IMG}"
${S3} cp "${BOOTSTRAP_IMG}" "s3://${S3_BUCKET}/"
${S3} cp "${MASTER_IMG}" "s3://${S3_BUCKET}/"
#########################################################
# Creating bootstrap AMI
rm -f /tmp/containers.json
cat << EOF > /tmp/containers.json
{
"Description": "Red Hat CoreOS ${RHCOS_VER} Bootstrap",
"Format": "RAW",
"UserBucket": {
"S3Bucket": "${S3_BUCKET}",
"S3Key": "$(basename ${BOOTSTRAP_IMG})"
}
}
EOF
BOOTSTRAP_IMPORT_ID=$( ${EC2} import-snapshot --disk-container "file:///tmp/containers.json" | jq -r '.ImportTaskId')
echo "Bootstrap Snapshot import ID: ${BOOTSTRAP_IMPORT_ID}"
x="unknown"
while [[ "$x" != "completed" ]]
do
echo "Waiting for bootstrap snapshot import to complete"
x=$(${EC2} describe-import-snapshot-tasks --import-task-ids ${BOOTSTRAP_IMPORT_ID} | jq -r '.ImportSnapshotTasks[0].SnapshotTaskDetail.Status')
sleep 5
done
BOOTSTRAP_SNAPSHOT=$(${EC2} describe-import-snapshot-tasks --import-task-ids ${BOOTSTRAP_IMPORT_ID} | jq -r '.ImportSnapshotTasks[0].SnapshotTaskDetail.SnapshotId')
echo "Bootstrap snapshot ID: ${BOOTSTRAP_SNAPSHOT}"
sleep 5
# Register the AMI
export BOOTSTRAP_AMI=$(${EC2} register-image \
--output text \
--name "rhcos-${RHCOS_VER}-bootstrap" \
--description "rhcos-${RHCOS_VER}-bootstrap" \
--block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"SnapshotId\":\"${BOOTSTRAP_SNAPSHOT}\",\"VolumeType\":\"sbp1\",\"DeleteOnTermination\":true}}]" \
--root-device-name /dev/sda1)
echo "Bootstrap AMI: ${BOOTSTRAP_AMI}"
#############################################################
# Creating Master AMI
rm -f /tmp/containers.json
cat << EOF > /tmp/containers.json
{
"Description": "Red Hat CoreOS ${RHCOS_VER} Master",
"Format": "RAW",
"UserBucket": {
"S3Bucket": "${S3_BUCKET}",
"S3Key": "$(basename ${MASTER_IMG})"
}
}
EOF
MASTER_IMPORT_ID=$( ${EC2} import-snapshot --disk-container "file:///tmp/containers.json" | jq -r '.ImportTaskId')
echo "Master Snapshot import ID: ${MASTER_IMPORT_ID}"
x="unknown"
while [[ "$x" != "completed" ]]
do
echo "Waiting for master snapshot import to complete"
x=$(${EC2} describe-import-snapshot-tasks --import-task-ids ${MASTER_IMPORT_ID} | jq -r '.ImportSnapshotTasks[0].SnapshotTaskDetail.Status')
sleep 5
done
MASTER_SNAPSHOT=$(${EC2} describe-import-snapshot-tasks --import-task-ids ${MASTER_IMPORT_ID} | jq -r '.ImportSnapshotTasks[0].SnapshotTaskDetail.SnapshotId')
echo "Master snapshot ID: ${MASTER_SNAPSHOT}"
sleep 5
# Register the AMI
export MASTER_AMI=$(${EC2} register-image \
--output text \
--name "rhcos-${RHCOS_VER}-master" \
--description "rhcos-${RHCOS_VER}-master" \
--block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"SnapshotId\":\"${MASTER_SNAPSHOT}\",\"VolumeType\":\"sbp1\",\"DeleteOnTermination\":true}}]" \
--root-device-name /dev/sda1)
echo "Master AMI: ${MASTER_AMI}"