Skip to content
Permalink
Browse files

fix: BuildConfig should not be generated by default

Related to issue #292
  • Loading branch information...
aureamunoz authored and iocanel committed Jul 26, 2019
1 parent 9637045 commit 0705831007a4a997ffefc6b269ba7417686cd8b0
@@ -23,7 +23,7 @@
import io.dekorate.kubernetes.annotation.Env;
import io.dekorate.component.model.DeploymentMode;

@ComponentApplication(name = "hello-world", exposeService = false, envs = @Env(name = "key1", value = "val1"))
@ComponentApplication(name = "hello-world", deploymentMode = DeploymentMode.build, exposeService = false, envs = @Env(name = "key1", value = "val1"))
public class Main {

public static void main(String[] args) {
@@ -32,6 +32,7 @@
import io.dekorate.component.decorator.ExposeServiceDecorator;
import io.dekorate.component.model.Component;
import io.dekorate.component.model.ComponentBuilder;
import io.dekorate.component.model.DeploymentMode;
import io.dekorate.config.ConfigurationSupplier;
import io.dekorate.kubernetes.config.BaseConfig;
import io.dekorate.kubernetes.config.ConfigKey;
@@ -99,20 +100,8 @@ private void addVisitors(ComponentConfig config) {
String type = config.getAttribute(RUNTIME_TYPE);
String version = config.getAttribute(RUNTIME_VERSION);

if (config.getProject().getScmInfo() != null) {
String url = config.getProject().getScmInfo().getUrl();
String branch = config.getProject().getScmInfo().getBranch();
String buildType = config.getBuildType();
Path modulePath = config.getProject().getScmInfo().getRoot().relativize(config.getProject().getRoot());


if (!config.getRemote().equals(Git.ORIGIN)) {
url = Git.getRemoteUrl(config.getProject().getScmInfo().getRoot(), config.getRemote())
.map(u -> u.replace(Git.GITHUB_SSH,Git.GITHUB_HTTPS))
.orElse(url);
}
resources.decorateCustom(ResourceGroup.NAME,
new AddBuildConfigToComponentDecorator(modulePath, url, branch, buildType));
if(DeploymentMode.build.equals(config.getDeploymentMode())) {
generateBuildConfig(config);
}

if (config.isExposeService()) {
@@ -139,6 +128,24 @@ private void addVisitors(ComponentConfig config) {
}
}

private void generateBuildConfig(ComponentConfig config) {
if (config.getProject().getScmInfo() != null) {
String url = config.getProject().getScmInfo().getUrl();
String branch = config.getProject().getScmInfo().getBranch();
String buildType = config.getBuildType();
Path modulePath = config.getProject().getScmInfo().getRoot().relativize(config.getProject().getRoot());


if (!config.getRemote().equals(Git.ORIGIN)) {
url = Git.getRemoteUrl(config.getProject().getScmInfo().getRoot(), config.getRemote())
.map(u -> u.replace(Git.GITHUB_SSH,Git.GITHUB_HTTPS))
.orElse(url);
}
resources.decorateCustom(ResourceGroup.NAME,
new AddBuildConfigToComponentDecorator(modulePath, url, branch, buildType));
}
}

private BaseConfig getKubernetesConfig() {
Optional<BaseConfig> optionalKubernetesConfig = configurators.get(BaseConfig.class);
if (optionalKubernetesConfig.isPresent()) {
@@ -16,7 +16,6 @@
package io.dekorate.examples;

import io.dekorate.component.model.Component;
import io.dekorate.component.model.Link;
import io.dekorate.deps.kubernetes.api.model.HasMetadata;
import io.dekorate.deps.kubernetes.api.model.KubernetesList;
import io.dekorate.utils.Serialization;
@@ -26,6 +25,7 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import io.dekorate.component.model.Component;
import io.dekorate.component.model.DeploymentMode;
@@ -40,12 +40,9 @@ public void shouldContainComponentWithDefaultValues() {
Assertions.assertEquals(1, items.size());
Component component = (Component) items.get(0);
Assertions.assertEquals("Component", component.getKind());
assertEquals("https://github.com/dekorateio/dekorate.git", component.getSpec().getBuildConfig().getUrl());
assertEquals("component-example", component.getMetadata().getName());
assertEquals(DeploymentMode.dev, component.getSpec().getDeploymentMode());
assertEquals(false, component.getSpec().isExposeService());
assertEquals("component-example", component.getSpec().getBuildConfig().getModuleDirName());
assertEquals("s2i", component.getSpec().getBuildConfig().getType());
assertEquals(1, component.getMetadata().getLabels().size());
assertNull(component.getSpec().getBuildConfig());
}

}

0 comments on commit 0705831

Please sign in to comment.
You can’t perform that action at this time.