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

Upgrade Spring example enabling the musl support #143

Closed
jabrena opened this issue Oct 30, 2022 · 6 comments
Closed

Upgrade Spring example enabling the musl support #143

jabrena opened this issue Oct 30, 2022 · 6 comments

Comments

@jabrena
Copy link
Contributor

jabrena commented Oct 30, 2022

Hi,

I was reviewing the repo, it is amazing but some techniques like static compilation with musl was not applied to the spring example.

From my side, I upgraded the example to spring-boot 3 RC1 with success and it is possible to compile in static but I was not able to enable the option for musl.

Did you try it?

			<plugin>
				<groupId>org.graalvm.buildtools</groupId>
				<artifactId>native-maven-plugin</artifactId>
				<configuration>
					<buildArgs>
						<buildArg>--static</buildArg>
					</buildArgs>
				</configuration>
			</plugin>

Test in local:

  • benchmark-jibber: 78 mb
  • benchmark-jibber-static: 77 mb
  • benchmark-jibber-static-musl: Ko
  • benchmark-jibber-static-upx: 18 mb

If you like, I could send a PR with current changes.

Many thanks in advance.

Juan Antonio

@jabrena jabrena changed the title upgrade the spring native with musl support upgrade the spring native example with musl support Oct 30, 2022
@jabrena jabrena changed the title upgrade the spring native example with musl support Upgrade Spring example enabling the musl support Oct 31, 2022
@jabrena
Copy link
Contributor Author

jabrena commented Nov 3, 2022

I was able to compile a Spring Boot application with musl support.

I am refactoring the docker file for it, because it requires a special folder for tomcat to avoid the following error:

2022-11-02T16:38:04.280Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[app:3.0.0-RC1]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578) ~[app:6.0.0-RC2]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[app:3.0.0-RC1]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[app:3.0.0-RC1]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[app:3.0.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[app:3.0.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[app:3.0.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[app:3.0.0-RC1]
	at com.example.benchmarks.BenchmarkServerJibber.main(BenchmarkServerJibber.java:18) ~[app:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to create tempDir. java.io.tmpdir is set to /tmp
	at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:208) ~[app:3.0.0-RC1]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:194) ~[app:3.0.0-RC1]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183) ~[app:3.0.0-RC1]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[app:3.0.0-RC1]
	... 8 common frames omitted
Caused by: java.nio.file.NoSuchFileException: /tmp/tomcat.8080.1228880437960241164
	at java.base@19/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:397) ~[app:na]
	at java.base@19/java.nio.file.Files.createDirectory(Files.java:700) ~[na:na]
	at java.base@19/java.nio.file.TempFileHelper.create(TempFileHelper.java:134) ~[na:na]
	at java.base@19/java.nio.file.TempFileHelper.createTempDirectory(TempFileHelper.java:171) ~[na:na]
	at java.base@19/java.nio.file.Files.createTempDirectory(Files.java:1017) ~[na:na]
	at org.springframework.boot.web.server.AbstractConfigurableWebServerFactory.createTempDir(AbstractConfigurableWebServerFactory.java:202) ~[app:3.0.0-RC1]
	... 11 common frames omitted

The issue was fixed but I am reviewing some ways to have the Docker file more elegant.

The configuration at pom.xml is:

			<plugin>
				<groupId>org.graalvm.buildtools</groupId>
				<artifactId>native-maven-plugin</artifactId>
				<configuration>
					<buildArgs>
						<buildArg>--static</buildArg>
						<buildArg>--libc=musl</buildArg>
					</buildArgs>
				</configuration>
			</plugin>

Results:

docker images jibber-benchmark --format '{{.Size}}\t{{.Repository}}\t{{.Tag}}\t{{.ID}}' | sed 's/ //' | sort -h -r | column -t

279MB   jibber-benchmark  buildpacks-jvm.0.0.1-SNAPSHOT     483a47cdfe58
91.3MB  jibber-benchmark  buildpacks-native.0.0.1-SNAPSHOT  9e56de567bcf
38.7MB  jibber-benchmark  native.0.0.1-SNAPSHOT             dba7fc1dc157
18.4MB  jibber-benchmark  native-upx.0.0.1-SNAPSHOT         8801957da44e

@jabrena
Copy link
Contributor Author

jabrena commented Nov 3, 2022

Fixed Docker image

@jabrena
Copy link
Contributor Author

jabrena commented Nov 10, 2022

Hi @fniephaus, @olyagpl

I propose to decouple the example about Spring Boot for native compilation in 2 folders:

  • Current folder would be the manual solution that anybody could do
  • Another folder with the solution provided by Buildbacks

Why I am thinking to add an additional folder?

In order to not puzzle the developer.
The buildback solution doesn't need the following plugin:

			<plugin>
				<groupId>org.graalvm.buildtools</groupId>
				<artifactId>native-maven-plugin</artifactId>
				<configuration>
					<buildArgs>
						<buildArg>--static</buildArg>
						<buildArg>--libc=musl</buildArg>
					</buildArgs>
				</configuration>
			</plugin>

But if you compile a spring boot application manual, you need it.

In the other hand, I believe that musl support was not iterated so much with Buildpacks, you can follow the next link:
paketo-buildpacks/java-native-image#507 (comment)

But manually, it is possible.

If you like the idea, I will send a PR in coming days with both examples refactored and organised

Waiting for your feedback :)

Juan Antonio

@fniephaus
Copy link
Member

Hi @jabrena, thanks for the suggestions. Since this repo focuses on GraalVM demos, I think it's good that we show the direct solution (what you called "manual" solution). We, however, neither maintain nor provide support for these buildpacks, which is why I'd be inclined not to include demos for them in this repo. We can, of course, mention buildpacks and link to corresponding resources somewhere in the docs of the demo.

@jabrena
Copy link
Contributor Author

jabrena commented Nov 11, 2022

Oki, I agree with your approach.
I will prepare the PR for it.

@jabrena
Copy link
Contributor Author

jabrena commented Jan 13, 2023

with current sources, everything is fine.
I will close the issue.

@jabrena jabrena closed this as completed Jan 13, 2023
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

2 participants