Add add_svcs, fix nvme, add eu-north-1 (#34)
* Allow additional services on the AMI's runlevels I'm using this with my AMIs to add haveged to the boot runlevel to boost the amount of initial entropy on smaller instance types, so sshd can start in under 6s instead of over 2m. add_svcs: boot: - haveged * fix race condition with nvme-ebs /dev linking * copy nvme stuff to build target in one operation * add eu-north-1 region
This commit is contained in:
parent
80c014d702
commit
4680ecd85e
4
Makefile
4
Makefile
|
@ -24,9 +24,11 @@ build/convert:
|
|||
@echo "#!`pwd`/.py3/bin/python" > build/convert
|
||||
@echo "import yaml, json, sys" >> build/convert
|
||||
@echo "y = yaml.load(open(sys.argv[1]))" >> build/convert
|
||||
@echo "for k in ['ami_access','deploy_regions','add_repos','add_pkgs']:" >> build/convert
|
||||
@echo "for k in ['ami_access','deploy_regions','add_repos','add_pkgs','add_svcs']:" >> build/convert
|
||||
@echo " if k in y and isinstance(y[k], list):" >> build/convert
|
||||
@echo " y[k] = ','.join(str(x) for x in y[k])" >> build/convert
|
||||
@echo " if k in y and isinstance(y[k], dict):" >> build/convert
|
||||
@echo " y[k] = ':'.join(str(l) + '=' + ','.join(str(s) for s in ss) for l, ss in y[k].items())" >> build/convert
|
||||
@echo "json.dump(y, sys.stdout, indent=4, separators=(',', ': '))" >> build/convert
|
||||
@chmod +x build/convert
|
||||
|
||||
|
|
|
@ -54,13 +54,10 @@ builders:
|
|||
|
||||
provisioners:
|
||||
- type: "file"
|
||||
source: "nvme-ebs-links.sh"
|
||||
destination: "/tmp/"
|
||||
- type: "file"
|
||||
source: "nvme-ebs-mdev.conf"
|
||||
destination: "/tmp/"
|
||||
source: "nvme/"
|
||||
destination: "/tmp"
|
||||
- type: "shell"
|
||||
script: "make_ami.sh"
|
||||
environment_vars:
|
||||
- "ALPINE_RELEASE={{user `alpine_release`}}"
|
||||
execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}''"'
|
||||
execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}'' ''{{user `add_svcs`}}''"'
|
||||
|
|
15
make_ami.sh
15
make_ami.sh
|
@ -157,7 +157,7 @@ install_core_packages() {
|
|||
setup_mdev() {
|
||||
local target="$1"
|
||||
|
||||
cp -a /tmp/nvme-ebs-links.sh "$target"/lib/mdev
|
||||
cp /tmp/nvme-ebs-links "$target"/lib/mdev
|
||||
sed -n -i -e '/# fallback/r /tmp/nvme-ebs-mdev.conf' -e 1x -e '2,${x;p}' -e '${x;p}' "$target"/etc/mdev.conf
|
||||
}
|
||||
|
||||
|
@ -229,11 +229,18 @@ EOF
|
|||
|
||||
enable_services() {
|
||||
local target="$1"
|
||||
local add_svcs="$2"
|
||||
|
||||
rc_add "$target" default sshd chronyd networking tiny-ec2-bootstrap
|
||||
rc_add "$target" sysinit devfs dmesg mdev hwdrivers
|
||||
rc_add "$target" boot modules hwclock swap hostname sysctl bootmisc syslog acpid
|
||||
rc_add "$target" shutdown killprocs savecache mount-ro
|
||||
|
||||
if [ -n "$add_svcs" ]; then
|
||||
local lvl_svcs; for lvl_svcs in $(echo "$add_svcs" | tr : ' '); do
|
||||
rc_add "$target" $(echo "$lvl_svcs" | tr =, ' ')
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
create_alpine_user() {
|
||||
|
@ -295,13 +302,14 @@ version_sorted() {
|
|||
}
|
||||
|
||||
main() {
|
||||
[ "$#" -ne 2 ] && die "Expecting two parameters\nUsage: $0 '<repo>[,<repo>]' '<pkg>[,<pkg>]'"
|
||||
[ "$#" -ne 3 ] && die "Expecting three parameters\nUsage: $0 '[<repo>[,...]]' '[<pkg>[,...]]' '[<lvl>=<svc>[,...][:...]]'"
|
||||
[ "$ALPINE_RELEASE" != 'edge' ] && {
|
||||
version_sorted $MIN_RELEASE $ALPINE_RELEASE || die "Minimum alpine_release is '$MIN_RELEASE'"
|
||||
}
|
||||
|
||||
local add_repos="$1"
|
||||
local add_pkgs="$2"
|
||||
local add_svcs="$3"
|
||||
|
||||
local device="/dev/xvdf"
|
||||
local target="/mnt/target"
|
||||
|
@ -316,6 +324,7 @@ main() {
|
|||
einfo "Creating root filesystem"
|
||||
make_filesystem "$device" "$target"
|
||||
|
||||
einfo "Configuring Alpine repositories"
|
||||
setup_repositories "$target" "$add_repos"
|
||||
|
||||
einfo "Fetching Alpine signing keys"
|
||||
|
@ -338,7 +347,7 @@ main() {
|
|||
setup_mdev "$target"
|
||||
setup_fstab "$target"
|
||||
setup_networking "$target"
|
||||
enable_services "$target"
|
||||
enable_services "$target" "$add_svcs"
|
||||
create_alpine_user "$target"
|
||||
configure_ntp "$target"
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ -x /usr/sbin/nvme ] || exit
|
||||
|
||||
case $ACTION in
|
||||
add|"")
|
||||
BASE=$(echo $MDEV | sed -re 's/^(nvme[0-9]+n[0-9]+).*/\1/')
|
||||
PART=$(echo $MDEV | sed -re 's/nvme[0-9]+n[0-9]+p?//g')
|
||||
EBS=$(/usr/sbin/nvme id-ctrl "/dev/$BASE" -b 2>/dev/null | dd bs=32 skip=96 count=1 2>/dev/null | tr -d ' ')
|
||||
EBS=${EBS#/dev/}$PART
|
||||
ln -sf $MDEV ${EBS/xvd/sd}
|
||||
ln -sf $MDEV ${EBS/sd/xvd}
|
||||
;;
|
||||
remove)
|
||||
for TARGET in sd* xvd*
|
||||
do
|
||||
[ "$(readlink $TARGET 2>/dev/null)" = $MDEV ] && rm -f $TARGET
|
||||
done
|
||||
;;
|
||||
esac
|
|
@ -1,3 +0,0 @@
|
|||
# ebs nvme links
|
||||
nvme[0-9]+n[0-9]+.* root:root 0660 */lib/mdev/nvme-ebs-links.sh
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ -x /usr/sbin/nvme ] || exit
|
||||
|
||||
case $ACTION in
|
||||
add|"")
|
||||
BASE=$(echo $MDEV | sed -re 's/^(nvme[0-9]+n[0-9]+).*/\1/')
|
||||
PART=$(echo $MDEV | sed -re 's/nvme[0-9]+n[0-9]+p?//g')
|
||||
until [ -n "$EBS" ]; do
|
||||
EBS=$(/usr/sbin/nvme id-ctrl "/dev/$BASE" -b 2>/dev/null | dd bs=32 skip=96 count=1 2>/dev/null | tr -d ' ')
|
||||
done
|
||||
EBS=${EBS#/dev/}$PART
|
||||
ln -sf "$MDEV" "${EBS/xvd/sd}"
|
||||
ln -sf "$MDEV" "${EBS/sd/xvd}"
|
||||
;;
|
||||
remove)
|
||||
for TARGET in sd* xvd*
|
||||
do
|
||||
[ "$(readlink $TARGET 2>/dev/null)" = "$MDEV" ] && rm -f "$TARGET"
|
||||
done
|
||||
;;
|
||||
esac
|
|
@ -0,0 +1,3 @@
|
|||
# ebs nvme links
|
||||
nvme[0-9]+n[0-9]+.* root:root 0660 */lib/mdev/nvme-ebs-links
|
||||
|
|
@ -36,6 +36,13 @@ add_repos:
|
|||
# List of additional packages to add to the AMI.
|
||||
add_pkgs:
|
||||
|
||||
# Additional services to start at the specified level.
|
||||
add_svcs:
|
||||
# boot:
|
||||
# - service1
|
||||
# default:
|
||||
# - service2
|
||||
|
||||
# Size of the AMI image (in GiB).
|
||||
volume_size: "1"
|
||||
|
||||
|
@ -55,6 +62,7 @@ deploy_regions:
|
|||
- "us-west-2"
|
||||
- "ca-central-1"
|
||||
- "eu-central-1"
|
||||
- "eu-north-1"
|
||||
- "eu-west-1"
|
||||
- "eu-west-2"
|
||||
- "eu-west-3"
|
||||
|
|
Loading…
Reference in New Issue