diff --git a/maintainers/scripts/ec2/create-ebs-amis.py b/maintainers/scripts/ec2/create-ebs-amis.py new file mode 100755 index 00000000000..3bcd47c7f5e --- /dev/null +++ b/maintainers/scripts/ec2/create-ebs-amis.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python + +import sys +from charon import deployment +from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType +import charon.util + +depl = deployment.Deployment("./ebs-creator.json", create=True, nix_exprs=["./ebs-creator.nix"]) +depl.deploy() + +m = depl.machines['machine'] + +# Do the installation. +m.run_command("if mountpoint -q /mnt; then umount /mnt; fi") +m.run_command("mkfs.ext4 -L nixos /dev/xvdg") +m.run_command("mkdir -p /mnt") +m.run_command("mount /dev/xvdg /mnt") +m.run_command("touch /mnt/.ebs") +m.run_command("mkdir -p /mnt/etc/nixos") +m.run_command("cp /etc/nixos/configuration.nix /mnt/etc/nixos/") # FIXME +m.run_command("nixos-checkout") # FIXME +m.run_command("nixos-install") +m.run_command("umount /mnt") + +# Create a snapshot. +m.connect() +volume = m._conn.get_all_volumes([], filters={'attachment.instance-id': m._instance_id, 'attachment.device': "/dev/sdg"})[0] +snapshot = volume.create_snapshot(description="NixOS EBS root disk") +#snapshot = m._conn.get_all_snapshots(["snap-f1c9679a"])[0] +print >> sys.stderr, "created snapshot {0}".format(snapshot.id) + +# Wait for the snapshot to finish. +def check(): + status = snapshot.update() + print >> sys.stderr, "snapshot status is {0}".format(status) + return status == '100%' +charon.util.check_wait(check, max_tries=120) + +# Register the image. +aki = m._conn.get_all_images(filters={'manifest-location': '*pv-grub-hd0_1.03-x86_64*'})[0] +print >> sys.stderr, "using kernel image %s - %s" %(aki.id, aki.location) + +block_map = BlockDeviceMapping() +block_map['/dev/sda'] = BlockDeviceType(snapshot_id=snapshot.id, delete_on_termination=True) +block_map['/dev/sdb'] = BlockDeviceType(ephemeral_name="ephemeral0") +block_map['/dev/sdc'] = BlockDeviceType(ephemeral_name="ephemeral1") +block_map['/dev/sdd'] = BlockDeviceType(ephemeral_name="ephemeral2") +block_map['/dev/sde1'] = BlockDeviceType(ephemeral_name="ephemeral3") + +ami_id = m._conn.register_image( + name="nixos-x86-64-ebs-test-9", description="NixOS (x86_64) EBS test", architecture="x86_64", + root_device_name="/dev/sda", kernel_id=aki.id, block_device_map=block_map) + +print >> sys.stderr, "registered AMI {0}".format(ami_id) diff --git a/maintainers/scripts/create-amis.sh b/maintainers/scripts/ec2/create-s3-amis.sh similarity index 100% rename from maintainers/scripts/create-amis.sh rename to maintainers/scripts/ec2/create-s3-amis.sh diff --git a/maintainers/scripts/ec2/ebs-creator.nix b/maintainers/scripts/ec2/ebs-creator.nix new file mode 100644 index 00000000000..bfda4aa4156 --- /dev/null +++ b/maintainers/scripts/ec2/ebs-creator.nix @@ -0,0 +1,13 @@ +{ + network.description = "NixOS EBS creator"; + + machine = + { config, pkgs, ... }: + { deployment.targetEnv = "ec2"; + deployment.ec2.region = "eu-west-1"; + deployment.ec2.instanceType = "m1.small"; + deployment.ec2.keyPair = "eelco"; + deployment.ec2.securityGroups = [ "eelco-test" ]; + deployment.ec2.blockDeviceMapping."/dev/xvdg".size = 20; + }; +}