Skip to content

Commit

Permalink
Fix NPE when cacheFrom is missing from config fabric8io#1274
Browse files Browse the repository at this point in the history
  • Loading branch information
travishaagen authored and Travis Haagen committed Oct 9, 2019
1 parent da1e203 commit 836ec71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private BuildImageConfiguration extractBuildConfiguration(ImageConfiguration fro
.cmd(extractArguments(valueProvider, CMD, config == null ? null : config.getCmd()))
.cleanup(valueProvider.getString(CLEANUP, config == null ? null : config.getCleanup()))
.noCache(valueProvider.getBoolean(NO_CACHE, config == null ? null : config.getNoCache()))
.cacheFrom(valueProvider.getString(CACHE_FROM, config == null ? null : config.getCacheFrom().toString()))
.cacheFrom(valueProvider.getString(CACHE_FROM, config == null ? null : (config.getCacheFrom() == null ? null : config.getCacheFrom().toString())))
.optimise(valueProvider.getBoolean(OPTIMISE, config == null ? null : config.getOptimise()))
.entryPoint(extractArguments(valueProvider, ENTRYPOINT, config == null ? null : config.getEntryPoint()))
.assembly(extractAssembly(config == null ? null : config.getAssemblyConfiguration(), valueProvider))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,22 @@ public void testCacheFrom() {
assertEquals(Collections.singletonList("foo/bar:latest"), config.getBuildConfiguration().getCacheFrom());
}

@Test
public void testCacheFromIsNullInBuildConfig() {
imageConfiguration = new ImageConfiguration.Builder()
.externalConfig(new HashMap<>())
.buildConfig(new BuildImageConfiguration.Builder().build())
.build();

List<ImageConfiguration> configs = resolveImage(
imageConfiguration,props(
"docker.name","demo",
"docker.from", "busybox"
));

assertNull(configs.get(0).getBuildConfiguration().getCacheFrom().get(0));
}

@Test
public void testNoOptimise() throws Exception {
String[] testData = new String[] {k(ConfigKey.NAME), "image", k(ConfigKey.OPTIMISE), "false", k(ConfigKey.FROM), "base" };
Expand Down

0 comments on commit 836ec71

Please sign in to comment.