Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.openshift.internal.restclient.model.build.GitBuildSource;
import com.openshift.internal.restclient.model.build.ImageChangeTrigger;
import com.openshift.internal.restclient.model.build.STIBuildStrategy;
import com.openshift.internal.restclient.model.build.SourceBuildStrategy;
import com.openshift.internal.restclient.model.build.WebhookTrigger;
import com.openshift.restclient.IClient;
import com.openshift.restclient.images.DockerImageURI;
Expand Down Expand Up @@ -166,6 +167,7 @@ public void setBuildStrategy(IBuildStrategy strategy) {
}
break;
case STI:
case Source:
if ( !(strategy instanceof ISTIBuildStrategy)) {
throw new IllegalArgumentException("IBuildStrategy of type Custom does not implement ISTIBuildStrategy");
}
Expand Down Expand Up @@ -221,18 +223,20 @@ public <T extends IBuildStrategy> T getBuildStrategy() {
getEnvMap(BUILDCONFIG_CUSTOM_ENV)
);
case STI:
boolean incremental = false;
case Source:
if(OpenShiftAPIVersion.v1beta1.name().equals(getApiVersion())) {
incremental = !asBoolean(BUILDCONFIG_STI_CLEAN);
} else if(OpenShiftAPIVersion.v1beta3.name().equals(getApiVersion())) {
incremental = asBoolean(BUILDCONFIG_STI_INCREMENTAL);
return (T) new STIBuildStrategy(asString(BUILDCONFIG_STI_IMAGE),
asString(BUILDCONFIG_STI_SCRIPTS),
!asBoolean(BUILDCONFIG_STI_CLEAN),
getEnvMap(BUILDCONFIG_STI_ENV)
);
}

return (T) new STIBuildStrategy(asString(BUILDCONFIG_STI_IMAGE),
return (T) new SourceBuildStrategy(asString(BUILDCONFIG_STI_IMAGE),
asString(BUILDCONFIG_STI_SCRIPTS),
incremental,
asBoolean(BUILDCONFIG_STI_INCREMENTAL),
getEnvMap(BUILDCONFIG_STI_ENV)
);

case Docker:
return (T) new DockerBuildStrategy(
asString(BUILDCONFIG_DOCKER_CONTEXTDIR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* @author Jeff Cantrill
*/
@Deprecated
public class STIBuildStrategy implements ISTIBuildStrategy{

private DockerImageURI image;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2015 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.internal.restclient.model.build;

import java.util.Map;

import com.openshift.restclient.model.build.BuildStrategyType;

/**
*
* @author jeff.cantrill
*
*/
public class SourceBuildStrategy extends STIBuildStrategy {

public SourceBuildStrategy(String image, String scriptsLocation, boolean incremental, Map<String, String> envVars) {
super(image, scriptsLocation, incremental, envVars);
}

@Override
public BuildStrategyType getType() {
return BuildStrategyType.Source;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public interface OpenShiftApiModelProperties extends ResourcePropertyKeys{
put(BUILDCONFIG_DOCKER_NOCACHE, new String[]{"spec","strategy", "dockerStrategy", "noCache"});
put(BUILDCONFIG_DOCKER_BASEIMAGE, new String[]{"spec","strategy", "dockerStrategy","baseImage"});
put(BUILDCONFIG_OUTPUT_REPO, new String[]{"spec","output", "to","name"});
put(BUILDCONFIG_STI_IMAGE, new String[]{"spec","strategy", "stiStrategy", "from","name"});
put(BUILDCONFIG_STI_SCRIPTS, new String[]{"spec","strategy", "stiStrategy", "scripts"});
put(BUILDCONFIG_STI_INCREMENTAL, new String[]{"spec","strategy", "stiStrategy", "incremental"});
put(BUILDCONFIG_STI_ENV, new String[]{"spec","strategy", "stiStrategy", "env"});
put(BUILDCONFIG_STI_IMAGE, new String[]{"spec","strategy", "sourceStrategy", "from","name"});
put(BUILDCONFIG_STI_SCRIPTS, new String[]{"spec","strategy", "sourceStrategy", "scripts"});
put(BUILDCONFIG_STI_INCREMENTAL, new String[]{"spec","strategy", "sourceStrategy", "incremental"});
put(BUILDCONFIG_STI_ENV, new String[]{"spec","strategy", "sourceStrategy", "env"});
put(BUILDCONFIG_TRIGGERS, new String[]{"spec","triggers"});
put(BUILD_CONFIG_WEBHOOK_GITHUB_SECRET, new String[]{"github","secret"});
put(BUILD_CONFIG_WEBHOOK_GENERIC_SECRET, new String[]{"generic","secret"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// TODO: evalute switching to a class/constants since enums are not extendable
public enum BuildStrategyType {
Docker,
@Deprecated
STI,
Source,
Custom
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/**
* @author Jeff Cantrill
*/
@Deprecated
public interface ISTIBuildStrategy extends IBuildStrategy {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2015 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.openshift.restclient.model.build;

/**
*
* @author jeff.cantrill
*
*/
public interface ISourceBuildStrategy extends ISTIBuildStrategy{

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void addBuildTriggers() {

@Test
public void getOutputRespositoryName(){
assertEquals("origin-ruby-sample", config.getOutputRepositoryName());
assertEquals("origin-ruby-sample:latest", config.getOutputRepositoryName());
}

@Test
Expand Down Expand Up @@ -111,7 +111,7 @@ public void setGitBuildSource() {
@Test
public void getSTIBuildStrategy() {
IBuildStrategy strategy = config.getBuildStrategy();
assertSTIBuildStrategy(strategy);
assertSourceBuildStrategy(strategy);
}

@Test
Expand All @@ -122,7 +122,7 @@ public void setSTIBuildStrategy() {
env.put("foo", "bar");
writeConfig.setBuildStrategy(new STIBuildStrategy("ruby-20-centos7:latest", "alocation", true, env));

assertSTIBuildStrategy(reCreateBuildConfig(writeConfig).getBuildStrategy());
assertSourceBuildStrategy(reCreateBuildConfig(writeConfig).getBuildStrategy());
}

private void assertBuildTriggers(IBuildTrigger[] triggers) {
Expand All @@ -143,8 +143,8 @@ private void assertGitBuildSource(IBuildSource source) {
assertEquals("Exp. to get the source ref","", git.getRef());
}

private void assertSTIBuildStrategy(IBuildStrategy strategy) {
assertEquals(BuildStrategyType.STI, strategy.getType());
private void assertSourceBuildStrategy(IBuildStrategy strategy) {
assertEquals(BuildStrategyType.Source, strategy.getType());
assertTrue(strategy instanceof ISTIBuildStrategy);

ISTIBuildStrategy sti = (ISTIBuildStrategy)strategy;
Expand Down
31 changes: 15 additions & 16 deletions src/test/resources/samples/openshift3/v1beta3_build_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"metadata": {
"name": "ruby-sample-build",
"namespace": "test",
"selfLink": "/osapi/v1beta1/buildConfigs/ruby-sample-build?namespace=test",
"uid": "87bc17dc-f41a-11e4-bc91-080027893417",
"resourceVersion": "58372",
"creationTimestamp": "2015-05-06T18:05:51Z",
"selfLink": "/osapi/v1beta3/namespaces/test/buildconfigs/ruby-sample-build",
"uid": "a87b6692-00a5-11e5-8ebb-080027893417",
"resourceVersion": "259",
"creationTimestamp": "2015-05-22T17:12:00Z",
"labels": {
"mylabel": "abe",
"name": "ruby-sample-build",
"template": "application-template-stibuild"
}
Expand Down Expand Up @@ -41,31 +42,29 @@
}
},
"strategy": {
"type": "STI",
"stiStrategy": {
"type": "Source",
"sourceStrategy": {
"from": {
"kind": "ImageStreamTag",
"name": "ruby-20-centos7:latest"
},
"incremental": true,
"scripts" : "alocation",
"env" : [
{
"name" : "foo",
"value" : "bar"
}
]
"env" : [{
"name" : "foo",
"value" : "bar"
}],
"incremental": true
}
},
"output": {
"to": {
"kind": "ImageStream",
"name": "origin-ruby-sample"
"kind": "ImageStreamTag",
"name": "origin-ruby-sample:latest"
}
},
"resources": {}
},
"status": {
"lastVersion": 1
}
}
}