-
Notifications
You must be signed in to change notification settings - Fork 312
/
parallelcluster.yaml
314 lines (277 loc) · 11 KB
/
parallelcluster.yaml
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
name: PCluster
description: Bake PCluster AMI
schemaVersion: 1.0
constants:
- ChefVersion:
type: string
value: 18.4.12
- BerkshelfVersion:
type: string
value: 8.0.7
- FailExitCode:
type: string
value: 1
phases:
- name: build
steps:
# Get AWS Region
- name: AWSRegion
action: ExecuteBash
inputs:
commands:
- |
set -v
echo ${AWS::Region}
# Get Cookbook name
- name: PClusterCookbookVersionName
action: ExecuteBash
inputs:
commands:
- |
set -v
echo "aws-parallelcluster-cookbook-${CfnParamCookbookVersion}"
# Get Cookbook Url
- name: CookbookUrl
action: ExecuteBash
inputs:
commands:
- |
set -v
COOKBOOK_URL="https://${AWS::Region}-aws-parallelcluster.s3.${AWS::Region}.${AWS::URLSuffix}/parallelcluster/${CfnParamCookbookVersion}/cookbooks/{{ build.PClusterCookbookVersionName.outputs.stdout }}.tgz"
[ -n "${CfnParamChefCookbook}" ] && COOKBOOK_URL="${CfnParamChefCookbook}"
echo "${!COOKBOOK_URL}"
# Get Cinc Url
- name: CincUrl
action: ExecuteBash
inputs:
commands:
- |
set -v
CINC_URL="https://${AWS::Region}-aws-parallelcluster.s3.${AWS::Region}.${AWS::URLSuffix}/archives/cinc/cinc-install-1.3.0.sh"
[ -n "${CfnParamCincInstaller}" ] && CINC_URL="${CfnParamCincInstaller}"
echo "${!CINC_URL}"
# Check input base AMI OS and get OS information, the output should be like amzn.2 | ubuntu.20.04 | ubuntu.22.04 | rhel.8.7 | rocky.8.8
- name: OperatingSystemRelease
action: ExecuteBash
inputs:
commands:
- |
set -v
FILE=/etc/os-release
if [ -e ${!FILE} ]; then
. ${!FILE}
echo "${!ID}${!VERSION_ID:+.${!VERSION_ID}}"
else
echo "The file '${!FILE}' does not exist. Failing build."
exit {{ FailExitCode }}
fi
# Get uniformed OS name
- name: OperatingSystemName
action: ExecuteBash
inputs:
commands:
- |
set -v
RELEASE='{{ build.OperatingSystemRelease.outputs.stdout }}'
if [ `echo "${!RELEASE}" | grep -w '^amzn\.2'` ]; then
OS='alinux2'
elif [ `echo "${!RELEASE}" | grep -w '^amzn\.2023'` ]; then
OS='alinux2023'
elif [ `echo "${!RELEASE}" | grep '^ubuntu\.20'` ]; then
OS='ubuntu2004'
elif [ `echo "${!RELEASE}" | grep '^ubuntu\.22'` ]; then
OS='ubuntu2204'
elif [ `echo "${!RELEASE}" | grep '^rhel\.8'` ]; then
OS='rhel8'
elif [ `echo "${!RELEASE}" | grep '^rocky\.8'` ]; then
OS='rocky8'
elif [ `echo "${!RELEASE}" | grep '^rhel\.9'` ]; then
OS='rhel9'
elif [ `echo "${!RELEASE}" | grep '^rocky\.9'` ]; then
OS='rocky9'
else
echo "Operating System '${!RELEASE}' is not supported. Failing build."
exit {{ FailExitCode }}
fi
echo ${!OS}
# Get platform name
- name: PlatformName
action: ExecuteBash
inputs:
commands:
- |
set -v
OS='{{ build.OperatingSystemName.outputs.stdout }}'
if [ `echo "${!OS}" | grep -E '^(alinux|centos|rhel|rocky)'` ]; then
PLATFORM='RHEL'
elif [ `echo "${!OS}" | grep -E '^ubuntu'` ]; then
PLATFORM='DEBIAN'
fi
echo ${!PLATFORM}
# Get input base AMI Architecture
- name: OperatingSystemArchitecture
action: ExecuteBash
inputs:
commands:
- |
set -v
ARCH=$(uname -m)
case ${!ARCH} in
'x86_64')
echo 'x86_64'
;;
'aarch64')
echo 'arm64'
;;
*)
echo "The '${!ARCH}' architecture is not supported. Failing build."
exit {{ FailExitCode }}
;;
esac
# Check if input base AMI has supported OS
- name: IsOperatingSystemSupported
action: ExecuteBash
inputs:
commands:
- |
set -v
if [ ${CfnParamUpdateOsAndReboot} == false ]; then
RELEASE='{{ build.OperatingSystemRelease.outputs.stdout }}'
if [ `echo "${!RELEASE}" | grep -Ev '^(amzn|centos|ubuntu|rhel|rocky)'` ]; then
echo "This component does not support '${!RELEASE}'. Failing build."
exit {{ FailExitCode }}
fi
# This component only supports aarch64 CPUs on Amazon Linux 2, Ubuntu2004, Ubuntu2204, RHEL8, Rocky8, RHEL9 and Rocky9
ARCH=$(uname -m)
if [[ `echo ${!ARCH}` == 'aarch64' ]]; then
if [ `echo "${!RELEASE}" | grep -Ev '^(amzn\.2|amzn\.2023|ubuntu\.20\.04|ubuntu\.22\.04|rhel\.8|rocky\.8|rhel\.9|rocky\.9)'` ]; then
echo "This component does not support '${!RELEASE}' on ARM64 CPUs. Failing build."
exit {{ FailExitCode }}
fi
fi
fi
# Install prerequisite OS packages
- name: InstallPrerequisite
action: ExecuteBash
inputs:
commands:
- |
set -v
OS='{{ build.OperatingSystemName.outputs.stdout }}'
PLATFORM='{{ build.PlatformName.outputs.stdout }}'
if [[ ${!PLATFORM} == RHEL ]]; then
yum -y groupinstall development && sudo yum -y install curl wget jq
if [[ ${!OS} =~ ^centos ]]; then
/bin/sed -r -i -e 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
elif [[ ${!PLATFORM} == DEBIAN ]]; then
if [[ "${CfnParamUpdateOsAndReboot}" == "false" ]]; then
# disable apt-daily.timer to avoid dpkg lock
flock $(apt-config shell StateDir Dir::State/d | sed -r "s/.*'(.*)\/?'$/\1/")/daily_lock systemctl disable --now apt-daily.timer apt-daily.service apt-daily-upgrade.timer apt-daily-upgrade.service
# disable unattended upgrades
sed "/Update-Package-Lists/s/\"1\"/\"0\"/; /Unattended-Upgrade/s/\"1\"/\"0\"/;" /etc/apt/apt.conf.d/20auto-upgrades > "/etc/apt/apt.conf.d/51pcluster-unattended-upgrades"
fi
apt-cache search build-essential
apt-get clean
apt-get -y update
apt-get -y install build-essential curl wget jq
fi
# Install Cinc
- name: InstallCinc
action: ExecuteBash
inputs:
commands:
- |
set -v
PLATFORM='{{ build.PlatformName.outputs.stdout }}'
if [[ ${!PLATFORM} == RHEL ]]; then
CA_CERTS_FILE=/etc/ssl/certs/ca-bundle.crt
yum -y upgrade ca-certificates
elif [[ ${!PLATFORM} == DEBIAN ]]; then
CA_CERTS_FILE=/etc/ssl/certs/ca-certificates.crt
apt-get -y --only-upgrade install ca-certificates
fi
curl --retry 3 -L {{ build.CincUrl.outputs.stdout }} | bash -s -- -v {{ ChefVersion }}
if [[ -e ${!CA_CERTS_FILE} ]]; then
mkdir -p /opt/cinc/embedded/ssl/certs
ln -sf ${!CA_CERTS_FILE} /opt/cinc/embedded/ssl/certs/cacert.pem
fi
curl --retry 3 -L -o gems.tgz https://${AWS::Region}-aws-parallelcluster.s3.${AWS::Region}.amazonaws.com/archives/dependencies/ruby/gems.tgz
tar -xf gems.tgz
cd vendor/cache
/opt/cinc/embedded/bin/gem install --local --no-document berkshelf:{{ BerkshelfVersion }}
# Download and vendor Cookbook
- name: DownloadCookbook
action: ExecuteBash
inputs:
commands:
- |
set -v
mkdir -p /etc/chef && sudo chown -R root:root /etc/chef
curl --retry 3 -L -o /etc/chef/aws-parallelcluster-cookbook.tgz "{{ build.CookbookUrl.outputs.stdout }}"
mkdir -p /tmp/cookbooks
cd /tmp/cookbooks
tar -xzf /etc/chef/aws-parallelcluster-cookbook.tgz
export HOME="/tmp"
for dir in $(ls /tmp/cookbooks); do
cd /tmp/cookbooks/${!dir}
LANG=en_US.UTF-8 sudo /opt/cinc/embedded/bin/berks vendor /etc/chef/cookbooks --delete || (echo 'Vendoring cookbook failed.' && exit {{ FailExitCode }})
done;
- name: CreatingChefClientFile
action: CreateFile
inputs:
- path: /etc/chef/client.rb
content: |
cookbook_path ['/etc/chef/cookbooks']
overwrite: true
- name: CreatingJsonFile
action: CreateFile
inputs:
- path: /etc/parallelcluster/image_dna.json
content: |
${CfnParamChefDnaJson}
overwrite: true
- name: InstallPClusterPackages
action: ExecuteBash
inputs:
commands:
- |
set -v
echo "Calling chef-client with /etc/parallelcluster/image_dna.json"
cat /etc/parallelcluster/image_dna.json
cinc-client --local-mode --config /etc/chef/client.rb --log_level info --force-formatter --no-color --chef-zero-port 8889 --json-attributes /etc/parallelcluster/image_dna.json --override-runlist aws-parallelcluster-entrypoints::install
- name: CreateBootstrapFile
action: CreateFile
inputs:
- path: /opt/parallelcluster/.bootstrapped
content: |
{{ build.PClusterCookbookVersionName.outputs.stdout }}
overwrite: true
- name: KeepSSM
action: ExecuteBash
inputs:
commands:
- |
set -v
if [[ -f /tmp/imagebuilder_service/ssm_installed ]]; then
echo "Keeping SSM agent installed"
rm -rf /tmp/imagebuilder_service/ssm_installed
else
echo "SSM agent is installed by default"
fi
- name: AmiCleanup
action: ExecuteBash
inputs:
commands:
- |
set -v
/usr/local/sbin/ami_cleanup.sh
- name: validate
steps:
- name: PClusterValidate
action: ExecuteBash
inputs:
commands:
- |
echo "Check ParallelCluster software stack has been installed"