Author: eelco
Date: Thu Apr 12 17:15:55 2012
New Revision: 33765
URL: https://nixos.org/websvn/nix/?rev=33765&sc=1
Log:
* Script for creating NixOS EBS-based AMIs.
Added:
nixos/trunk/maintainers/scripts/ec2/
nixos/trunk/maintainers/scripts/ec2/create-ebs-amis.py (contents, props
changed)
nixos/trunk/maintainers/scripts/ec2/create-s3-amis.sh
- copied unchanged from r33757,
nixos/trunk/maintainers/scripts/create-amis.sh
nixos/trunk/maintainers/scripts/ec2/ebs-creator.nix
Deleted:
nixos/trunk/maintainers/scripts/create-amis.sh
Added: nixos/trunk/maintainers/scripts/ec2/create-ebs-amis.py
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ nixos/trunk/maintainers/scripts/ec2/create-ebs-amis.py Thu Apr 12
17:15:55 2012 (r33765)
@@ -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)
Copied: nixos/trunk/maintainers/scripts/ec2/create-s3-amis.sh (from r33757,
nixos/trunk/maintainers/scripts/create-amis.sh)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ nixos/trunk/maintainers/scripts/ec2/create-s3-amis.sh Thu Apr 12
17:15:55 2012 (r33765, copy of r33757,
nixos/trunk/maintainers/scripts/create-amis.sh)
@@ -0,0 +1,46 @@
+#! /bin/sh -e
+
+revision=$(svnversion "$NIXOS")
+echo "NixOS revision is $revision"
+
+buildAndUploadFor() {
+ system="$1"
+ arch="$2"
+
+ echo "building $system image..."
+ NIXOS_CONFIG=$NIXOS/modules/virtualisation/amazon-config.nix nix-build
"$NIXOS" \
+ -A config.system.build.amazonImage --argstr system "$system" -o ec2-ami
+
+ ec2-bundle-image -i ./ec2-ami/nixos.img --user "$AWS_ACCOUNT" --arch
"$arch" \
+ -c "$EC2_CERT" -k "$EC2_PRIVATE_KEY"
+
+ for region in eu-west-1 us-east-1 us-west-1; do
+ echo "uploading $system image for $region..."
+
+ name="$(echo nixos-$arch-r$revision | tr '[A-Z]_' '[a-z]-')"
+
+ bucket="$name-$region"
+
+ if [ "$region" = eu-west-1 ]; then s3location=EU;
+ elif [ "$region" = us-east-1 ]; then s3location=US;
+ else s3location="$region"
+ fi
+
+ ec2-upload-bundle -b "$bucket" -m /tmp/nixos.img.manifest.xml \
+ -a "$AWS_ACCESS_KEY_ID" -s "$AWS_SECRET_ACCESS_KEY" --location
"$s3location"
+
+ kernel=$(ec2-describe-images -o amazon --filter
"manifest-location=*pv-grub-hd0_1.03-$arch*" --region "$region" | cut -f 2)
+ echo "using PV-GRUB kernel $kernel"
+
+ ami=$(ec2-register "$bucket/nixos.img.manifest.xml" -n "$name" -d
"NixOS $system r$revision" \
+ --region "$region" --kernel "$kernel" | cut -f 2)
+
+ echo "AMI ID is $ami"
+
+ echo "$system" "$region" "$ami" >> amis
+
+ ec2-modify-image-attribute --region "$region" "$ami" -l -a all
+ done
+}
+
+buildAndUploadFor x86_64-linux x86_64
Added: nixos/trunk/maintainers/scripts/ec2/ebs-creator.nix
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ nixos/trunk/maintainers/scripts/ec2/ebs-creator.nix Thu Apr 12 17:15:55
2012 (r33765)
@@ -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;
+ };
+}
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits