question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_skaffold-init task multimodule logic issues

See original GitHub issue

The issues with the current logic (at least in the maven plugin, gradle task might have the same issues):

  • when a submodule has a different parent specified (e.g. spring boot starter pom) then our current logic fails to set the project id as the parent comes back as null in the InitMojo - this creates issues in multimodule projects (e.g. the Cloud Code java guestbook sample) because the listed projects don’t have anything in them
  • I’m not sure how frequent nested modules are but currently we don’t handle those well either
  • we are using the artifactId instead of the module name to return a project which is a problem as that is interpreted on the skaffold side as a directory

I won’t have time to fully implement the thing with tests and everything, but as I played around with the code this seemed to do the job altogether:

@Mojo(name = InitMojo.GOAL_NAME, requiresDependencyCollection = ResolutionScope.NONE)
public class InitMojo extends JibPluginConfiguration {

  @VisibleForTesting static final String GOAL_NAME = "_skaffold-init";

  @Override
  public void execute() throws MojoExecutionException {
    checkJibVersion();
    MavenProject project = getProject();
    MavenProject topLevelProject = getSession().getTopLevelProject();
    if (!project.equals(topLevelProject)) {
      return;
    }

    if (isParentProject(project)) {
      Set<MavenProject> projects = collectLeafProjects(project);
      for (MavenProject p : projects) {
        print(p, true);
      }
    } else {
      print(project, false);
    }
  }

  private Set<MavenProject> collectLeafProjects(MavenProject project) {
    Set<MavenProject> projects = new HashSet<>();
    for (MavenProject p : project.getCollectedProjects()) {
      if (isParentProject(p)) {
        projects.addAll(collectLeafProjects(p));
      } else {
        projects.add(p);
      }
    }
    return projects;
  }

  private boolean isParentProject(MavenProject project) {
    return project.getPackaging().equals("pom") && project.getModules().size() > 0;
  }

  private void print(MavenProject project, boolean setProject) throws MojoExecutionException {
    SkaffoldInitOutput skaffoldInitOutput = new SkaffoldInitOutput();
    skaffoldInitOutput.setImage(getTargetImage());
    if (setProject) {
      skaffoldInitOutput.setProject(project.getGroupId() + ":" + project.getArtifactId());
    }
    System.out.println();
    System.out.println("BEGIN JIB JSON");
    try {
      System.out.println(skaffoldInitOutput.getJsonString());
    } catch (IOException ex) {
      throw new MojoExecutionException(ex.getMessage(), ex);
    }
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chanseokohcommented, Feb 25, 2020

@balopat @jonjohnsonjr we’ve released Jib 2.1.0, which fixes this issue.

0reactions
jonjohnsonjrcommented, Feb 11, 2020

For posterity, I’ll chime in to say my issue is now fixed.

Before

$ skaffold init --XXenableJibInit --analyze | jq .
{
  "builders": [
    {
      "name": "Jib Maven Plugin",
      "payload": {
        "path": "pom.xml"
      }
    },
    {
      "name": "Jib Maven Plugin",
      "payload": {
        "path": "pom.xml"
      }
    },
    {
      "name": "Docker",
      "payload": {
        "path": "backend/Dockerfile"
      }
    },
    {
      "name": "Docker",
      "payload": {
        "path": "frontend/Dockerfile"
      }
    }
  ],
  "images": [
    {
      "name": "java-guestbook-backend",
      "foundMatch": false
    },
    {
      "name": "java-guestbook-frontend",
      "foundMatch": false
    },
    {
      "name": "mongo",
      "foundMatch": false
    }
  ]
}

After

$ skaffold init --XXenableJibInit --analyze | jq .
{
  "builders": [
    {
      "name": "Jib Maven Plugin",
      "payload": {
        "path": "pom.xml",
        "project": "org.springframework.boot:frontend"
      }
    },
    {
      "name": "Jib Maven Plugin",
      "payload": {
        "path": "pom.xml",
        "project": "org.springframework.boot:backend"
      }
    },
    {
      "name": "Docker",
      "payload": {
        "path": "backend/Dockerfile"
      }
    },
    {
      "name": "Docker",
      "payload": {
        "path": "frontend/Dockerfile"
      }
    }
  ],
  "images": [
    {
      "name": "java-guestbook-backend",
      "foundMatch": false
    },
    {
      "name": "java-guestbook-frontend",
      "foundMatch": false
    },
    {
      "name": "mongo",
      "foundMatch": false
    }
  ]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Init - Skaffold
skaffold init walks your project directory and looks for any build configuration files such as Dockerfile , build.gradle/pom.xml ...
Read more >
Kubernetes Development Environment with Skaffold
The purpose of these labs is to help you learn Kubernetes by solving different tasks, such as creating pods, scaling deployments, and so...
Read more >
CHANGELOG.md · Whoisxiang/skaffold - Gitee.com
Highlights: skaffold init now supports Java and Python projects with Buildpacks projects; A bunch of debug improvements to skaffold debug; skaffold render can ......
Read more >
How we reduced our Gradle build times by over 80%
If you're working on a multi-module project, then forcing Gradle to execute tasks in parallel is ... Convert build logic to static tasks....
Read more >
Guide: Docker to Kubernetes Migration - IT Outposts
Will you have the resources to modify your application's logic if it needs to ... With the command skaffold init, a project can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found