Skip to content

Commit

Permalink
Create packer file for CentOS8
Browse files Browse the repository at this point in the history
* Create packer file for CentOS8 with similar logic to CentOS7
* Using dnf instead of yum as package manager everywhere

Signed-off-by: Rex <[email protected]>
  • Loading branch information
rexcsn authored and enrico-usai committed Sep 30, 2020
1 parent bbf45bf commit f37364a
Show file tree
Hide file tree
Showing 2 changed files with 311 additions and 3 deletions.
6 changes: 3 additions & 3 deletions amis/build_ami.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#
# Usage: build_ami.sh --os <os> --region <region> --partition <partition> [--public] [--custom]
# [--build-date <build-date>] [--arch <arch>]
# os: the os to build (supported values: all|centos6|centos7|alinux|alinux2|ubuntu1604|ubuntu1804)
# os: the os to build (supported values: all|centos6|centos7|centos8|alinux|alinux2|ubuntu1604|ubuntu1804)
# partition: partition to build in (supported values: commercial|govcloud|china)
# region: region to copy ami too (supported values: all|us-east-1|us-gov-west-1|...)
# custom: specifies to create the AMI from a custom AMI-id, which must be specified by variable CUSTOM_AMI_ID in the environment (optional)
Expand Down Expand Up @@ -114,7 +114,7 @@ parse_options() {
check_options() {
set -e

available_arm_os="ubuntu1804 alinux2" # subset of supported OSes for which ARM AMIs are available
available_arm_os="ubuntu1804 alinux2 centos8" # subset of supported OSes for which ARM AMIs are available
available_os="centos6 centos7 alinux ubuntu1604 ${available_arm_os}"
cwd="$(dirname $0)"
tmp_dir=$(mktemp -d)
Expand Down Expand Up @@ -222,7 +222,7 @@ do_command() {
RC=$?
done
;;
centos6|centos7|alinux|ubuntu1604|ubuntu1804|alinux2)
centos6|centos7|centos8|alinux|ubuntu1604|ubuntu1804|alinux2)
packer build -color=false -var-file="${cwd}/packer_variables.json" -only=${only} "${cwd}/packer_${_os}.json"
RC=$?
;;
Expand Down
308 changes: 308 additions & 0 deletions amis/packer_centos8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
{
"variables" : {
"parallelcluster_version" : "",
"parallelcluster_cookbook_version" : "",
"chef_version" : "",
"chef_custom_install_url" : "{{env `CHEF_CUSTOM_INSTALL_URL`}}",
"berkshelf_version" : "",
"build_for" : "{{env `BUILD_FOR`}}",
"ami_perms" : "{{env `AMI_PERMS`}}",
"build_date" : "{{env `BUILD_DATE`}}",
"cookbook_path" : "{{env `COOKBOOK_PATH`}}",
"nvidia_enabled" : "{{env `NVIDIA_ENABLED`}}",
"dcv_installed": "{{env `DCV_INSTALLED`}}",
"instance_type" : "{{env `AWS_FLAVOR_ID`}}",
"subnet_id" : "{{env `AWS_SUBNET_ID`}}",
"security_group_id" : "{{env `AWS_SECURITY_GROUP_ID`}}",
"vpc_id" : "{{env `AWS_VPC_ID`}}",
"associate_public_ip" : "{{env `ASSOCIATE_PUBLIC_IP`}}",
"ami_name_prefix" : "{{env `AMI_NAME_PREFIX`}}",
"region" : "{{env `AWS_REGION`}}",
"custom_ami_id" : "{{env `CUSTOM_AMI_ID`}}",
"custom_node_package" : "{{env `PARALLELCLUSTER_NODE_URL`}}",
"parallelcluster_ref" : "{{env `PARALLELCLUSTER_REF`}}",
"parallelcluster_cookbook_ref" : "{{env `PARALLELCLUSTER_COOKBOOK_REF`}}",
"parallelcluster_node_ref" : "{{env `PARALLELCLUSTER_NODE_REF`}}",
"ami_arch" : "{{env `AMI_ARCH`}}",
"user_data_file" : "{{env `USER_DATA_SCRIPT`}}",
"iam_instance_profile" : "{{env `AWS_IAM_PROFILE`}}"
},
"builders" : [
{
"name" : "centos8",
"type" : "amazon-ebs",
"region" : "{{user `region`}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "CentOS 8.* *",
"root-device-type": "ebs",
"architecture": "{{user `ami_arch`}}"
},
"owners": ["125523088429"],
"most_recent": true
},
"ami_regions" : "{{user `build_for`}}",
"ami_groups" : "{{user `ami_perms`}}",
"instance_type" : "{{user `instance_type`}}",
"ssh_username" : "centos",
"ssh_pty" : true,
"ami_name" : "{{user `ami_name_prefix` | clean_resource_name}}aws-parallelcluster-{{user `parallelcluster_version`}}-centos8-hvm-{{user `ami_arch`}}-{{user `build_date`}}",
"subnet_id" : "{{user `subnet_id`}}",
"security_group_id" : "{{user `security_group_id`}}",
"vpc_id" : "{{user `vpc_id`}}",
"skip_region_validation" : true,
"associate_public_ip_address" : "{{user `associate_public_ip`}}",
"sriov_support" : true,
"ena_support" : true,
"shutdown_behavior" : "terminate",
"user_data_file" : "{{user `user_data_file`}}",
"iam_instance_profile" : "{{user `iam_instance_profile`}}",
"tags" : {
"parallelcluster_version" : "aws-parallelcluster-{{user `parallelcluster_version`}}",
"build_date" : "{{user `build_date`}}",
"parallelcluster_ref" : "{{user `parallelcluster_ref`}}",
"parallelcluster_cookbook_ref" : "{{user `parallelcluster_cookbook_ref`}}",
"parallelcluster_node_ref" : "{{user `parallelcluster_node_ref`}}"
},
"run_tags" : {
"parallelcluster_version" : "aws-parallelcluster-{{user `parallelcluster_version`}}",
"build_date" : "{{user `build_date`}}",
"parallelcluster_ref" : "{{user `parallelcluster_ref`}}",
"parallelcluster_cookbook_ref" : "{{user `parallelcluster_cookbook_ref`}}",
"parallelcluster_node_ref" : "{{user `parallelcluster_node_ref`}}"
},
"launch_block_device_mappings" : [
{
"device_name" : "/dev/sda1",
"volume_size" : "25",
"volume_type" : "gp2",
"delete_on_termination" : true
},
{
"device_name" : "/dev/sdb",
"no_device" : true
},
{
"device_name" : "/dev/sdc",
"no_device" : true
}
],
"ami_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"no_device" : true
},
{
"device_name" : "/dev/sdc",
"no_device" : true
}
]
},
{
"name" : "custom-centos8",
"type" : "amazon-ebs",
"region" : "{{user `region`}}",
"source_ami": "{{user `custom_ami_id`}}",
"ami_regions" : "{{user `build_for`}}",
"ami_groups" : "{{user `ami_perms`}}",
"instance_type" : "{{user `instance_type`}}",
"ssh_username" : "centos",
"ssh_pty" : true,
"ami_name" : "{{user `ami_name_prefix` | clean_resource_name}}aws-parallelcluster-{{user `parallelcluster_version`}}-centos8-hvm-{{user `ami_arch`}}-{{user `build_date`}}",
"subnet_id" : "{{user `subnet_id`}}",
"vpc_id" : "{{user `vpc_id`}}",
"skip_region_validation" : true,
"associate_public_ip_address" : "{{user `associate_public_ip`}}",
"sriov_support" : true,
"ena_support" : true,
"shutdown_behavior" : "terminate",
"user_data_file" : "{{user `user_data_file`}}",
"iam_instance_profile" : "{{user `iam_instance_profile`}}",
"tags" : {
"parallelcluster_version" : "aws-parallelcluster-{{user `parallelcluster_version`}}",
"build_date" : "{{user `build_date`}}"
},
"run_tags" : {
"Name": "Packer Builder {{user `custom_ami_id`}}",
"parallelcluster_version" : "aws-parallelcluster-{{user `parallelcluster_version`}}",
"build_date" : "{{user `build_date`}}"
},
"launch_block_device_mappings" : [
{
"device_name" : "/dev/sda1",
"volume_type" : "gp2",
"delete_on_termination" : true
},
{
"device_name" : "/dev/sdb",
"no_device" : true
},
{
"device_name" : "/dev/sdc",
"no_device" : true
}
],
"ami_block_device_mappings" : [
{
"device_name" : "/dev/sdb",
"no_device" : true
},
{
"device_name" : "/dev/sdc",
"no_device" : true
}
]
}
],
"provisioners" : [
{
"type" : "shell",
"inline" : [
"sudo dnf -y install epel-release",
"sudo /bin/sed -r -i -e 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"
]
},
{
"type" : "shell",
"only": ["centos8"],
"inline" : [
"sudo /bin/sed -r -i -e 's/GRUB_CMDLINE_LINUX=\"(.*)\"/GRUB_CMDLINE_LINUX=\"\\1 rd.driver.blacklist=nouveau nouveau.modeset=0\"/' /etc/default/grub",
"sudo grub2-mkconfig -o /boot/grub2/grub.cfg"
]
},
{
"type" : "shell",
"inline" : [
"sudo dnf -y groupinstall development && sudo dnf -y install curl wget jq"
]
},
{
"type" : "file",
"source" : "{{user `cookbook_path`}}",
"destination" : "/tmp/cookbook"
},
{
"type" : "shell",
"inline" : [
"set -x",
"region=\"{{user `region`}}\"",
"chef_install_url=\"https://${region}-aws-parallelcluster.s3.${region}.amazonaws.com$([ \"${region}\" != \"${region#cn-*}\" ] && echo \".cn\" || exit 0)/archives/cinc/cinc-install.sh\"",
"[ -n \"{{user `chef_custom_install_url`}}\" ] && chef_install_url=\"{{user `chef_custom_install_url`}}\"",
"curl --retry 3 -L ${chef_install_url} | sudo bash -s -- -v {{user `chef_version`}}"
]
},
{
"type" : "shell",
"inline" : [
"sudo /opt/cinc/embedded/bin/gem install --no-document berkshelf:{{user `berkshelf_version`}}"
]
},
{
"type" : "shell",
"inline" : [
"set -x",
"sudo /opt/cinc/embedded/bin/berks vendor /etc/chef/cookbooks --berksfile /tmp/cookbook/Berksfile",
"sudo chown -R root:root /etc/chef"
]
},
{
"type" : "chef-solo",
"only": ["centos8"],
"remote_cookbook_paths" : [
"/etc/chef/cookbooks"
],
"skip_install" : "true",
"execute_command" : "sudo chef-client -z --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
"json" : {
"cfncluster" : {
"default_pre_reboot" : "false"
}
},
"run_list" : [
"aws-parallelcluster::_default_pre"
]
},
{
"type" : "shell",
"only": ["centos8"],
"expect_disconnect" : "true",
"inline" : [
"sudo reboot"
]
},
{
"type" : "chef-solo",
"only": ["centos8"],
"pause_before": "2m",
"json" : {
"cfncluster" : {
"cfn_region": "{{user `region`}}",
"nvidia" : {
"enabled" : "{{user `nvidia_enabled`}}"
},
"dcv": {
"installed" : "{{user `dcv_installed`}}"
},
"custom_node_package" : "{{user `custom_node_package`}}",
"cfn_base_os" : "centos8"
}
},
"remote_cookbook_paths" : [
"/etc/chef/cookbooks"
],
"skip_install" : "true",
"execute_command" : "sudo chef-client -z --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
"run_list" : [
"aws-parallelcluster::default"
]
},
{
"type" : "chef-solo",
"only": ["custom-centos8"],
"remote_cookbook_paths" : [
"/etc/chef/cookbooks"
],
"json" : {
"cfncluster" : {
"cfn_base_os" : "centos8"
}
},
"skip_install" : "true",
"execute_command" : "sudo chef-client -z --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
"run_list" : [
"aws-parallelcluster::default"
]
},
{
"type" : "shell",
"inline" : [
"region=\"{{user `region`}}\"",
"bucket=\"s3.amazonaws.com\"",
"[[ ${region} =~ ^cn- ]] && bucket=\"s3.cn-north-1.amazonaws.com.cn/cn-north-1-aws-parallelcluster\"",
"curl --retry 3 -L -o /tmp/aws-cfn-bootstrap-latest.tar.gz https://${bucket}/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz",
"which pip2",
"if [ $? -eq 0 ]; then sudo pip2 install /tmp/aws-cfn-bootstrap-latest.tar.gz; else sudo pip install /tmp/aws-cfn-bootstrap-latest.tar.gz; fi"
]
},
{
"type" : "shell",
"inline" : [
"sudo rm -rf /tmp/* /var/tmp/* && sudo rm -f /root/.ssh/authorized_keys && rm -f ~/.ssh/authorized_keys",
"echo aws-parallelcluster-{{user `parallelcluster_version`}} | sudo tee /opt/parallelcluster/.bootstrapped"
]
},
{
"type" : "shell",
"inline" : [
"sudo sed -i -e \"s/\\s*Defaults\\s\\s*requiretty//# Defaults requiretty/\" /etc/sudoers"
]
},
{
"type" : "shell",
"inline" : [
"sudo /usr/local/sbin/ami_cleanup.sh"
]
}
]
}

0 comments on commit f37364a

Please sign in to comment.