Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Fix #825 : More flexible S2I binary build data format #1355

Closed
wants to merge 1 commit into from

Conversation

rohanKanojia
Copy link
Member

@rhuss
Copy link
Contributor

rhuss commented Aug 14, 2018

Awesome, thanks a lot @rohanKanojia ! Unfortunately I only can have a look at it as I'm on PTO for the rest of the week (+ Monday next week). I hope that I can then work fulltime on fmp as the last two weeks were eaten by my other work (we are about to release Fuse 7.1).

sorry for that.

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a first round of reviews which you might want to address.

Currently I'm not so happy about the build service in genereal (and how things are moved around), so will wrap my brain around this.

btw, feel free to use lambdas, too (like for filtering the file names).

@@ -35,7 +35,7 @@
*
* @param imageConfig the image to build
*/
void build(ImageConfiguration imageConfig) throws Fabric8ServiceException;
void build(ImageConfiguration imageConfig, BinaryInputArchiveBuilder binaryInputArchiveBuilder) throws Fabric8ServiceException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bad smell to add a parameter which is useful only for a particular implementation. I.e. the BuildService itself shoudl be agnostic of any implementation, but by adding an OpenShift specific build you directly couple it with the OpenShift build mechanism.

}
private File createEmptyTargetDir() {
File targetDir = new File(config.getBuildDirectory(), "docker");
targetDir.mkdirs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should check the return value

boolean bAllFilesDeleted = true;
String[] files = parentDir.list(filterNameFilter);

if(files.length == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

files can be null, too

@@ -55,4 +56,21 @@ public static String getAbsolutePath(URL url) {
throw new RuntimeException(e);
}
}

public static boolean deleteFilesInDirectory(File parentDir, FilenameFilter filterNameFilter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value is not really used

File fileToDelete = null;
for(String file : files) {
String absoluteFilePath = parentDir.getAbsolutePath() + File.separator + file;
fileToDelete = new File(absoluteFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's about just new File(parentDir, file) ?

@Override
public void createBinaryInput(ServiceHub hub, File binaryInputDirectory, ImageConfiguration imageConfiguration) throws Fabric8ServiceException {
try {
File targetDirectory = new File(config.getBuildDirectory());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here and in the WebApp generator look quite the same. Shouldn't we extract it into an external class which then is used here and in the Webapp generator ?

import java.util.Arrays;
import java.util.List;

public class OpenshiftWildFlyS2IHandler extends AbstractAppServerHandler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure about the name. What's the difference the WildFlyAppServerHandler ?


public class OpenshiftWildFlyS2IHandler extends AbstractAppServerHandler {
public OpenshiftWildFlyS2IHandler(MavenProject project) {
super("tomcat", project);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"tomcat" sounds fishy here.

public boolean isApplicable() {
if(PlatformMode.isOpenShiftMode(project.getProperties())) {
return hasOneOf("**/META-INF/context.xml") ||
MavenUtil.hasPlugin(project, "org.apache.tomcat.maven:tomcat6-maven-plugin") ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is a tomcat maven plugin an indicator for this wildfly handler ?

@@ -73,6 +73,7 @@
<!-- Upstream -->
<version.image.java.upstream.docker>1.5</version.image.java.upstream.docker>
<version.image.java.upstream.s2i>2.3</version.image.java.upstream.s2i>
<version.image.webapp.upstream.s2i>latest</version.image.webapp.upstream.s2i>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't use latest in our deps if not for a very good reason. Can't we stick to a version, like for the other images ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, there doesn't seem to be any other tag here: https://hub.docker.com/r/openshift/wildfly-101-centos7/tags/

@codecov
Copy link

codecov bot commented Sep 17, 2018

Codecov Report

Merging #1355 into master will decrease coverage by 0.12%.
The diff coverage is 26.86%.

@@             Coverage Diff              @@
##             master    #1355      +/-   ##
============================================
- Coverage     31.85%   31.73%   -0.13%     
- Complexity     1001     1007       +6     
============================================
  Files           174      177       +3     
  Lines          9915    10000      +85     
  Branches       1790     1800      +10     
============================================
+ Hits           3158     3173      +15     
- Misses         6406     6472      +66     
- Partials        351      355       +4

} catch (IOException e) {
throw new Fabric8ServiceException("Unable to add environment variables to the S2I build archive", e);
}
File tarFile = File.createTempFile(config.getArtifactId().toString(), ".tar");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understand this: tarFile is a temporary tar filename but the tar archive itself is created with the destFile as name. The return value is then a the temporary name (which doesn't point to any tar archive if I understood the code right). Could you please check this again ?

}
File tarFile = File.createTempFile(config.getArtifactId().toString(), ".tar");
File destFile = new File(targetDir, config.getArtifactId() + ".tar");
tarArchiver.setDestFile(destFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not sure that this works if you put the destination file into the directory that you tar up (as it would be tar up itself, too)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naiively I would expect a

tarArchiver.setDestFile(tarFile);
tarArchiver.createArchive();
return tarFile;

and removing destFile ....

File targetDir = createEmptyTargetDir();

// Fill the directory with the data in the right directory structure
binaryInputArchiveBuilder.createBinaryInput(dockerServiceHub, targetDir, imageConfig);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's about adding a File return value to the BinaryInputArchiveBuilder which then holds the the TAR archive ?

Advantages:

  • Get rid of createTar() method
  • Simplify interface to one method
  • No need for the targetDir parameter. This just would be an implementation details.

If you don't mind I would change it like this and push it to your branch (just to speed up things and to clarify my point).

@rohanKanojia would this be ok for you ?

return hasOneOf("**/META-INF/context.xml") ||
MavenUtil.hasPlugin(project, "org.apache.tomcat.maven:tomcat6-maven-plugin") ||
MavenUtil.hasPlugin(project, "org.apache.tomcat.maven:tomcat7-maven-plugin");
if(!PlatformMode.isOpenShiftMode(project.getProperties())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation of this check ?

@Override
public boolean isApplicable() {
if(PlatformMode.isOpenShiftMode(project.getProperties())) {
return hasOneOf("**/META-INF/context.xml") || project.getPackaging().equals("war");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. You have a dedicated handler only for s2i build ?. But shouldn't we just check then for the packaging ? Not sure why a JAR archive with a "**/META-INF/context.xml" should be considered as a war file.

@rhuss
Copy link
Contributor

rhuss commented Oct 3, 2018

@rohanKanojia Thanks a lot for your changes which adhere to the comments I did. However while reviewing and some minor refactorings, I thought again about this PR and I now believe, that a Generator shouldn't be actually responsible for the creation of the binary input.

Why? Well, because a generator is only about creating the configuration of an image which then can be created in multiple ways (docker, s2i binary, s2i docker, ...). So the generator should be agnostic of the concrete creation of the image.

What now? The generator selects a base image and the base image is actually that part which in the s2i binary input case determines the format of the binary input. So my suggestion would be to either examine the generated images for the 'from' images or evaluate a certain meta-data (label) which could be set by the generator. Then a kind of 'BinaryBuildSelector' would examine this base image and creates the binary input which fits this s2i builder image.

Does this make sense? If so, I would like to postpone this story for the next sprint implement it in a generator independent way.

@rohanKanojia
Copy link
Member Author

@rhuss : ah, okay

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
target/4.0 PR for targeted to 4.0.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants