diff options
author | Jake Buchholz <tomalok@gmail.com> | 2020-08-09 21:27:28 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-08-12 18:12:22 -0700 |
commit | d593de3833014b4e83d7693a5e6691013122eb0e (patch) | |
tree | 4342dccef141275877971c8e0773bde41bf5b9da | |
parent | d765bd4ab77fc3ef7c3d66d644016c5b07e8ddab (diff) | |
download | alpine-ec2-ami-d593de3833014b4e83d7693a5e6691013122eb0e.tar.bz2 alpine-ec2-ami-d593de3833014b4e83d7693a5e6691013122eb0e.tar.xz alpine-ec2-ami-d593de3833014b4e83d7693a5e6691013122eb0e.zip |
Optional Additional Setup
Profiles can specify 'setup_script' to do additional things. If additional files/dirs are required, a 'setup_copy' map will copy them to the build instance so that 'setup_script' can use/install them.
TBD: docs.
-rw-r--r-- | packer.conf | 4 | ||||
-rwxr-xr-x | scripts/builder.py | 21 | ||||
-rwxr-xr-x | scripts/setup-ami | 17 |
3 files changed, 38 insertions, 4 deletions
diff --git a/packer.conf b/packer.conf index 04962bf..a62d7de 100644 --- a/packer.conf +++ b/packer.conf | |||
@@ -69,8 +69,8 @@ builders = [ | |||
69 | provisioners = [ | 69 | provisioners = [ |
70 | { | 70 | { |
71 | type = "file" | 71 | type = "file" |
72 | source = "../scripts/nvme-ebs-links" | 72 | source = "./profile/{{user `profile`}}/{{user `profile_build`}}/setup-ami.d" |
73 | destination = "/tmp/nvme-ebs-links" | 73 | destination = "/tmp/setup-ami.d" |
74 | } | 74 | } |
75 | { | 75 | { |
76 | type = "shell" | 76 | type = "shell" |
diff --git a/scripts/builder.py b/scripts/builder.py index c249ba9..ea23d99 100755 --- a/scripts/builder.py +++ b/scripts/builder.py | |||
@@ -513,16 +513,35 @@ class ConfigBuilder: | |||
513 | profile = os.path.splitext(os.path.split(file)[-1])[0] | 513 | profile = os.path.splitext(os.path.split(file)[-1])[0] |
514 | self.build_profile(profile) | 514 | self.build_profile(profile) |
515 | 515 | ||
516 | def rel_symlink(self, src_path, dest_dir, dest): | ||
517 | os.symlink( | ||
518 | os.path.relpath(src_path, dest_dir), | ||
519 | os.path.join(dest_dir, dest)) | ||
520 | |||
516 | def build_profile(self, profile): | 521 | def build_profile(self, profile): |
517 | build_config = pyhocon.ConfigFactory.parse_file( | 522 | build_config = pyhocon.ConfigFactory.parse_file( |
518 | os.path.join(self.config_path, f"{profile}.conf")) | 523 | os.path.join(self.config_path, f"{profile}.conf")) |
519 | 524 | ||
520 | for build, cfg in build_config["BUILDS"].items(): | 525 | for build, cfg in build_config["BUILDS"].items(): |
521 | build_dir = os.path.join(self.out_dir, profile, build) | 526 | build_dir = os.path.join(self.out_dir, profile, build) |
527 | setup_dir = os.path.join(build_dir, "setup-ami.d") | ||
522 | 528 | ||
523 | # Always start fresh | 529 | # Always start fresh |
524 | shutil.rmtree(build_dir, ignore_errors=True) | 530 | shutil.rmtree(build_dir, ignore_errors=True) |
525 | os.makedirs(build_dir) | 531 | os.makedirs(setup_dir) |
532 | |||
533 | # symlink nvme script | ||
534 | self.rel_symlink("scripts/nvme-ebs-links", setup_dir, "nvme-ebs-links") | ||
535 | |||
536 | # symlink additional setup_script | ||
537 | if "setup_script" in cfg.keys(): | ||
538 | self.rel_symlink(cfg["setup_script"], setup_dir, "setup_script") | ||
539 | del cfg["setup_script"] | ||
540 | |||
541 | if "setup_copy" in cfg.keys(): | ||
542 | for dst, src in cfg["setup_copy"].items(): | ||
543 | self.rel_symlink(src, setup_dir, dst) | ||
544 | del cfg["setup_copy"] | ||
526 | 545 | ||
527 | cfg["profile"] = profile | 546 | cfg["profile"] = profile |
528 | cfg["profile_build"] = build | 547 | cfg["profile_build"] = build |
diff --git a/scripts/setup-ami b/scripts/setup-ami index 1710ca9..e3c311d 100755 --- a/scripts/setup-ami +++ b/scripts/setup-ami | |||
@@ -154,7 +154,7 @@ install_core_packages() { | |||
154 | } | 154 | } |
155 | 155 | ||
156 | setup_mdev() { | 156 | setup_mdev() { |
157 | cp /tmp/nvme-ebs-links "$TARGET/lib/mdev" | 157 | cp /tmp/setup-ami.d/nvme-ebs-links "$TARGET/lib/mdev" |
158 | 158 | ||
159 | # insert nvme ebs mdev configs just above "# fallback" comment | 159 | # insert nvme ebs mdev configs just above "# fallback" comment |
160 | sed -n -i \ | 160 | sed -n -i \ |
@@ -288,6 +288,19 @@ configure_ntp() { | |||
288 | -i "$TARGET/etc/chrony/chrony.conf" | 288 | -i "$TARGET/etc/chrony/chrony.conf" |
289 | } | 289 | } |
290 | 290 | ||
291 | setup_script() { | ||
292 | if [ -f /tmp/setup-ami.d/setup_script ]; then | ||
293 | einfo "Executing additional setup script" | ||
294 | ( | ||
295 | cd /tmp/setup-ami.d | ||
296 | chmod u+x ./setup_script | ||
297 | TARGET="$TARGET" ./setup_script | ||
298 | ) | ||
299 | else | ||
300 | einfo "No additional setup script" | ||
301 | fi | ||
302 | } | ||
303 | |||
291 | cleanup() { | 304 | cleanup() { |
292 | # Sweep cruft out of the image that doesn't need to ship or will be | 305 | # Sweep cruft out of the image that doesn't need to ship or will be |
293 | # re-generated when the image boots | 306 | # re-generated when the image boots |
@@ -344,6 +357,8 @@ main() { | |||
344 | create_alpine_user | 357 | create_alpine_user |
345 | configure_ntp | 358 | configure_ntp |
346 | 359 | ||
360 | setup_script | ||
361 | |||
347 | einfo "All done, cleaning up" | 362 | einfo "All done, cleaning up" |
348 | cleanup | 363 | cleanup |
349 | } | 364 | } |