Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker run failed #2228

Closed
SandNight opened this issue Jan 14, 2020 · 10 comments
Closed

docker run failed #2228

SandNight opened this issue Jan 14, 2020 · 10 comments
Milestone

Comments

@SandNight
Copy link

SandNight commented Jan 14, 2020

Environment:

  • Jib version: 1.8.0
  • Build tool: Maven 3.6.1
  • OS: Mac 10.15.2

Description of the issue:

run jib-maven-plugin:1.8.0:dockerBuild in idea
the image build successful
but when I run this image, failed

Maybe the JDK configuration is wrong
What should I do

Expected behavior:
run success

Steps to reproduce:

  1. dockerBuild
  2. run image

jib-maven-plugin Configuration:

<plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>1.8.0</version>
                <configuration>
                    <to>
                        <image>harbor.test.com/${project.parent.artifactId}/${project.artifactId}:${env}-${project.version}</image>
                    </to>
                    <from>
                        <image>openjdk:alpine</image>
                    </from>
                    <container>
                        <mainClass>com.test.auth.server.AuthServerApplication</mainClass>
                        <jvmFlags>
                            <jvmFlag>-Xms512m</jvmFlag>
                        </jvmFlags>
                        <ports>
                            <port>9082</port>
                        </ports>
                        <environment>
                            <TZ>Asia/Shanghai</TZ>
                        </environment>
                        <volumes>/tmp</volumes>
                        <useCurrentTimestamp>true</useCurrentTimestamp>
                        <labels>
                            <maintainer>jade</maintainer>
                        </labels>
                    </container>
                    <allowInsecureRegistries>true</allowInsecureRegistries>
                </configuration>
            </plugin>

Log output:

/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/java -Dvisualvm.id=2681117957594 -Dmaven.multiModuleProjectDirectory=/Users/jade/work/workspace/test/test-auth/test-auth-server -Dmaven.home=/Users/jade/work/software/apache-maven-3.6.1 -Dclassworlds.conf=/Users/jade/work/software/apache-maven-3.6.1/bin/m2.conf "-Dmaven.ext.class.path=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven-event-listener.jar" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50153:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath /Users/jade/work/software/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version2019.3.1 -s /Users/jade/work/software/apache-maven-3.6.1/conf/settings.xml -DskipTests=true com.google.cloud.tools:jib-maven-plugin:1.8.0:dockerBuild -P dev
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.test:test-auth-server:jar:1.0-SNAPSHOT
[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.alibaba:fastjson:jar -> duplicate declaration of version 1.2.60 @ com.test:test-dependencies:1.0.2, /Users/jade/work/software/maven_repository/com/test/test-dependencies/1.0.2/test-dependencies-1.0.2.pom, line 3179, column 25
[WARNING] 'dependencyManagement.dependencies.dependency.version' for com.test.cloud:test-cloud-starter:jar is either LATEST or RELEASE (both of them are being deprecated) @ com.test:test-dependencies:1.0.2, /Users/jade/work/software/maven_repository/com/test/test-dependencies/1.0.2/test-dependencies-1.0.2.pom, line 3187, column 26
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ----------------------< com.test:test-auth-server >-----------------------
[INFO] Building test-auth-server 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-auth-api/1.0.4-SNAPSHOT/maven-metadata.xml
Downloaded from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-auth-api/1.0.4-SNAPSHOT/maven-metadata.xml (772 B at 3.4 kB/s)
Downloading from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/cloud/test-cloud-starter/1.0.6-SNAPSHOT/maven-metadata.xml
Downloaded from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/cloud/test-cloud-starter/1.0.6-SNAPSHOT/maven-metadata.xml (780 B at 52 kB/s)
Downloading from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-utils/1.0-SNAPSHOT/maven-metadata.xml
Downloaded from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-utils/1.0-SNAPSHOT/maven-metadata.xml (760 B at 51 kB/s)
Downloading from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-base/1.0-SNAPSHOT/maven-metadata.xml
Downloaded from test: http://172.16.6.124:8044/nexus/repository/maven-public/com/test/test-base/1.0-SNAPSHOT/maven-metadata.xml (588 B at 42 kB/s)
[INFO]
[INFO] --- jib-maven-plugin:1.8.0:dockerBuild (default-cli) @ test-auth-server ---
[WARNING] is deprecated; use with the value USE_CURRENT_TIMESTAMP instead
[WARNING] Setting image creation time to current time; your image may not be reproducible.
[INFO]
[INFO] Containerizing application to Docker daemon as harbor.test.com/test-auth/test-auth-server:dev-1.0-SNAPSHOT...
[WARNING] Base image 'openjdk:alpine' does not use a specific image digest - build may not be reproducible
[INFO] Getting manifest for base image openjdk:alpine...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building snapshot dependencies layer...
[INFO] Building classes layer...
[INFO] The base image requires auth. Trying again for openjdk:alpine...
[INFO] Retrieving registry credentials for registry-1.docker.io...
[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry-1.docker.io

Got output:

credentials not found in native keychain

[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: registry.hub.docker.com

Got output:

credentials not found in native keychain

[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: index.docker.io

Got output:

credentials not found in native keychain

[WARNING] The credential helper (docker-credential-desktop) has nothing for server URL: docker.io

Got output:

credentials not found in native keychain

[INFO] Using base image with digest: sha256:d4c84528b8de75bf40ef402e7b02ffe60c5ae834a702e510664be1f6fc03d510
[INFO]
[INFO] Container entrypoint set to [java, -Xms512m, -cp, /app/resources:/app/classes:/app/libs/*, com.test.auth.server.AuthServerApplication]
[INFO] Loading to Docker daemon...
[INFO]
[INFO] Built image to Docker daemon as harbor.test.com/test-auth/test-auth-server:dev-1.0-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.254 s
[INFO] Finished at: 2020-01-14T09:34:38+08:00
[INFO] ------------------------------------------------------------------------

docker run log
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(Ljava/lang/Class;Ljava/lang/ClassLoader;)Ljava/util/List; from class org.springframework.boot.SpringApplication
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.(SpringApplication.java:268)
at org.springframework.boot.SpringApplication.(SpringApplication.java:249)
at org.springframework.boot.builder.SpringApplicationBuilder.createSpringApplication(SpringApplicationBuilder.java:104)
at org.springframework.boot.builder.SpringApplicationBuilder.(SpringApplicationBuilder.java:92)
at com.test.auth.server.AuthServerApplication.main(AuthServerApplication.java:22)

Additional Information:
host
172.16.5.111 harbor.test.com

@chanseokoh
Copy link
Member

Hi @SandNight, could you share a sample repo?

@kan-izh
Copy link

kan-izh commented Jan 14, 2020

I am pretty sure there are conflicting versions of Spring dependencies. So, nothing to do with Jib. Even if the app works locally, it may fail in docker just because .jars are placed into the classpath in random order and different classes are loaded.

@loosebazooka
Copy link
Member

loosebazooka commented Jan 15, 2020

as @kan-izh said, it's quite possible that the ordering of dependency loading is messing this up. Especially if this works locally.

Can you run

mvn dependency:copy-dependencies

inspect the copied dependencies by looking for SpringFactoriesLoader (assuming linux)

cd target/dependency
grep SpringFactoriesLoader.class -r *

presumably if the theory holds true, you will see more than one instance of this class in multiple jar files?

@SandNight
Copy link
Author

as @kan-izh said, it's quite possible that the ordering of dependency loading is messing this up. Especially if this works locally.

Can you run

mvn dependency:copy-dependencies

inspect the copied dependencies by looking for SpringFactoriesLoader (assuming linux)

cd target/dependency
grep SpringFactoriesLoader.class -r *

presumably if the theory holds true, you will see more than one instance of this class in multiple jar files?

thank you,I should have found the problem

$ grep SpringFactoriesLoader.class -r *
Binary file org.springframework.core-3.2.2.RELEASE.jar matches
Binary file spring-core-5.1.8.RELEASE.jar matches

@loosebazooka
Copy link
Member

So there are two parts of this problem:

  1. jib does not currently preserve the classpath order of dependencies specified in the build file.
  2. You are importing spring-core twice, can you share more of your buildfile so we can see what's going on?

@chanseokoh
Copy link
Member

chanseokoh commented Jan 16, 2020

Yeah, it is an open issue in Jib that the dependency loading order at runtime is not the same order as defined in pom.xml. You might find some useful into in #1907 and #1871 (possibly a workaround). But it'd be ideal to remove duplicate classes from your dependencies (if possible).

@suztomo
Copy link
Contributor

suztomo commented Jan 16, 2020

@SandNight I'm interested in the problem. I develop Linkage Checker Enforcer rule to detect such incompatible libraries in your project:
https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/Linkage-Checker-Enforcer-Rule. When you have time, would you try this out? (or share a sample repository to reproduce the problem?)

@elharo
Copy link
Contributor

elharo commented Jan 17, 2020

Try building this with Java 11. That might detect split package issues and same classes in multiple jars that Java 8 won't warn about.

@chanseokoh
Copy link
Member

chanseokoh commented Jan 23, 2020

@SandNight we didn't hear from you for a while. We will assume that the issue is due to a class loading order at runtime that is different from that of the dependency order listed in your pom.xml. I will close this as a dup of #1871 and #1907. Feel free to re-open if you think this is not.

@chanseokoh
Copy link
Member

@SandNight @kan-izh we've released Jib 2.7.0 which added a new configuration option (jib.container.expandClasspathDependencies (Gradle) / <container><expandClasspathDependencies> (Maven)) that enables expanding classpath dependencies in the default java command for an image ENTRYPOINT. Turning on the option (off by default) will enumerate all the dependencies, which will match the dependency loading order in Maven or Gradle builds. For example, the ENTRYPOINT becomes

java ... -cp /app/resources:/app/classes:/app/libs/spring-boot-starter-web-2.0.3.RELEASE.jar:/app/libs/shared-library-0.1.0.jar:/app/libs/spring-boot-starter-json-2.0.3.RELEASE.jar:... com.example.Main

instead of the default

java ... -cp /app/resources:/app/classes:/app/libs/* com.example.Main

Expanding the dependency list can be useful in AppCDS too.

Note that an expanded dependency list can become very long in practice, and we are not sure if there may be a potential issue due to a long command line ("argument list too long" or "command line is too long").

As with other Jib configurations, this option can also be set through the system property (-Djib.container.expandClasspathDependencies=true|false).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants