Skip to content

Commit

Permalink
Fix eclipse-jkube#197: Provided Dockerfile is always skipped in simpl…
Browse files Browse the repository at this point in the history
…e Dockerfile mode
  • Loading branch information
rohanKanojia committed Jun 2, 2020
1 parent 11be290 commit 8f4bf3e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage:
```
### 1.0.0-SNAPSHOT
* Fix #173: Use OpenShift compliant git/vcs annotations
* Fix #187: Provided Dockerfile is always skipped in simple Dockerfile mode
* Fix #182: Assembly is never null
* Fix #198: Wildfly works in OpenShift with S2I binary build (Docker)
* Fix #199: BaseGenerator retrieves runtime mode from context (not from missing properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.eclipse.jkube.generator.api.support;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Collections;
Expand Down Expand Up @@ -204,7 +205,13 @@ protected String getAlias() {
}

protected boolean shouldAddImageConfiguration(List<ImageConfiguration> configs) {
return !containsBuildConfiguration(configs) || Configs.asBoolean(getConfig(Config.add));
if (isSimpleDockerfileMode()) {
return false;
}
if (!containsBuildConfiguration(configs)) {
return true;
}
return Configs.asBoolean(getConfig(Config.add));
}

protected String getConfigWithFallback(Config name, String key, String defaultVal) {
Expand All @@ -230,6 +237,14 @@ private boolean containsBuildConfiguration(List<ImageConfiguration> configs) {
return false;
}

private boolean isSimpleDockerfileMode() {
if (getProject() != null && getProject().getBaseDirectory() != null && getProject().getBaseDirectory().exists()) {
File dockerFile = new File(getProject().getBaseDirectory(), "Dockerfile");
return dockerFile.exists();
}
return false;
}

protected void addSchemaLabels(BuildConfiguration.BuildConfigurationBuilder buildBuilder, PrefixedLogger log) {
final JavaProject project = getProject();
String docURL = project.getDocumentationUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package org.eclipse.jkube.generator.api.support;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -29,7 +31,9 @@
import org.eclipse.jkube.generator.api.GeneratorContext;
import mockit.Expectations;
import mockit.Mocked;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -56,6 +60,8 @@ public class BaseGeneratorTest {
@Mocked
private ProcessorConfig config;

@Rule
public TemporaryFolder folder= new TemporaryFolder();

@Test
public void fromAsConfigured() {
Expand Down Expand Up @@ -205,10 +211,29 @@ public void shouldAddDefaultImage(@Mocked final ImageConfiguration ic1, @Mocked
ic2.getBuildConfiguration(); result = null; minTimes = 0;
}};
BaseGenerator generator = createGenerator(null);
assertTrue(generator.shouldAddImageConfiguration(Collections.<ImageConfiguration>emptyList()));
assertTrue(generator.shouldAddImageConfiguration(Collections.emptyList()));
assertFalse(generator.shouldAddImageConfiguration(Arrays.asList(ic1, ic2)));
assertTrue(generator.shouldAddImageConfiguration(Arrays.asList(ic2)));
assertFalse(generator.shouldAddImageConfiguration(Arrays.asList(ic1)));
assertTrue(generator.shouldAddImageConfiguration(Collections.singletonList(ic2)));
assertFalse(generator.shouldAddImageConfiguration(Collections.singletonList(ic1)));
}

@Test
public void shouldNotAddDefaultImageInCaseOfSimpleDockerfile() throws IOException {
// Given
File projectBaseDir = folder.newFolder("test-project-dir");
File dockerFile = new File(projectBaseDir, "Dockerfile");
boolean isTestDockerfileCreated = dockerFile.createNewFile();
new Expectations() {{
ctx.getProject(); result = project;
project.getBaseDirectory(); result = projectBaseDir;
}};

// When
BaseGenerator generator = createGenerator(null);

// Then
assertTrue(isTestDockerfileCreated);
assertFalse(generator.shouldAddImageConfiguration(Collections.emptyList()));
}

@Test
Expand Down

0 comments on commit 8f4bf3e

Please sign in to comment.