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

Intermittent build failures with jib-maven-plugin #4180

Open
kumarineha304 opened this issue Jan 31, 2024 · 3 comments
Open

Intermittent build failures with jib-maven-plugin #4180

kumarineha304 opened this issue Jan 31, 2024 · 3 comments

Comments

@kumarineha304
Copy link

kumarineha304 commented Jan 31, 2024

I have below jib-maven-plugin dependency added in my maven pom.xml file as below:

<plugin>
              <groupId>com.google.cloud.tools</groupId>
              <artifactId>jib-maven-plugin</artifactId>
              <version>${jib-maven-plugin.version}</version>
              <configuration>
                <skip>true</skip>
                <from>
                  <image>${jib-maven-plugin.image}</image>
                  <credHelper>ecr-login</credHelper>
                  <platforms>
                    <platform>
                      <architecture>${jib-maven-plugin.architecture}</architecture>
                      <os>linux</os>
                    </platform>
                  </platforms>
                </from>
                <to>
                  <credHelper>ecr-login</credHelper>
                </to>
                <container>
                  <entrypoint>
                    <shell>bash</shell>
                    <option>-c</option>
                    <arg>/entrypoint.sh</arg>
                  </entrypoint>
                  <environment>
                    <SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
                  </environment>
                  <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
                  <user>9002</user>
                  <workingDirectory>/home/javarun</workingDirectory>
                </container>
              </configuration>
            </plugin>

Usually my build runs completely fine and all images are built as expected but there are intermittent failure issues where the build starts failing and fails continuously for 2-3 days sometimes a week and then gets fixed on its own all of a sudden.

I get below error when the build fails:
Error: -04 12:46:45.430000: [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:3.3.1:dockerBuild (default-cli) on project demo-service: Obtaining project build output files failed; make sure you have compiled your project before trying to build the image. (Did you accidentally run "mvn clean jib:build" instead of "mvn clean compile jib:build"?): /codebuild/output/src3077/src/DemoService/demo-service/target/classes -> [Help 1]
Error: -04 12:46:45.430000: [ERROR]

@chanseokoh
Copy link
Member

chanseokoh commented Jan 31, 2024

The exception is thrown here.

I guess your project is not a war project, right? Then what the code does is simple: retrieving project build output (e.g., compiled .class files, dependency .jars, resource files, etc.), and normally, it won't throw an IOException (except for the obvious case where /codebuild/output/src3077/src/DemoService/demo-service/target/classes doesn't exist, which means you didn't compile your project or somehow Jib ran before Maven had a chance to create the directory).

But looking at this part,

instead of "mvn clean compile jib:build"?): /codebuild/output/src3077/src/DemoService/demo-service/target/classes -> [Help 1]

the message is the underlying exception from here, so it definitely means there was an I/O error when dealing with this particular directory (/codebuild/output/src3077/src/DemoService/demo-service/target/classes).

BTW, you can make Maven output debug logs and get the full stack trace with mvn -X ..., although I think the exception message you will get would be the same.

@kumarineha304
Copy link
Author

Thank you for taking time to respond to the query, the problem with the issue is its not consistent things are working perfectly fine now so I won't be able to regenerate it somehow all of a sudden I start getting this error and it keeps on going for a while and it again gets resolved all on its own.

We are using 3.3.1 of the jib plugin can this be resolved using the higher version. Or we need to change something the way we are building our project.

Yes you said it right we don't have the application getting build as a war.

@chanseokoh
Copy link
Member

chanseokoh commented Feb 1, 2024

I don't think upgrading Jib will fix it. It's an error in your system where Jib is unable to read /codebuild/output/src3077/src/DemoService/demo-service/target/classes because a normal I/O operation fails. One common cause is that the user didn't run mvn compile, which would create the output directory. But I am not sure if that's the case here. Your filesystem might genuinely have IO issues.

Some possibilities I can think of:

  • /codebuild/output/src3077/src is a network file system and you sometimes have issues accessing them.
  • Someone Jib and the regular Maven compile plugin run in parallel, making Jib sometimes run before /codebuild/output/src3077/src/DemoService/demo-service/target/classes is created.
  • Some plugin or application (e.g., Anti-Virus) interferes with the directory somehow.
  • Something else.

As a desperate move, you could try mvn compile && sleep 5s && ls <project root>/demo-service/target/classes && sleep 5s && ls <project root>/demo-service/target/classes && mvn jib:build or something like that.

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

No branches or pull requests

4 participants