From 02774c630807183ec7969145e0ccb4930cc96e06 Mon Sep 17 00:00:00 2001 From: Gard Rimestad Date: Mon, 29 Feb 2016 11:33:14 +0100 Subject: [PATCH 1/2] amazon chroot builder support --- .../rosco/providers/aws/AWSBakeHandler.groovy | 4 +- .../providers/aws/AWSBakeHandlerSpec.groovy | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandler.groovy b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandler.groovy index b6a35bee2..5eda1805e 100644 --- a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandler.groovy +++ b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandler.groovy @@ -27,8 +27,8 @@ import org.springframework.stereotype.Component @Component public class AWSBakeHandler extends CloudProviderBakeHandler { - private static final String BUILDER_TYPE = "amazon-ebs" - private static final String IMAGE_NAME_TOKEN = "amazon-ebs: Creating the AMI:" + private static final String BUILDER_TYPE = "amazon-(chroot|ebs)" + private static final String IMAGE_NAME_TOKEN = "amazon-(chroot|ebs): Creating the AMI:" @Autowired RoscoAWSConfiguration.AWSBakeryDefaults awsBakeryDefaults diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandlerSpec.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandlerSpec.groovy index 4b1c9dfb4..04f8060b3 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandlerSpec.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/aws/AWSBakeHandlerSpec.groovy @@ -108,6 +108,51 @@ class AWSBakeHandlerSpec extends Specification { awsBakeryDefaults = new ObjectMapper().convertValue(awsBakeryDefaultsJson, RoscoAWSConfiguration.AWSBakeryDefaults) } + void 'can identify amazon-ebs builds'() { + setup: + @Subject + AWSBakeHandler awsBakeHandler = new AWSBakeHandler(awsBakeryDefaults: awsBakeryDefaults) + + when: + def logsContent = + " amazon-ebs: Processing triggers for libc-bin ...\n" + + Boolean awsProducer = awsBakeHandler.isProducerOf(logsContent) + + then: + awsProducer == true + } + + void 'can identify amazon-chroot builds'() { + setup: + @Subject + AWSBakeHandler awsBakeHandler = new AWSBakeHandler(awsBakeryDefaults: awsBakeryDefaults) + + when: + def logsContent = + " amazon-chroot: Processing triggers for libc-bin ...\n" + + Boolean awsProducer = awsBakeHandler.isProducerOf(logsContent) + + then: + awsProducer == true + } + + void 'rejects non amazon builds'() { + setup: + @Subject + AWSBakeHandler awsBakeHandler = new AWSBakeHandler(awsBakeryDefaults: awsBakeryDefaults) + + when: + def logsContent = + " somesystem-thing: Processing triggers for libc-bin ...\n" + + Boolean awsProducer = awsBakeHandler.isProducerOf(logsContent) + + then: + awsProducer == false + } + void 'can scrape packer logs for image name'() { setup: @Subject @@ -142,6 +187,41 @@ class AWSBakeHandlerSpec extends Specification { } } + void 'can scrape packer (amazon-chroot) logs for image name'() { + setup: + @Subject + AWSBakeHandler awsBakeHandler = new AWSBakeHandler(awsBakeryDefaults: awsBakeryDefaults) + + when: + def logsContent = + " amazon-chroot: Processing triggers for libc-bin ...\n" + + " amazon-chroot: ldconfig deferred processing now taking place\n" + + "==> amazon-chroot: Stopping the source instance...\n" + + "==> amazon-chroot: Waiting for the instance to stop...\n" + + "==> amazon-chroot: Creating the AMI: kato-x8664-1422459898853-ubuntu\n" + + " amazon-chroot: AMI: ami-2c014644\n" + + "==> amazon-chroot: Waiting for AMI to become ready...\n" + + "==> amazon-chroot: Terminating the source AWS instance...\n" + + "==> amazon-chroot: Deleting temporary security group...\n" + + "==> amazon-chroot: Deleting temporary keypair...\n" + + "Build 'amazon-chroot' finished.\n" + + "\n" + + "==> Builds finished. The artifacts of successful builds are:\n" + + "--> amazon-chroot: AMIs were created:\n" + + "\n" + + "us-east-1: ami-2c014644" + + Bake bake = awsBakeHandler.scrapeCompletedBakeResults(REGION, "123", logsContent) + + then: + with (bake) { + id == "123" + ami == "ami-2c014644" + image_name == "kato-x8664-1422459898853-ubuntu" + } + } + + void 'scraping returns null for missing image id'() { setup: @Subject From b91a226b28217590c9109aba778b55b606ea9cf0 Mon Sep 17 00:00:00 2001 From: Gard Rimestad Date: Mon, 29 Feb 2016 12:06:26 +0100 Subject: [PATCH 2/2] chroot packer template --- rosco-web/config/packer/aws-chroot.json | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 rosco-web/config/packer/aws-chroot.json diff --git a/rosco-web/config/packer/aws-chroot.json b/rosco-web/config/packer/aws-chroot.json new file mode 100644 index 000000000..142c38192 --- /dev/null +++ b/rosco-web/config/packer/aws-chroot.json @@ -0,0 +1,41 @@ +{ + "variables": { + "aws_access_key": "", + "aws_secret_key": "", + "aws_subnet_id": "{{env `AWS_SUBNET_ID`}}", + "aws_vpc_id": "{{env `AWS_VPC_ID`}}", + "aws_region": null, + "aws_ssh_username": null, + "aws_instance_type": null, + "aws_source_ami": null, + "aws_target_ami": null, + "aws_associate_public_ip_address": "true", + "aws_enhanced_networking": "false", + "appversion": "", + "build_host": "", + "repository": "", + "package_type": "", + "packages": "", + "upgrade": "", + "configDir": null + }, + "builders": [{ + "type": "amazon-chroot", + "ami_virtualization_type": "hvm", + "access_key": "{{user `aws_access_key`}}", + "secret_key": "{{user `aws_secret_key`}}", + "source_ami": "{{user `aws_source_ami`}}", + "ami_name": "{{user `aws_target_ami`}}", + "tags": {"appversion": "{{user `appversion`}}", "build_host": "{{user `build_host`}}"} + }], + "provisioners": [{ + "type": "shell", + "script": "{{user `configDir`}}/install_packages.sh", + "environment_vars": [ + "repository={{user `repository`}}", + "package_type={{user `package_type`}}", + "packages={{user `packages`}}", + "upgrade={{user `upgrade`}}" + ] + }] +}