-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcustomize-ami.sh
executable file
·340 lines (322 loc) · 13.3 KB
/
customize-ami.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/bin/sh
#
# Copyright (c) 2017 Amazon.com, Inc. or its affiliates. All Rights
# Reserved.
#
# Additional copyrights may follow
#
# Script to take a normal EC2 AMI and make it OMPI Jenkins-ified,
# intended to be run on a stock instance. This script should probably
# not be called directly (except when debugging), but instead called
# from the packer.json file included in this directory. Packer will
# automate creating all current AMIs, using this script to configure
# all the in-AMI bits.
#
# It is recommended that you use build-amis.sh to build a current set
# of AMIs; see build-amis.sh for usage details.
#
set -e
pandoc_x86_url="s3://ompi-jenkins-config/pandoc-2.14.2-linux-amd64.tar.gz"
pandoc_arm_url="s3://ompi-jenkins-config/pandoc-2.14.2-linux-arm64.tar.gz"
awscli_x86_url="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
awscli_arm_url="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"
labels="ec2"
os=`uname -s`
arch=`uname -m`
if test "${os}" = "Linux"; then
eval "PLATFORM_ID=`sed -n 's/^ID=//p' /etc/os-release`"
eval "VERSION_ID=`sed -n 's/^VERSION_ID=//p' /etc/os-release`"
else
PLATFORM_ID=`uname -s`
VERSION_ID=`uname -r`
fi
echo "==> Platform: $PLATFORM_ID"
echo "==> Version: $VERSION_ID"
echo "==> Architecture: $arch"
OPTIND=1 # Reset in case getopts has been used previously in the shell.
run_test=1 # -b runs an ompi build test; useful for testing new AMIs
clean_ami=1 # -t enables testing mode, where the AMI isn't cleaned up
# after the test (so remote logins still work)
while getopts "h?tb" opt; do
case "$opt" in
h|\?)
echo "usage: customize-ami.sh [-t]"
exit 1
;;
b)
run_test=1
;;
t)
clean_ami=0
;;
esac
done
pandoc_installed=0
sphinx_installed=0
case $PLATFORM_ID in
rhel|centos)
echo "==> Installing packages"
# RHEL's default repos only include the "base" compiler
# version, so don't worry about script version
# differentiation.
sudo yum -y update
sudo yum -y group install "Development Tools"
sudo yum -y install libevent hwloc hwloc-libs gdb
labels="${labels} linux rhel ${VERSION_ID}"
case $VERSION_ID in
7.*)
sudo yum -y install gcc gcc-c++ gcc-gfortran \
python3
( cd $HOME
curl -O https://download.java.net/java/GA/jdk23.0.1/c28985cbf10d4e648e4004050f8781aa/11/GPL/openjdk-23.0.1_linux-x64_bin.tar.gz
tar xf openjdk-23.0.1_linux-x64_bin.tar.gz
cd /usr/local
sudo cp -rf $HOME/jdk-23.0.1/* .
cd $HOME
rm -rf openjdk-23.0.1_linux-x64_bin.tar.gz jdk-23.0.1
)
labels="${labels} gcc48"
;;
8.*)
sudo yum -y install python3.8 \
gcc gcc-c++ gcc-gfortran \
java-17-openjdk-headless
sudo yum -y remove java-1.8.0-openjdk-headless
sudo alternatives --set python /usr/bin/python3
sudo pip3 install sphinx recommonmark docutils sphinx-rtd-theme
sphinx_installed=1
labels="${labels} gcc8"
;;
*)
echo "ERROR: Unknown version ${PLATFORM_ID} ${VERSION_ID}"
exit 1
;;
esac
if test "$arch" = "x86_64" ; then
awscli_url="${awscli_x86_url}"
else
awscli_url="${awscli_arm_url}"
fi
(cd /tmp && \
curl "${awscli_url}" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
sudo ./aws/install &&
rm -rf aws)
;;
amzn)
echo "==> Installing packages"
sudo yum -y update
sudo yum -y groupinstall "Development Tools"
sphinx_installed=1
labels="${labels} linux"
case $VERSION_ID in
2)
sudo yum -y install clang hwloc-devel \
python2-pip python2 python2-boto3 python3-pip python3 \
java-17-amazon-corretto-headless libevent-devel hwloc-devel \
hwloc gdb python3-pip python3-devel
sudo pip install mock
# system python3 is linked against openssl 1.0, which doesn't work with
# urllib3 2.0 or later. So pin to an older version of urllib :(.
sudo pip3 install sphinx recommonmark docutils sphinx-rtd-theme 'urllib3<2'
labels="${labels} amazon_linux_2-${arch} gcc7 clang7"
;;
*)
echo "ERROR: Unknown version ${PLATFORM_ID} ${VERSION_ID}"
exit 1
;;
esac
echo "==> Disabling Security Updates"
sed -e 's/repo_upgrade: security/repo_upgrade: none/g' /etc/cloud/cloud.cfg > /tmp/cloud.cfg.new
sudo mv -f /tmp/cloud.cfg.new /etc/cloud/cloud.cfg
;;
ubuntu)
echo "==> Installing packages"
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential gfortran \
autoconf automake libtool flex hwloc libhwloc-dev git \
awscli rman pandoc
pandoc_installed=1
sphinx_installed=1
labels="${labels} linux ubuntu_${VERSION_ID}-${arch}"
case $VERSION_ID in
18.04)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
python-boto3 python-pip \
python-mock \
openjdk-17-jre-headless \
gcc-4.8 g++-4.8 gfortran-4.8 \
gcc-5 g++-5 gfortran-5 \
gcc-6 g++-6 gfortran-6 \
gcc-7 g++-7 gfortran-7 \
gcc-8 g++-8 gfortran-8 \
clang-3.9 clang-4.0 clang-5.0 clang-6.0 \
clang-7 clang-8 clang-9
sudo pip install sphinx recommonmark docutils sphinx-rtd-theme
labels="${labels} gcc48 gcc5 gcc6 gcc7 gcc8 clang39 clang40 clang50 clang60 clang7 clang8 clang9"
if test "$arch" = "x86_64" ; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install gcc-multilib g++-multilib gfortran-multilib
labels="${labels} 32bit_builds"
fi
# Sphinx has become too old for master on Ubuntu 18, so don't try to build there.
sphinx_installed=0
;;
20.04)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
python-is-python3 python3-boto3 python3-mock \
python3-pip \
openjdk-21-jdk-headless \
gcc-7 g++-7 gfortran-7 \
gcc-8 g++-8 gfortran-8 \
gcc-9 g++-9 gfortran-9 \
gcc-10 g++-10 gfortran-10 \
clang-6.0 clang-7 clang-8 clang-9 clang-10 \
clang-format-11 bsdutils
sudo pip3 install -U sphinx recommonmark docutils sphinx-rtd-theme
labels="${labels} gcc7 gcc8 gcc9 gcc10 clang60 clang7 clang8 clang9 clang10"
if test "$arch" = "x86_64" ; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install gcc-multilib g++-multilib gfortran-multilib
labels="${labels} 32bit_builds"
fi
;;
22.04)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
python-is-python3 python3-boto3 python3-mock \
python3-pip \
openjdk-21-jre-headless \
gcc-9 g++-9 gfortran-9 \
gcc-10 g++-10 gfortran-10 \
gcc-11 g++-11 gfortran-11 \
gcc-12 g++-12 gfortran-12 \
clang-11 clang-12 clang-13 clang-14 \
clang-format-14 bsdutils
sudo pip3 install sphinx recommonmark docutils sphinx-rtd-theme
labels="${labels} gcc9 gcc10 gcc11 gcc12 clang11 clang12 clang13 clang14"
if test "$arch" = "x86_64" ; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install gcc-multilib g++-multilib gfortran-multilib
labels="${labels} 32bit_builds"
fi
;;
24.04)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
python-is-python3 python3-boto3 python3-mock \
python3-pip \
openjdk-21-jdk-headless \
gcc-9 g++-9 gfortran-9 \
gcc-10 g++-10 gfortran-10 \
gcc-11 g++-11 gfortran-11 \
gcc-12 g++-12 gfortran-12 \
clang-11 clang-12 clang-13 clang-14 \
clang-format-14 bsdutils
sudo pip3 install sphinx recommonmark docutils sphinx-rtd-theme
labels="${labels} gcc9 gcc10 gcc11 gcc12 clang11 clang12 clang13 clang14"
if test "$arch" = "x86_64" ; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install gcc-multilib g++-multilib gfortran-multilib
labels="${labels} 32bit_builds"
fi
;;
*)
echo "ERROR: Unknown version ${PLATFORM_ID} ${VERSION_ID}"
exit 1
;;
esac
echo "==> Disabling Security Updates"
sed -e 's/APT::Periodic::Update-Package-Lists "1";/APT::Periodic::Update-Package-Lists "0";/g' /etc/apt/apt.conf.d/20auto-upgrades | sed -e 's/APT::Periodic::Unattended-Upgrade "1";/APT::Periodic::Unattended-Upgrade "0";/g' > /tmp/20auto-upgrades
sudo mv -f /tmp/20auto-upgrades /etc/apt/apt.conf.d/20auto-upgrades
;;
sles)
sudo zypper -n update
sudo zypper -n install gcc gcc-c++ gcc-fortran \
autoconf automake libtool flex make gdb git bzip2
labels="${labels} linux sles_${VERSION_ID}-${arch}"
sphinx_installed=1
case $VERSION_ID in
15.*)
sudo zypper -n install \
java-11-openjdk \
python3-boto python3-boto3 python3-mock \
python3-pip
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo pip install sphinx recommonmark docutils sphinx-rtd-theme
;;
*)
echo "ERROR: Unknown version ${PLATFORM_ID} ${VERSION_ID}"
exit 1
;;
esac
;;
FreeBSD)
labels="${labels} freebsd-${VERSION_ID}-${arch}"
su -m root -c 'pkg install -y sudo'
if ! grep -q '^%wheel ALL=(ALL) NOPASSWD: ALL' /usr/local/etc/sudoers ; then
echo "--> Updating sudoers"
su -m root -c 'echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /usr/local/etc/sudoers'
else
echo "--> Skipping sudoers update"
fi
sudo pkg install -y openjdk17 autoconf automake libtool gcc wget curl git hs-pandoc
pandoc_installed=1
if ! grep -q '/dev/fd' /etc/fstab ; then
echo "Adding /dev/fd entry to /etc/fstab"
sudo sh -c 'echo "fdesc /dev/fd fdescfs rw 0 0" >> /etc/fstab'
fi
if ! grep -q '/proc' /etc/fstab ; then
echo "Adding /proc entry to /etc/fstab"
sudo sh -c 'echo "proc /proc procfs rw 0 0 " >> /etc/fstab'
fi
;;
*)
echo "ERROR: Unkonwn platform ${PLATFORM_ID}"
exit 1
esac
if test $pandoc_installed -eq 0 ; then
if test $arch == "x86_64" ; then
pandoc_url=${pandoc_x86_url}
else
pandoc_url=${pandoc_arm_url}
fi
pandoc_tarname=`basename ${pandoc_url}`
aws s3 cp "${pandoc_url}" "${pandoc_tarname}"
tar xf "${pandoc_tarname}"
# Pandoc does not name its directories exactly the same name
# as the tarball. Sigh.
pandoc_dir=`find . -maxdepth 1 -name "pandoc*" -type d -print`
sudo cp "${pandoc_dir}/bin/pandoc" "/usr/local/bin/pandoc"
rm -rf "${pandoc_tarname}" "${pandoc_dir}"
fi
if test $run_test != 0; then
# for these tests, fail the script if a test fails
set -e
echo "==> Running Compile test"
cd
git clone --recurse-submodules https://github.com/open-mpi/ompi.git
cd ompi
./autogen.pl
./configure --prefix=$HOME/install
if test "$sphinx_installed" = "1" ; then
make -j 4 distcheck
else
make -j 4 all
make check
make install
fi
cd $HOME
rm -rf ${HOME}/ompi ${HOME}/install
echo "==> SUCCESS! Open MPI compiled!"
fi
if test "${clean_ami}" != "0" ; then
echo "==> Cleaning instance"
if test "${PLATFORM_ID}" = "FreeBSD" ; then
sudo touch /firstboot
fi
rm -rf ${HOME}/.ssh ${HOME}/.history ${HOME}/.bash_history ${HOME}/.sudo_as_admin_successful ${HOME}/.cache ${HOME}/.oracle_jre_usage
sudo rm -rf /var/log/*
sudo rm -f /etc/ssh/ssh_host*
sudo rm -rf /root/* ~root/.ssh ~root/.history ~root/.bash_history
echo "Recommended labels: ${labels}"
else
echo "Skipped cleaning instance. Do not use to build AMI!"
fi
echo "==> All done!"
# cleanup phase