-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(artifact/decoration): Artifact decoration spinnaker/spinnaker#1348…
… (#138) This PR makes igor understand deb and rpm packages by heart and enables igor to be configured to support various file artifact types. The artifact decoration is currently opt in through a feature flag in the igor configuration. spinnaker/spinnaker#1348
- Loading branch information
1 parent
f800783
commit 4a3a410
Showing
15 changed files
with
702 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...roovy/com/netflix/spinnaker/igor/build/artifact/decorator/ArtifactDetailsDecorator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor.build.artifact.decorator | ||
|
||
import com.netflix.spinnaker.igor.build.model.GenericArtifact | ||
|
||
interface ArtifactDetailsDecorator { | ||
|
||
GenericArtifact decorate(GenericArtifact genericArtifact) | ||
|
||
boolean handles(GenericArtifact genericArtifact) | ||
|
||
String decoratorName() | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...oovy/com/netflix/spinnaker/igor/build/artifact/decorator/ConfigurableFileDecorator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor.build.artifact.decorator | ||
|
||
import com.netflix.spinnaker.igor.build.model.GenericArtifact | ||
|
||
class ConfigurableFileDecorator implements ArtifactDetailsDecorator { | ||
|
||
final String decoratorRegex | ||
final String identifierRegex | ||
final String type | ||
|
||
ConfigurableFileDecorator(String type, String decoratorRegex, String identifierRegex) { | ||
this.decoratorRegex = decoratorRegex | ||
this.identifierRegex = identifierRegex | ||
this.type = type | ||
} | ||
|
||
@Override | ||
GenericArtifact decorate(GenericArtifact genericArtifact) { | ||
def m | ||
|
||
if ((m = genericArtifact.fileName =~ decoratorRegex)) { | ||
genericArtifact.name = m.group(1) | ||
genericArtifact.version = m.group(2) | ||
genericArtifact.type = m.groupCount() > 2 ? m.group(3) : type | ||
genericArtifact.reference = genericArtifact.fileName | ||
} | ||
|
||
return genericArtifact | ||
} | ||
|
||
@Override | ||
boolean handles(GenericArtifact genericArtifact) { | ||
return genericArtifact.fileName =~ identifierRegex | ||
} | ||
|
||
@Override | ||
String decoratorName() { | ||
return type | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ain/groovy/com/netflix/spinnaker/igor/build/artifact/decorator/DebDetailsDecorator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor.build.artifact.decorator | ||
|
||
import com.netflix.spinnaker.igor.build.model.GenericArtifact | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@ConditionalOnProperty('artifact.decorator.enabled') | ||
class DebDetailsDecorator implements ArtifactDetailsDecorator { | ||
|
||
String packageType = "deb" | ||
String versionDelimiter = '_' | ||
|
||
@Override | ||
GenericArtifact decorate(GenericArtifact genericArtifact) { | ||
genericArtifact.name = extractName(genericArtifact.fileName) | ||
genericArtifact.version = extractVersion(genericArtifact.fileName) | ||
genericArtifact.type = packageType | ||
genericArtifact.reference = genericArtifact.fileName | ||
return genericArtifact | ||
} | ||
|
||
@Override | ||
boolean handles(GenericArtifact genericArtifact) { | ||
if (!genericArtifact.fileName) { | ||
return false | ||
} | ||
return genericArtifact.fileName.tokenize('.').last() == "deb" | ||
} | ||
|
||
@Override | ||
String decoratorName() { | ||
return packageType | ||
} | ||
|
||
String extractVersion(String file) { | ||
List<String> parts = file.tokenize(versionDelimiter) | ||
parts.pop() | ||
return parts.pop() | ||
} | ||
|
||
String extractName(String file) { | ||
List<String> parts = file.tokenize(versionDelimiter) | ||
return parts.first() | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ain/groovy/com/netflix/spinnaker/igor/build/artifact/decorator/RpmDetailsDecorator.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor.build.artifact.decorator | ||
|
||
import com.netflix.spinnaker.igor.build.model.GenericArtifact | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@ConditionalOnProperty('artifact.decorator.enabled') | ||
class RpmDetailsDecorator implements ArtifactDetailsDecorator { | ||
|
||
String packageType = 'rpm' | ||
String versionDelimiter = '-' | ||
|
||
@Override | ||
GenericArtifact decorate(GenericArtifact genericArtifact) { | ||
genericArtifact.name = extractName(genericArtifact.fileName) | ||
genericArtifact.version = extractVersion(genericArtifact.fileName) | ||
genericArtifact.type = packageType | ||
genericArtifact.reference = genericArtifact.fileName | ||
return genericArtifact | ||
} | ||
|
||
@Override | ||
boolean handles(GenericArtifact genericArtifact) { | ||
if (!genericArtifact.fileName) { | ||
return false | ||
} | ||
return genericArtifact.fileName.tokenize('.').last() == "rpm" | ||
} | ||
|
||
@Override | ||
String decoratorName() { | ||
return packageType | ||
} | ||
|
||
String extractVersion(String file) { | ||
List<String> parts = file.tokenize(versionDelimiter) | ||
parts.pop() | ||
return parts.pop() | ||
} | ||
|
||
String extractName(String file) { | ||
List<String> parts = file.tokenize(versionDelimiter) | ||
parts.pop() | ||
parts.pop() | ||
return parts.join(versionDelimiter) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...web/src/main/groovy/com/netflix/spinnaker/igor/config/ArtifactDecorationProperties.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor.config | ||
|
||
import groovy.transform.CompileStatic | ||
import org.hibernate.validator.constraints.NotEmpty | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Configuration | ||
|
||
import javax.validation.Valid | ||
|
||
@Configuration | ||
@CompileStatic | ||
@ConfigurationProperties(prefix = 'artifact.decorator') | ||
class ArtifactDecorationProperties { | ||
boolean enabled = false | ||
|
||
@Valid | ||
List<FileDecorator> fileDecorators | ||
|
||
static class FileDecorator { | ||
@NotEmpty | ||
String type | ||
|
||
@NotEmpty | ||
String decoratorRegex | ||
|
||
@NotEmpty | ||
String identifierRegex | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.