Created
January 3, 2019 15:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example
download latest OVA and verify signature
pipe transpiled ignition and embed in OVA
Now use
coreos_2019-01-03-155849UTC.ova
to deploy your machines.