-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor (jkube-kit) : Move Dockerfile opinionated ImageConfig logic …
…from `ConfigHelper.initImageConfiguration` to a dedicated generator + ConfigHelper modifies the provided set of ImageConfigurations when it detects a `Dockerfile` in project root directory. This is actually a feature called Simple Dockerfile Mode. However, this mutation of ImageConfiguration from within `initImageConfiguration` does not look appropriate. It can be moved to a dedicated generator that will get activated when `Dockerfile` is present in project base directory. + Add a new generator SimpleDockerfileGenerator, it adds a simple ImageConfiguration with Dockerfile configured in build and adds it to existing set of ImageConfigurations. Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
df35e19
commit ce63991
Showing
18 changed files
with
353 additions
and
112 deletions.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-parent</artifactId> | ||
<version>1.17-SNAPSHOT</version> | ||
<relativePath>../../parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>jkube-kit-generator-dockerfile-simple</artifactId> | ||
|
||
<name>JKube Kit :: Generator :: Dockerfile Simple</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-generator-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
67 changes: 67 additions & 0 deletions
67
...rc/main/java/org/eclipse/jkube/generator/dockerfile/simple/SimpleDockerfileGenerator.java
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,67 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.generator.dockerfile.simple; | ||
|
||
import org.eclipse.jkube.generator.api.GeneratorContext; | ||
import org.eclipse.jkube.generator.api.support.BaseGenerator; | ||
import org.eclipse.jkube.kit.build.api.helper.ImageNameFormatter; | ||
import org.eclipse.jkube.kit.common.JKubeException; | ||
import org.eclipse.jkube.kit.config.image.ImageConfiguration; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.eclipse.jkube.kit.build.api.helper.DockerFileUtil.addSimpleDockerfileConfig; | ||
import static org.eclipse.jkube.kit.build.api.helper.DockerFileUtil.createSimpleDockerfileConfig; | ||
import static org.eclipse.jkube.kit.build.api.helper.DockerFileUtil.getTopLevelDockerfile; | ||
import static org.eclipse.jkube.kit.build.api.helper.DockerFileUtil.isSimpleDockerFileMode; | ||
import static org.eclipse.jkube.kit.common.util.BuildReferenceDateUtil.getBuildTimestamp; | ||
import static org.eclipse.jkube.kit.common.util.PropertiesUtil.getValueFromProperties; | ||
|
||
public class SimpleDockerfileGenerator extends BaseGenerator { | ||
public SimpleDockerfileGenerator(GeneratorContext context) { | ||
super(context, "dockerfile-simple"); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(List<ImageConfiguration> configs) { | ||
return isSimpleDockerFileMode(getContext().getProject().getBaseDirectory()) && | ||
(configs.isEmpty() || configs.get(0).getBuild() == null); | ||
} | ||
|
||
@Override | ||
public List<ImageConfiguration> customize(List<ImageConfiguration> configs, boolean prePackagePhase) { | ||
ImageNameFormatter imageNameFormatter = new ImageNameFormatter(getContext().getProject(), extractBuildTimestampFromProject()); | ||
File topDockerfile = getTopLevelDockerfile(getContext().getProject().getBaseDirectory()); | ||
String defaultImageName = imageNameFormatter.format(getValueFromProperties(getContext().getProject().getProperties(), | ||
"jkube.image.name", "jkube.generator.name")); | ||
if (configs.isEmpty()) { | ||
configs.add(createSimpleDockerfileConfig(topDockerfile, defaultImageName)); | ||
} else if (configs.size() == 1 && configs.get(0).getBuildConfiguration() == null) { | ||
configs.set(0, addSimpleDockerfileConfig(configs.get(0), topDockerfile)); | ||
} | ||
return configs; | ||
} | ||
|
||
private Date extractBuildTimestampFromProject() { | ||
try { | ||
return getBuildTimestamp(null, null, getContext().getProject().getBuildDirectory().getAbsolutePath(), | ||
"docker/build.timestamp"); | ||
} catch (IOException ioException) { | ||
throw JKubeException.launderThrowable("failure in extract project build timestamp", ioException); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
jkube-kit/generator/dockerfile-simple/src/main/resources/META-INF/jkube/generator-default
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,5 @@ | ||
# The order of the generators used is defined in the active profile | ||
# (which is the profile "default" by default) | ||
# You can find the default profiles in "profiles-default.yml" | ||
|
||
org.eclipse.jkube.generator.dockerfile.simple.SimpleDockerfileGenerator |
Oops, something went wrong.