#Hello, I've been looking into using
1 messages ยท Page 1 of 1 (latest)
Welcome @vivid rain ! Taking a quick look, it should be easy to run JIB builds in a container in Dagger.
Which style does your team use?
https://github.com/GoogleContainerTools/jib?tab=readme-ov-file#quickstart
- Maven
- Gradle
- Jib Core
- Jib CLI
Guessing Maven like
https://github.com/GoogleContainerTools/jib/tree/master/examples/helloworld
mvn compile jib:build
Do y'all execute your JIB builds on Google Cloud Run or locally or both?
That's great to hear! Yes currently it's using that style, mvn compile jib:build
I believe the JIB builds are just done local now. We have a fully self-managed k8 cluster so ideally we would port the execution to that.
got it. Do you push images direct to a registry or create tarballs that you then work with?
Direct to registry
Got it. Is there a project that we can look at? Or is one of the examples in the repo above a good proxy?
The hello-world above is a fine example.
Great. Let's give it a try and see if there are any gotchas.
It might also make sense to move some of the builds to native Dagger, but excited to see how this goes ๐
Thank you!
Given that the Java SDK is still experimental, which SDK would be best?
Go, Python, TypeScript?
Go
here's my process:
mkdir jib-test; cd jib-test
dagger init --sdk go
replace main.go with
// A test of JIB build
package main
import (
"dagger/jib-test/internal/dagger"
)
type JibTest struct{}
// Publishes image to ttl.sh and returns Dagger Container - all built with Jib
func (m *JibTest) JibBuild(source *dagger.Directory) *dagger.Container {
var opts = dagger.ContainerOpts{Platform: dagger.Platform("linux/amd64")}
build := dag.Container(opts).
From("maven:3-jdk-11").
WithMountedDirectory("/mnt", source).
WithWorkdir("/mnt").
// build and push to ttl.sh/jpadams/image-built-with-jib
WithExec([]string{"mvn", "compile", "jib:build"}).
// build and write tarball to /mnt/target/image-built-with-jib.tar
WithExec([]string{"mvn", "compile", "jib:buildTar"})
return dag.Container(opts).
// turns the tarball into a proper Dagger Container
Import(build.File("/mnt/target/image-built-with-jib.tar"))
}
Call it using my repo with a modified pom.xml
dagger call jib-build --source https://github.com/jpadams/jib\#master:examples/helloworld
https://github.com/jpadams/jib/blob/master/examples/helloworld/pom.xml#L41-L65
Then have some fun:
dagger call jib-build --source https://github.com/jpadams/jib\#master:examples/helloworld with-exec --args "" --use-entrypoint stdout
(issue proposing a way to sweeten this ๐ up https://github.com/dagger/dagger/issues/8335)
docker run --platform linux/amd64 ttl.sh/jpadams/image-built-with-jib
dagger call jib-build --source https://github.com/jpadams/jib\#master:examples/helloworld terminal --cmd bash
now you're in a terminal inside the built container!
try running the entrypoint yourself ๐
java -cp /app/resources:/app/classes:/app/libs/* example.HelloWorld
After playing with Jib a bit, I'd probably convert the Jib builds to pure Dagger, but also we can happily coexist with them.
Could be generalized into a nice module for all sorts of Jib build and publish stuff ๐
Thank you very much Jeremy!! I will try to play with this soon ๐