aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--alpine-ami.yaml9
-rwxr-xr-xmake_ami.sh15
-rwxr-xr-xnvme-ebs-links.sh20
-rw-r--r--nvme-ebs-mdev.conf3
-rwxr-xr-xnvme/nvme-ebs-links22
-rw-r--r--nvme/nvme-ebs-mdev.conf3
-rw-r--r--variables.yaml-default8
8 files changed, 51 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index f3e4c8a..6a76c0a 100644
--- a/Makefile
+++ b/Makefile
@@ -24,9 +24,11 @@ build/convert:
24 @echo "#!`pwd`/.py3/bin/python" > build/convert 24 @echo "#!`pwd`/.py3/bin/python" > build/convert
25 @echo "import yaml, json, sys" >> build/convert 25 @echo "import yaml, json, sys" >> build/convert
26 @echo "y = yaml.load(open(sys.argv[1]))" >> build/convert 26 @echo "y = yaml.load(open(sys.argv[1]))" >> build/convert
27 @echo "for k in ['ami_access','deploy_regions','add_repos','add_pkgs']:" >> build/convert 27 @echo "for k in ['ami_access','deploy_regions','add_repos','add_pkgs','add_svcs']:" >> build/convert
28 @echo " if k in y and isinstance(y[k], list):" >> build/convert 28 @echo " if k in y and isinstance(y[k], list):" >> build/convert
29 @echo " y[k] = ','.join(str(x) for x in y[k])" >> build/convert 29 @echo " y[k] = ','.join(str(x) for x in y[k])" >> build/convert
30 @echo " if k in y and isinstance(y[k], dict):" >> build/convert
31 @echo " y[k] = ':'.join(str(l) + '=' + ','.join(str(s) for s in ss) for l, ss in y[k].items())" >> build/convert
30 @echo "json.dump(y, sys.stdout, indent=4, separators=(',', ': '))" >> build/convert 32 @echo "json.dump(y, sys.stdout, indent=4, separators=(',', ': '))" >> build/convert
31 @chmod +x build/convert 33 @chmod +x build/convert
32 34
diff --git a/alpine-ami.yaml b/alpine-ami.yaml
index 5991115..a4ba2c0 100644
--- a/alpine-ami.yaml
+++ b/alpine-ami.yaml
@@ -54,13 +54,10 @@ builders:
54 54
55provisioners: 55provisioners:
56 - type: "file" 56 - type: "file"
57 source: "nvme-ebs-links.sh" 57 source: "nvme/"
58 destination: "/tmp/" 58 destination: "/tmp"
59 - type: "file"
60 source: "nvme-ebs-mdev.conf"
61 destination: "/tmp/"
62 - type: "shell" 59 - type: "shell"
63 script: "make_ami.sh" 60 script: "make_ami.sh"
64 environment_vars: 61 environment_vars:
65 - "ALPINE_RELEASE={{user `alpine_release`}}" 62 - "ALPINE_RELEASE={{user `alpine_release`}}"
66 execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}''"' 63 execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}'' ''{{user `add_svcs`}}''"'
diff --git a/make_ami.sh b/make_ami.sh
index b5097ab..c8dde78 100755
--- a/make_ami.sh
+++ b/make_ami.sh
@@ -157,7 +157,7 @@ install_core_packages() {
157setup_mdev() { 157setup_mdev() {
158 local target="$1" 158 local target="$1"
159 159
160 cp -a /tmp/nvme-ebs-links.sh "$target"/lib/mdev 160 cp /tmp/nvme-ebs-links "$target"/lib/mdev
161 sed -n -i -e '/# fallback/r /tmp/nvme-ebs-mdev.conf' -e 1x -e '2,${x;p}' -e '${x;p}' "$target"/etc/mdev.conf 161 sed -n -i -e '/# fallback/r /tmp/nvme-ebs-mdev.conf' -e 1x -e '2,${x;p}' -e '${x;p}' "$target"/etc/mdev.conf
162} 162}
163 163
@@ -229,11 +229,18 @@ EOF
229 229
230enable_services() { 230enable_services() {
231 local target="$1" 231 local target="$1"
232 local add_svcs="$2"
232 233
233 rc_add "$target" default sshd chronyd networking tiny-ec2-bootstrap 234 rc_add "$target" default sshd chronyd networking tiny-ec2-bootstrap
234 rc_add "$target" sysinit devfs dmesg mdev hwdrivers 235 rc_add "$target" sysinit devfs dmesg mdev hwdrivers
235 rc_add "$target" boot modules hwclock swap hostname sysctl bootmisc syslog acpid 236 rc_add "$target" boot modules hwclock swap hostname sysctl bootmisc syslog acpid
236 rc_add "$target" shutdown killprocs savecache mount-ro 237 rc_add "$target" shutdown killprocs savecache mount-ro
238
239 if [ -n "$add_svcs" ]; then
240 local lvl_svcs; for lvl_svcs in $(echo "$add_svcs" | tr : ' '); do
241 rc_add "$target" $(echo "$lvl_svcs" | tr =, ' ')
242 done
243 fi
237} 244}
238 245
239create_alpine_user() { 246create_alpine_user() {
@@ -295,13 +302,14 @@ version_sorted() {
295} 302}
296 303
297main() { 304main() {
298 [ "$#" -ne 2 ] && die "Expecting two parameters\nUsage: $0 '<repo>[,<repo>]' '<pkg>[,<pkg>]'" 305 [ "$#" -ne 3 ] && die "Expecting three parameters\nUsage: $0 '[<repo>[,...]]' '[<pkg>[,...]]' '[<lvl>=<svc>[,...][:...]]'"
299 [ "$ALPINE_RELEASE" != 'edge' ] && { 306 [ "$ALPINE_RELEASE" != 'edge' ] && {
300 version_sorted $MIN_RELEASE $ALPINE_RELEASE || die "Minimum alpine_release is '$MIN_RELEASE'" 307 version_sorted $MIN_RELEASE $ALPINE_RELEASE || die "Minimum alpine_release is '$MIN_RELEASE'"
301 } 308 }
302 309
303 local add_repos="$1" 310 local add_repos="$1"
304 local add_pkgs="$2" 311 local add_pkgs="$2"
312 local add_svcs="$3"
305 313
306 local device="/dev/xvdf" 314 local device="/dev/xvdf"
307 local target="/mnt/target" 315 local target="/mnt/target"
@@ -316,6 +324,7 @@ main() {
316 einfo "Creating root filesystem" 324 einfo "Creating root filesystem"
317 make_filesystem "$device" "$target" 325 make_filesystem "$device" "$target"
318 326
327 einfo "Configuring Alpine repositories"
319 setup_repositories "$target" "$add_repos" 328 setup_repositories "$target" "$add_repos"
320 329
321 einfo "Fetching Alpine signing keys" 330 einfo "Fetching Alpine signing keys"
@@ -338,7 +347,7 @@ main() {
338 setup_mdev "$target" 347 setup_mdev "$target"
339 setup_fstab "$target" 348 setup_fstab "$target"
340 setup_networking "$target" 349 setup_networking "$target"
341 enable_services "$target" 350 enable_services "$target" "$add_svcs"
342 create_alpine_user "$target" 351 create_alpine_user "$target"
343 configure_ntp "$target" 352 configure_ntp "$target"
344 353
diff --git a/nvme-ebs-links.sh b/nvme-ebs-links.sh
deleted file mode 100755
index ca8c4f6..0000000
--- a/nvme-ebs-links.sh
+++ /dev/null
@@ -1,20 +0,0 @@
1#!/bin/sh
2
3[ -x /usr/sbin/nvme ] || exit
4
5case $ACTION in
6 add|"")
7 BASE=$(echo $MDEV | sed -re 's/^(nvme[0-9]+n[0-9]+).*/\1/')
8 PART=$(echo $MDEV | sed -re 's/nvme[0-9]+n[0-9]+p?//g')
9 EBS=$(/usr/sbin/nvme id-ctrl "/dev/$BASE" -b 2>/dev/null | dd bs=32 skip=96 count=1 2>/dev/null | tr -d ' ')
10 EBS=${EBS#/dev/}$PART
11 ln -sf $MDEV ${EBS/xvd/sd}
12 ln -sf $MDEV ${EBS/sd/xvd}
13 ;;
14 remove)
15 for TARGET in sd* xvd*
16 do
17 [ "$(readlink $TARGET 2>/dev/null)" = $MDEV ] && rm -f $TARGET
18 done
19 ;;
20esac
diff --git a/nvme-ebs-mdev.conf b/nvme-ebs-mdev.conf
deleted file mode 100644
index 2d60927..0000000
--- a/nvme-ebs-mdev.conf
+++ /dev/null
@@ -1,3 +0,0 @@
1# ebs nvme links
2nvme[0-9]+n[0-9]+.* root:root 0660 */lib/mdev/nvme-ebs-links.sh
3
diff --git a/nvme/nvme-ebs-links b/nvme/nvme-ebs-links
new file mode 100755
index 0000000..c197a73
--- /dev/null
+++ b/nvme/nvme-ebs-links
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3[ -x /usr/sbin/nvme ] || exit
4
5case $ACTION in
6 add|"")
7 BASE=$(echo $MDEV | sed -re 's/^(nvme[0-9]+n[0-9]+).*/\1/')
8 PART=$(echo $MDEV | sed -re 's/nvme[0-9]+n[0-9]+p?//g')
9 until [ -n "$EBS" ]; do
10 EBS=$(/usr/sbin/nvme id-ctrl "/dev/$BASE" -b 2>/dev/null | dd bs=32 skip=96 count=1 2>/dev/null | tr -d ' ')
11 done
12 EBS=${EBS#/dev/}$PART
13 ln -sf "$MDEV" "${EBS/xvd/sd}"
14 ln -sf "$MDEV" "${EBS/sd/xvd}"
15 ;;
16 remove)
17 for TARGET in sd* xvd*
18 do
19 [ "$(readlink $TARGET 2>/dev/null)" = "$MDEV" ] && rm -f "$TARGET"
20 done
21 ;;
22esac
diff --git a/nvme/nvme-ebs-mdev.conf b/nvme/nvme-ebs-mdev.conf
new file mode 100644
index 0000000..c30b6fd
--- /dev/null
+++ b/nvme/nvme-ebs-mdev.conf
@@ -0,0 +1,3 @@
1# ebs nvme links
2nvme[0-9]+n[0-9]+.* root:root 0660 */lib/mdev/nvme-ebs-links
3
diff --git a/variables.yaml-default b/variables.yaml-default
index 668233a..d9dff95 100644
--- a/variables.yaml-default
+++ b/variables.yaml-default
@@ -36,6 +36,13 @@ add_repos:
36# List of additional packages to add to the AMI. 36# List of additional packages to add to the AMI.
37add_pkgs: 37add_pkgs:
38 38
39# Additional services to start at the specified level.
40add_svcs:
41# boot:
42# - service1
43# default:
44# - service2
45
39# Size of the AMI image (in GiB). 46# Size of the AMI image (in GiB).
40volume_size: "1" 47volume_size: "1"
41 48
@@ -55,6 +62,7 @@ deploy_regions:
55 - "us-west-2" 62 - "us-west-2"
56 - "ca-central-1" 63 - "ca-central-1"
57 - "eu-central-1" 64 - "eu-central-1"
65 - "eu-north-1"
58 - "eu-west-1" 66 - "eu-west-1"
59 - "eu-west-2" 67 - "eu-west-2"
60 - "eu-west-3" 68 - "eu-west-3"