Skip to content

Commit

Permalink
Merge pull request #74 from gardleopard/amazon_chroot_support
Browse files Browse the repository at this point in the history
amazon chroot builder support
  • Loading branch information
Matt Duftler committed Mar 1, 2016
2 parents d8a6d64 + b91a226 commit 0b3ef49
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions rosco-web/config/packer/aws-chroot.json
Original file line number Diff line number Diff line change
@@ -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`}}"
]
}]
}

0 comments on commit 0b3ef49

Please sign in to comment.