Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Created January 3, 2019 15:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ansemjo/04493ce197148c998bbab0d92e145500 to your computer and use it in GitHub Desktop.
Save ansemjo/04493ce197148c998bbab0d92e145500 to your computer and use it in GitHub Desktop.
Embed CoreOS ignition configuration in the released OVA for easy deployment of multiple instances on VMware.
#!/usr/bin/env bash
# Copyright (c) 2019 Anton Semjonov
# Licensed under the MIT License
# This script embeds a transpiled ignition (JSON) config in the CoreOS OVA
# as guestinfo parameters, so you can deploy several machines with the
# same configuration easily.
# required arguments / inputs
# $1 - path to ova
# stdin - ignition json
# be verbose and exit on errors
set -eux -o pipefail
# test if given file is readable
test -r "$1" && test ! -d "$1"
# read ignition from stdin and encode
ignition="$(base64 -w0)"
# use a temporary directory to extract ova
tmp="$(mktemp -d)"
tar -xv -C "$tmp" -f "$1"
pushd "$tmp"
# insert ignition in ovf
# ovf:key="guestinfo.coreos.config.data" ovf:value="">
sed -i '/"guestinfo.coreos.config.data"/s/\(ovf:value\)="[^"]*"/\1="'"$ignition"'"/' *.ovf
sed -i '/"guestinfo.coreos.config.data.encoding"/s/\(ovf:value\)="[^"]*"/\1="base64"/' *.ovf
# recalculate checksum
mf=$(ls -1 *.mf | head -1)
rm "$mf"
sha1sum --tag * > "$mf"
# repack ova
popd
output="coreos_$(date --utc +%F-%H%M%S%Z).ova"
(cd "$tmp" && tar cv *) > "$output"
# remove temporary directory
rm -rf "$tmp"
@ansemjo
Copy link
Author

ansemjo commented Jan 3, 2019

Usage example

download latest OVA and verify signature

$ curl --remote-name-all https://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova{,.sig}
[...]
$ gpg --verify coreos_production_vmware_ova.ova.sig
[...]
gpg: Signature made Sun 16 Dec 2018 01:32:15 CET
gpg:                using RSA key 4D7241B14AA47290515D6A8D7FB32ABC0638EB2F
gpg: Good signature from "CoreOS Buildbot (Offical Builds) <buildbot@coreos.com>" [marginal]
[...]

pipe transpiled ignition and embed in OVA

$ ct < /path/to/ignition.yml | ./embed_ignition.sh coreos_production_vmware_ova.ova
[...]
+ output=coreos_2019-01-03-155849UTC.ova
+ cd /tmp/tmp.Uiq2C1lYod
+ tar cv coreos_production_vmware_ova_image.vmdk coreos_production_vmware_ova.mf coreos_production_vmware_ova.ovf
coreos_production_vmware_ova_image.vmdk
coreos_production_vmware_ova.mf
coreos_production_vmware_ova.ovf
+ rm -rf /tmp/tmp.Uiq2C1lYod

Now use coreos_2019-01-03-155849UTC.ova to deploy your machines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment