Skip to content

Commit

Permalink
Improve build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
carletes committed Apr 3, 2016
1 parent 5a357de commit af45201
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 30 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ COREOS_MD5_CHECKSUM = 2207f09699ee37e79c32aae972432059
OPENNEBULA_DATASTORE = default

PACKER_IMAGE_DIR = builds/coreos-$(COREOS_CHANNEL)-$(COREOS_VERSION)-qemu
PACKER_IMAGE = $(PACKER_IMAGE_DIR)/packer-qemu
PACKER_IMAGE_NAME = coreos-$(COREOS_CHANNEL)-$(COREOS_VERSION)
PACKER_IMAGE = $(PACKER_IMAGE_DIR)/$(PACKER_IMAGE_NAME)
PACKER_IMAGE_DEPS = \
coreos.json \
packer.sh \
Expand Down Expand Up @@ -33,9 +34,10 @@ $(PACKER_IMAGE): $(PACKER_IMAGE_DEPS)
COREOS_MD5_CHECKSUM=$(COREOS_MD5_CHECKSUM) \
PACKER_LOG=1 \
./packer.sh build coreos.json
mv $(PACKER_IMAGE_DIR)/packer-qemu $(PACKER_IMAGE)
echo "Image file $(PACKER_IMAGE) ready"

.PHONY: register clean
.PHONY: appliance register clean

OPENNEBULA_IMAGE = coreos-$(COREOS_CHANNEL)

Expand All @@ -52,5 +54,12 @@ register: $(PACKER_IMAGE)
oneimage update $(OPENNEBULA_IMAGE) --append .ec2_attrs
rm -f .ec2_attrs

appliance: $(PACKER_IMAGE)
./generate-appliance-json.py \
--output appliance.json \
$(COREOS_CHANNEL) \
$(COREOS_VERSION) \
$(PACKER_IMAGE)

clean:
rm -rf builds
130 changes: 130 additions & 0 deletions generate-appliance-json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python

"""Uploads a CoreOS image to the OpenNebula MarketPlace."""

import argparse
import hashlib
import json
import os
import sys


SHORT_DESCRIPTION_TEMPLATE = """
CoreOS %(channel)s image for KVM hosts under OpenNebula.
""".strip()

DESCRIPTION_TEMPLATE = """
Password for user `core` is disabled. You will need an SSH key in order to
log in.
This image works best with two network interfaces defined:
* The first network interface will be used as CoreOS' private IPv4
address.
* If there is a second network interface defined, it will be used as
CoreOS' public IPv4 network.
The VM template bundled with this image includes a `USER_DATA` field, with
which you may pass extra
[cloud-config](https://coreos.com/os/docs/latest/cloud-config.html)
user data to configure your CoreOS instance.
The source code for this image is available at:
<https://github.com/carletes/coreos-opennebula-image>
Contributions are most welcome!
""".strip()

IMAGE_TEMPLATE_TEXT = json.dumps({
"CONTEXT": {
"NETWORK": "YES",
"SET_HOSTNAME": "$NAME",
"SSH_PUBLIC_KEY": "$USER[SSH_PUBLIC_KEY]",
"USER_DATA": "$USER_DATA",
},
"CPU": "1",
"GRAPHICS": {
"LISTEN": "0.0.0.0",
"TYPE": "vnc"
},
"MEMORY": "512",
"OS": {
"ARCH": "x86_64"
},
"USER_INPUTS": {
"USER_DATA": "M|text|User data for `cloud-config`",
}
})


def main():
p = argparse.ArgumentParser(description=__doc__.strip())
p.add_argument("channel",
help="CoreOS channel of the image")
p.add_argument("version",
help="CoreOS version of the image")
p.add_argument("image",
help="path to the qcow2 image file to upload")
p.add_argument("--output",
help=("path to the outpu JSON file. If not given, the "
"image will not be uploaded."))

args = p.parse_args()
vars = {
"channel": args.channel,
"version": args.version,
}

hypervisor = "KVM"
image_fmt = "qcow2"
os_arch = "x86_64"
os_id = "CoreOS"
os_release = "%s (%s channel)" % (args.version, args.channel)
appliance = json.dumps({
"name": "CoreOS %s" % (args.channel,),
"short_description": SHORT_DESCRIPTION_TEMPLATE % vars,
"description": DESCRIPTION_TEMPLATE % vars,
"version": args.version,
"opennebula_version": "4.14",
"files": [
{
"name": "coreos-%s-%s" % (args.channel, args.version),
"size": str(os.stat(args.image).st_size),
"md5": md5_hash(args.image),
"compression": "none",
"driver": image_fmt,
"type": "OS",
"hypervisor": hypervisor,
"format": image_fmt,
"os-id": os_id,
"os-release": os_release,
"os-arch": os_arch
}
],
"hypervisor": hypervisor,
"format": image_fmt,
"os-id": os_id,
"os-release": os_release,
"os-arch": os_arch,
"opennebula_template": IMAGE_TEMPLATE_TEXT,
}, indent=4)

if args.output is None:
print appliance
return

with open(args.output, "w") as f:
f.write(appliance)


def md5_hash(fname):
md5 = hashlib.md5()
with open(fname, "rb") as f:
md5.update(f.read())
return md5.hexdigest()



if __name__ == "__main__":
sys.exit(main())
28 changes: 0 additions & 28 deletions upload-marketplace.sh

This file was deleted.

0 comments on commit af45201

Please sign in to comment.