Skip to content

Commit

Permalink
fix(rosco) Make baked artifacts adhere to the proposed standard (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
brujoand authored and Matt Duftler committed Nov 2, 2017
1 parent 66b8a89 commit 858cf33
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 55 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allprojects {
group = "com.netflix.spinnaker.rosco"

ext {
spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.109.2'
spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.113.1'
}

def checkLocalVersions = [spinnakerDependenciesVersion: spinnakerDependenciesVersion]
Expand Down Expand Up @@ -60,6 +60,7 @@ allprojects {
compile spinnaker.dependency("groovy")
compile spinnaker.dependency("korkSwagger")
compile spinnaker.dependency("spectatorReg")
compile spinnaker.dependency("korkArtifacts")
}
test {
testLogging {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Nov 13 10:25:29 PST 2015
#Fri Oct 13 09:56:27 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
1 change: 1 addition & 0 deletions rosco-core/rosco-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies {
compile spinnaker.dependency("frigga")
compile spinnaker.dependency('jacksonGuava')
compile spinnaker.dependency('jedis')
compile spinnaker.dependency("korkArtifacts")
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import io.swagger.annotations.ApiModelProperty
import com.netflix.spinnaker.kork.artifacts.model.Artifact;

/**
* The details of a completed bake.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.netflix.spinnaker.rosco.executor

import com.netflix.spectator.api.Registry
import com.netflix.spinnaker.rosco.api.Artifact
import com.netflix.spinnaker.rosco.api.Bake
import com.netflix.spinnaker.rosco.api.BakeRequest
import com.netflix.spinnaker.rosco.api.BakeStatus
Expand Down Expand Up @@ -218,7 +217,7 @@ class BakePoller implements ApplicationListener<ContextRefreshedEvent> {
BakeRequest bakeRequest = bakeStore.retrieveBakeRequestById(bakeId)
BakeRecipe bakeRecipe = bakeStore.retrieveBakeRecipeById(bakeId)
bakeDetails.artifact = cloudProviderBakeHandler.produceArtifactDecorationFrom(
bakeRequest, bakeRecipe, bakeDetails, cloudProvider
bakeRequest, bakeRecipe, bakeDetails, cloudProvider, region
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.netflix.spinnaker.rosco.providers

import com.netflix.spinnaker.rosco.api.Artifact
import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.rosco.api.Bake
import com.netflix.spinnaker.rosco.api.BakeOptions
import com.netflix.spinnaker.rosco.api.BakeOptions.BaseImage
Expand Down Expand Up @@ -110,16 +110,18 @@ abstract class CloudProviderBakeHandler {
* Returns a decorated artifact for a given bake. Right now this is a generic approach
* but it could be useful to override this method for specific providers.
*/
def Artifact produceArtifactDecorationFrom(BakeRequest bakeRequest, BakeRecipe bakeRecipe, Bake bakeDetails, String cloudProvider) {
def Artifact produceArtifactDecorationFrom(BakeRequest bakeRequest, BakeRecipe bakeRecipe, Bake bakeDetails, String cloudProvider, String region) {
Artifact bakedArtifact = new Artifact(
name: bakeRecipe?.name,
version: bakeRecipe?.version,
type: cloudProvider,
type: "${cloudProvider}/image",
location: region,
reference: bakeDetails.ami ?: bakeDetails.image_name,
metadata: [
build_info_url: bakeRequest?.build_info_url,
build_number: bakeRequest?.build_number
]
],
uuid: bakeDetails.id
)

return bakedArtifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.netflix.spinnaker.rosco.executor

import com.netflix.spectator.api.DefaultRegistry
import com.netflix.spinnaker.rosco.api.Artifact
import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.rosco.api.Bake
import com.netflix.spinnaker.rosco.api.BakeRequest
import com.netflix.spinnaker.rosco.api.BakeStatus
Expand All @@ -33,7 +33,6 @@ import spock.lang.Unroll

class BakePollerSpec extends Specification implements TestDefaults {

private static final String REGION = "some-region"
private static final String JOB_ID = "123"
private static final String AMI_ID = "ami-3cf4a854"
private static final String IMAGE_NAME = "some-image"
Expand Down Expand Up @@ -63,7 +62,7 @@ class BakePollerSpec extends Specification implements TestDefaults {
then:
1 * jobExecutorMock.updateJob(JOB_ID) >> incompleteBakeStatus
1 * bakeStoreMock.updateBakeStatus(incompleteBakeStatus)
numStatusLookups * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION
numStatusLookups * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION
numStatusLookups * bakeStoreMock.retrieveBakeStatusById(JOB_ID) >> incompleteBakeStatus

where:
Expand Down Expand Up @@ -100,8 +99,8 @@ class BakePollerSpec extends Specification implements TestDefaults {
1 * jobExecutorMock.updateJob(JOB_ID) >> completeBakeStatus
1 * bakeStoreMock.retrieveCloudProviderById(JOB_ID) >> BakeRequest.CloudProviderType.gce.toString()
1 * cloudProviderBakeHandlerRegistryMock.lookup(BakeRequest.CloudProviderType.gce) >> cloudProviderBakeHandlerMock
2 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION // 1 for metrics
1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(REGION, JOB_ID, "$LOGS_CONTENT\n$LOGS_CONTENT") >> bakeDetails
2 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION // 1 for metrics
1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(SOME_REGION, JOB_ID, "$LOGS_CONTENT\n$LOGS_CONTENT") >> bakeDetails
1 * bakeStoreMock.retrieveBakeRequestById(JOB_ID) >> bakeRequest
1 * bakeStoreMock.retrieveBakeRecipeById(JOB_ID) >> bakeRecipe
1 * bakeStoreMock.updateBakeDetails(bakeDetails)
Expand Down Expand Up @@ -132,7 +131,7 @@ class BakePollerSpec extends Specification implements TestDefaults {
1 * jobExecutorMock.updateJob(JOB_ID) >> null
1 * bakeStoreMock.storeBakeError(JOB_ID, "Unable to retrieve status for '$JOB_ID'.")
1 * bakeStoreMock.cancelBakeById(JOB_ID)
1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION
1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION
1 * bakeStoreMock.retrieveBakeStatusById(JOB_ID) >> new BakeStatus()
}

Expand All @@ -147,7 +146,7 @@ class BakePollerSpec extends Specification implements TestDefaults {
def bakedArtifact = new Artifact(
name: bakeRecipe.name,
version: bakeRecipe.version,
type: DOCKER_CLOUD_PROVIDER,
type: "${DOCKER_CLOUD_PROVIDER}/image",
reference: AMI_ID,
metadata: [
build_info_url: bakeRequest.build_info_url,
Expand All @@ -170,9 +169,9 @@ class BakePollerSpec extends Specification implements TestDefaults {
then:
1 * bakeStoreMock.retrieveCloudProviderById(JOB_ID) >> DOCKER_CLOUD_PROVIDER.toString()
1 * cloudProviderBakeHandlerRegistryMock.lookup(DOCKER_CLOUD_PROVIDER) >> cloudProviderBakeHandlerMock
1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION
1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(REGION, JOB_ID, LOGS_CONTENT) >> bakeDetails
1 * cloudProviderBakeHandlerMock.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, bakeDetails, DOCKER_CLOUD_PROVIDER.toString()) >> bakedArtifact
1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION
1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(SOME_REGION, JOB_ID, LOGS_CONTENT) >> bakeDetails
1 * cloudProviderBakeHandlerMock.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, bakeDetails, DOCKER_CLOUD_PROVIDER.toString(), SOME_REGION) >> bakedArtifact
1 * bakeStoreMock.retrieveBakeRequestById(JOB_ID) >> bakeRequest
1 * bakeStoreMock.retrieveBakeRecipeById(JOB_ID) >> bakeRecipe
1 * bakeStoreMock.updateBakeDetails(decoratedBakeDetails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.netflix.spinnaker.rosco.providers

import com.netflix.spinnaker.rosco.api.Artifact
import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.rosco.providers.util.TestDefaults
import spock.lang.Specification
import spock.lang.Subject
Expand All @@ -30,19 +30,21 @@ class CloudProviderBakeHandlerSpec extends Specification implements TestDefaults
def expectedArtifact = new Artifact (
name: SOME_BAKE_RECIPE.name,
version: SOME_BAKE_RECIPE.version,
type: SOME_CLOUD_PROVIDER,
location: SOME_REGION,
type: "${SOME_CLOUD_PROVIDER}/image",
reference: SOME_BAKE_DETAILS.ami,
metadata: [
build_info_url: SOME_BAKE_REQUEST.build_info_url,
build_number: SOME_BAKE_REQUEST.build_number
]
],
uuid: SOME_BAKE_DETAILS.id
)

@Subject
CloudProviderBakeHandler bakeHandler = Spy(CloudProviderBakeHandler)

when:
Artifact producedArtifact = bakeHandler.produceArtifactDecorationFrom(SOME_BAKE_REQUEST, SOME_BAKE_RECIPE, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER)
Artifact producedArtifact = bakeHandler.produceArtifactDecorationFrom(SOME_BAKE_REQUEST, SOME_BAKE_RECIPE, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER, SOME_REGION)

then:
producedArtifact == expectedArtifact
Expand All @@ -53,7 +55,7 @@ class CloudProviderBakeHandlerSpec extends Specification implements TestDefaults
expect:
@Subject
CloudProviderBakeHandler bakeHandler = Spy(CloudProviderBakeHandler)
def decoratedArtifact = bakeHandler.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER)
def decoratedArtifact = bakeHandler.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER, SOME_REGION)
decoratedArtifact.name == expectedName
decoratedArtifact.version == expectedVersion
decoratedArtifact.reference == expectedReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ trait TestDefaults {
static final String SOME_AMI_ID = "ami-3cf4a854"
static final String SOME_IMAGE_NAME = "ubuntu/trusty"
static final String SOME_CLOUD_PROVIDER = "aws"
static final String SOME_REGION = "eu-west-1"

static final Bake SOME_BAKE_DETAILS = new Bake(id: SOME_JOB_ID, ami: SOME_AMI_ID, image_name: SOME_IMAGE_NAME)
static final BakeRequest SOME_BAKE_REQUEST = new BakeRequest(build_info_url: SOME_BUILD_INFO_URL, build_number: SOME_BUILD_NR)
Expand Down

0 comments on commit 858cf33

Please sign in to comment.