Skip to content

Commit

Permalink
Merge pull request #68 from gardleopard/upgrade_flag
Browse files Browse the repository at this point in the history
upgrade support
  • Loading branch information
Matt Duftler committed Feb 19, 2016
2 parents 0802bfa + 66d77ee commit 70691b1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BakeRequest {
Boolean enhanced_networking
String ami_name
String ami_suffix
Boolean upgrade

@ApiModelProperty("The explicit packer template to use, instead of resolving one from rosco's configuration")
String template_file_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ abstract class CloudProviderBakeHandler {
parameterMap.build_host = bakeRequest.build_host
}

if (bakeRequest.upgrade) {
parameterMap.upgrade = bakeRequest.upgrade
}

parameterMap.configDir = configDir

if (bakeRequest.extended_attributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,46 @@ class AWSBakeHandlerSpec extends Specification {
1 * packerCommandFactoryMock.buildPackerCommand("", parameterMap, "$configDir/$awsBakeryDefaults.templateFile")
}

void 'produces packer command with all required parameters including upgrade'() {
setup:
def imageNameFactoryMock = Mock(ImageNameFactory)
def packerCommandFactoryMock = Mock(PackerCommandFactory)
def bakeRequest = new BakeRequest(user: "[email protected]",
package_name: PACKAGE_NAME,
base_os: "ubuntu",
vm_type: BakeRequest.VmType.hvm,
cloud_provider_type: BakeRequest.CloudProviderType.aws,
upgrade: true)
def targetImageName = "kato-x8664-timestamp-ubuntu"
def parameterMap = [
aws_access_key: awsBakeryDefaults.awsAccessKey,
aws_secret_key: awsBakeryDefaults.awsSecretKey,
aws_region: REGION,
aws_ssh_username: "ubuntu",
aws_instance_type: "t2.micro",
aws_source_ami: SOURCE_UBUNTU_HVM_IMAGE_NAME,
aws_target_ami: targetImageName,
deb_repo: DEBIAN_REPOSITORY,
packages: PACKAGE_NAME,
upgrade: true,
configDir: configDir
]

@Subject
AWSBakeHandler awsBakeHandler = new AWSBakeHandler(configDir: configDir,
awsBakeryDefaults: awsBakeryDefaults,
imageNameFactory: imageNameFactoryMock,
packerCommandFactory: packerCommandFactoryMock,
debianRepository: DEBIAN_REPOSITORY)

when:
awsBakeHandler.producePackerCommand(REGION, bakeRequest)

then:
1 * imageNameFactoryMock.deriveImageNameAndAppVersion(bakeRequest, _) >> [targetImageName, null, PACKAGE_NAME]
1 * packerCommandFactoryMock.buildPackerCommand("", parameterMap, "$configDir/$awsBakeryDefaults.templateFile")
}

void 'throws exception when virtualization settings are not found for specified operating system'() {
setup:
def imageNameFactoryMock = Mock(ImageNameFactory)
Expand Down
4 changes: 3 additions & 1 deletion rosco-web/config/packer/aws-ebs.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"build_host": "",
"deb_repo": "",
"packages": "",
"upgrade": "",
"configDir": null
},
"builders": [{
Expand All @@ -38,7 +39,8 @@
"script": "{{user `configDir`}}/install_packages.sh",
"environment_vars": [
"deb_repo={{user `deb_repo`}}",
"packages={{user `packages`}}"
"packages={{user `packages`}}",
"upgrade={{user `upgrade`}}"
],
"pause_before": "30s"
}]
Expand Down
4 changes: 3 additions & 1 deletion rosco-web/config/packer/gce.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build_host": "",
"deb_repo": "",
"packages": "",
"upgrade": "",
"configDir": null
},
"builders": [{
Expand All @@ -29,7 +30,8 @@
"script": "{{user `configDir`}}/install_packages.sh",
"environment_vars": [
"deb_repo={{user `deb_repo`}}",
"packages={{user `packages`}}"
"packages={{user `packages`}}",
"upgrade={{user `upgrade`}}"
],
"pause_before": "30s"
}]
Expand Down
6 changes: 6 additions & 0 deletions rosco-web/config/packer/install_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

echo "deb_repo=$deb_repo"
echo "packages=$packages"
echo "upgrade=$upgrade"

# Strip leading/trailing quotes if present.
deb_repo=`echo $deb_repo | sed 's/^"\(.*\)"$/\1/'`
Expand All @@ -16,4 +17,9 @@ if [[ "$deb_repo" != "" ]]; then
fi

sudo apt-get update

if [[ "$upgrade" == "true" ]]; then
sudo unattended-upgrade -v
fi

sudo apt-get install --force-yes -y $packages

0 comments on commit 70691b1

Please sign in to comment.