-1

I'm building my images using pack cli:

pack build fhir-mongo --builder paketobuildpacks/builder:base --path target/hes-mpi-fhir-mongodb-service-0.0.1-SNAPSHOT.jar

This is my project structure:

.
├── hes-mpi-fhir-mongodb
│  ├── deployment.yaml
│  ├── pom.xml
│  ├── skaffold.yaml
│  └──  src
└── hes-spring-boot-core     <<< dependency requiered by hes-mpi-fhir-mongodb
   ├── pom.xml
   └── src

As you can see, I managing two maven projects.

My host building steps are:

$ hes-spring-boot-core > mvn clean install
$ hes-mpi-fhir-mongodb > mvn clean package

I mean, I first install hes-spring-boot-core into local repository and then I build hes-mpi-fhir-mongodb:

My skaffold.yml file is:

apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: hes-mpi-fhir-mongodb
build:
  artifacts:
  - image: pom-xml-image
    buildpacks:
      builder: paketobuildpacks/builder:base
profiles:
  - name: dev
    deploy:
      kustomize:
        paths: ["kustomize/dev"]

I'm getting this message, when I'm trying to build image:

...
[builder] Running "/layers/google.java.maven/maven/bin/mvn clean package --batch-mode -DskipTests -Dhttp.keepAlive=false --quiet"
[builder] [ERROR] Failed to execute goal on project hes-mpi-fhir-mongodb-service: Could not resolve dependencies for project cat.gencat.catsalut.hes.mpi.fhir:hes-mpi-fhir-mongodb-service:jar:0.0.1-SNAPSHOT: Could not find artifact cat.gencat.catsalut.hes:hes-spring-boot-core:jar:1.0.6 in central (https://repo.maven.apache.org/maven2)

It's getting me that maven builder is not able to find artifact cat.gencat.catsalut.hes:hes-spring-boot-core:jar:1.0.6.

This error doesn't appear when I perform above pack cli command!

How can I add this project as a dependency?

I've took a look on documentation. There are some fields that are messing me:

dependencies: file dependencies that skaffold should watch for both rebuilding and file syncing for this artifact.

Artifact Dependency: You can define dependency on other artifacts using the requires keyword. This can be useful to specify another artifact image as the builder or runImage.

I'm using skaffold v1.35.1.

Information

  • Skaffold version: 1.35.1
  • Operating system:
  • Installed via: skaffold.dev
  • Contents of skaffold.yaml:
apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: hes-mpi-fhir-mongodb
build:
  artifacts:
  - image: pom-xml-image
    context: target/hes-mpi-fhir-mongodb-service-0.0.1-SNAPSHOT.jar
    buildpacks:
      builder: paketobuildpacks/builder:base
      dependencies:
        paths:
          - "target/hes-mpi-fhir-mongodb-service-0.0.1-SNAPSHOT.jar"
    # requires:
    #   - image: core
profiles:
  - name: dev
    deploy:
      kustomize:
        paths: ["kustomize/dev"]

Also I've tried to build two images. But problem arises.

apiVersion: skaffold/v2beta26
kind: Config
metadata:
  name: hes-mpi-fhir-mongodb
build:
  artifacts:
  - image: core
    context: ../hes-spring-boot-core
    buildpacks:
      builder: paketobuildpacks/builder:base
      env:
        - "BP_MAVEN_BUILD_ARGUMENTS=install"
  - image: pom-xml-image
    # context: target/hes-mpi-fhir-mongodb-service-0.0.1-SNAPSHOT.jar
    buildpacks:
      builder: paketobuildpacks/builder:base
      dependencies:
        paths:
          - "target/hes-mpi-fhir-mongodb-service-0.0.1-SNAPSHOT.jar"
    requires:
      - image: core
profiles:
  - name: dev
    deploy:
      kustomize:
        paths: ["kustomize/dev"]

Jordi
  • 20,868
  • 39
  • 149
  • 333

2 Answers2

1

I don't really understand fully what's going on from your description, but it seems rather complex.

I think you're producing several jar files from a Maven build and then looking to use Skaffold with buildpacks to package up those resulting jars into a container image. There is a risk here that you may package up stale jar files. To my mind, the better solution is to either have your Maven build create the jars and container images (e.g., using Jib, or Spring Boot's image creation), or use Skaffold to orchestrate the Maven build and build the container images.

Another complication is that Buildpacks builds are isolated from the local file system by being run in a docker container. When a buildpacks build is triggered, part of the local file system is copied into the container, and the build then has no further access to the local file system. For pack build, this copy is rooted in the current directory. For a Skaffold-triggered build, this copy is rooted from the context field, which defaults to the current directory. The buildpacks won't see any files outside of this copy. So a mvn install performed as part of one artifact's buildpacks build will not be seen in another.


If you're just looking to build and then package up your jars into a container image, consider looking at Jib. Jib provides a Maven plugin and is easily integrated into your existing Maven builds. It supports Spring apps, and it uses some nifty tricks to speed up packaging images. You can use profiles and binding goals to phases to decide when to produce an image.

Skaffold also has native support for using Jib.

I don't know if the Paketo Java buildpacks support building multi-module projects, but the GCP Java Buildpacks do not currently.


Aside: your build error includes a reference to /layers/google.java.maven, which indicates that you're trying the GCP Buildpacks.

Brian de Alwis
  • 2,814
  • 2
  • 18
  • 32
  • 1
    The Paketo Java buildpack will work with a multi-module Maven project, but you will probably need to point it to the artifact that you want to propagate from the build into the container image (it only accepts one at the moment). You set `$BP_MAVEN_BUILT_ARTIFACT` to the artifact, it defaults to `target/*.[ejw]ar`. – Daniel Mikusa Jan 08 '22 at 03:58
  • GCP Buildpacks can work with multi-module projects in a similar but more limited way by having the root module create a single artifact such as using the maven shade plugin. – Brian de Alwis Jan 11 '22 at 15:37
0

I came across the same problem and managed to fix it by overriding mvn BP_MAVEN_BUILD_ARGUMENTS and BP_MAVEN_BUILT_ARTIFACT . Assuming you are using a parent maven project and the two projects are submodules of the parent. The skaffold.yaml will look like:

buildpacks:
  builder: paketobuildpacks/builder:base
  env:
  - "BP_MAVEN_BUILD_ARGUMENTS=--projects hes-spring-boot-core,hes-mpi-fhir-mongodb --also-make package -DskipTests"
  - "BP_MAVEN_BUILT_ARTIFACT=hes-mpi-fhir-mongodb/target/*.jar"

This builds both the projects in one single command. Beware that the context should be the root.