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

docs: Port Spring guide to use functions #7021

Merged
merged 13 commits into from
May 25, 2024

Conversation

vikram-dagger
Copy link
Contributor

@vikram-dagger vikram-dagger commented Apr 4, 2024

@vikram-dagger
Copy link
Contributor Author

vikram-dagger commented Apr 5, 2024

I see the following error but I'm not able to find the cause: Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure. The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

The MySQL properties are at https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/application-mysql.properties

@vito @helderco can I request your help to debug this?

@d3rp3tt3
Copy link
Contributor

```shell
dagger install github.com/levlaz/daggerverse/mariadb@v0.2.1
dagger install github.com/jcsirot/daggerverse/java@250eb3e0f49da321cca2241fe1e1d017b4143a91
dagger install github.com/shykes/daggerverse/docker@3338120927f8e291c4780de691ef63a7c9d825c0
Copy link
Contributor

@vito vito Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need Docker for? That seems really out of left field, I'd only expect to run Docker in Dagger in fringe situations (legacy compatibility, booth demos, etc).

Removed it locally, doesn't seem to affect anything 🤔

edit: oh, now that I fixed the DB thing below, it does indeed want Docker, nevermind! 🙏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikram-dagger so I got it past the broken DB setup, but now it's failing in a few places because the docker CLI isn't installed. Pausing there for now. Left inline comments covering my tracks.

To be honest if this example requires Docker it feels pretty distracting from the core focus of the doc (see my initial reaction). I wonder if we should just find a simpler example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vito thanks for your help on this, you made much more progress than I did! I'm fine with using a different Spring or other Java example. Do you have a suggestion, or should I try to find something online?

WithJdk("17").
WithMaven("3.9.5").
WithProject(source.WithoutDirectory("dagger")).
Maven([]string{"-X", "-Dspring.profiles.active=mysql", "clean", "package"})
Copy link
Contributor

@vito vito Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue seems to be that you need the database bound and configured (i.e. the build := part below) before running this command. I'm not seeing a way to do that with the Java module though (cc @jcsirot). Maybe skip the module for now?

edit: actually it looks like we can just pluck .Container() off and work from there, Maven( is just shorthand for WithExec(mvn ...) - working on that now!

// TODO: this doesn't work because the docker CLI isn't installed. And
// installing it just gives us a broken podman CLI. Whee.
//
// Can we just disable the tests that use Docker?
Copy link
Contributor Author

@vikram-dagger vikram-dagger Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea. I checked the app README, it says At development time we recommend you use the test applications set up as main() methods in PetClinicIntegrationTests (using the default H2 database and also adding Spring Boot Devtools), MySqlTestApplication and PostgresIntegrationTests. These are set up so that you can run the apps in your IDE to get fast feedback and also run the same classes as integration tests against the respective database. The MySql integration tests use Testcontainers to start the database in a Docker container, and the Postgres tests use Docker Compose to do the same thing.

It sounds like the app's test suite is already starting MySQL in a container, exactly the same as I was trying to do in the example pipeline. Not quite sure how that helps us move it forward though.

https://github.com/spring-projects/spring-petclinic?tab=readme-ov-file#test-applications

Copy link

@cchanley2003 cchanley2003 Apr 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an example working using test containers. You shouldn't start a Maria db as a service but instead start docker as a service. You shouldn't need a docker client for test containers the Java code interacts with docker. I did have to disable ryuk. TESTCONTAINERS_RYUK_DISABLED=true

See https://discord.com/channels/707636530424053791/1179822601099554856/1209537679780487249

@vikram-dagger vikram-dagger marked this pull request as ready for review April 30, 2024 16:03
@vikram-dagger
Copy link
Contributor Author

vikram-dagger commented Apr 30, 2024

MyModule.publish(
    imageName: "my-java-app"
    registryAddress: "docker.io"
    registryPassword: ✔ setSecret(name: "a82aef58d43bc3ce560a85e82952d14e88976477b69669adef04f99fb3d556e0"): Secret! 0.0s
    registryUsername: "XX"
    source: ✔ blob(digest: "sha256:fcb84...", mediaType: "application/vnd.oci.image.layer.v1.tar+zstd", size: 39716398, uncompressed: "sha256:59e7981b7b6a7869df5b9da68f07dbe034b2..."): Directory! 0.0s
    version: "0.1"
  ): String! 7m47.5s
! call function "publish": process "/runtime" did not complete successfully: exit code: 1
┃ ╭─ Error ──────────────────────────────────────────────────────────────────────╮                 
┃ │ Function execution error: unhandled errors in a TaskGroup (1 sub-exception)  │                 
┃ ╰──────────────────────────────────────────────────────────────────────────────╯                 
  ✘ Container.file(path: "target/spring-petclinic-3.2.0-SNAPSHOT.jar"): File! 7m35.3s
  ! process "mvn package" did not complete successfully: exit code: 1
    ✘ exec mvn package 5m58.3s
    ! process "mvn package" did not complete successfully: exit code: 1
    ┃ [ERROR]                                                                                      
    ┃ [ERROR] For more information about the errors and possible solutions, please read the followi
    ┃  articles:                                                                                   
    ┃ [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException       

Error: response from query: input: myModule.publish resolve: call function "publish": process "/runtime" did not complete successfully: exit code: 1

Stderr:
╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ Function execution error: unhandled errors in a TaskGroup (1 sub-exception)  │
╰──────────────────────────────────────────────────────────────────────────────╯

@helderco @marcosnils can you please help me debug the above? The same code works in Go and TypeScript.

@marcosnils
Copy link
Contributor

@helderco @marcosnils can you please help me debug the above? The same code works in Go and TypeScript.

@vikram-dagger is this only happening in the python pipeline?

@vikram-dagger
Copy link
Contributor Author

@vikram-dagger is this only happening in the python pipeline?

@marcosnils Yes

@helderco
Copy link
Contributor

helderco commented May 3, 2024

@vikram-dagger vikram-dagger changed the title docs: Ports Spring guide to use functions docs: Port Spring guide to use functions May 8, 2024
Copy link
Member

@gerhard gerhard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased and force pushed @vikram-dagger

If checks pass, good to merge from my side ⛴️

Copy link
Contributor

@kpenfound kpenfound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused

vikram-dagger and others added 12 commits May 24, 2024 23:01
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Docker still failing - can it be disabled instead? Seems distracting

Signed-off-by: Alex Suraci <alex@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
Co-authored-by: Kyle Penfound <kyle@dagger.io>
Signed-off-by: Solomon Hykes <shykes@users.noreply.github.com>
@shykes
Copy link
Contributor

shykes commented May 24, 2024

FYI don't merge, there's a broken snippet (python)

@jpadams
Copy link
Contributor

jpadams commented May 24, 2024

Python snippet working for me now from a new module I made with dagger init --sdk python where I replaced the main with this snippet. I couldn't repro the error message above from 0.11.4 engine and CLI.

I'm on a Mac M1 arm machine, so I needed to force use of linux/amd64 variant of the eclipse-temurinimage from Docker Hub.
image

image

my fix:
image

Running locally, I think I kept running out of resources, so I cranked up all the limits in Docker Desktop for memory, swap, virtual memory, volumes, etc, and it worked after that.

[Too many errors, abort]
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Once I fixed platform and increased Docker Desktop resources, I had no issue publishing to ttl.sh. Though, since I was forced to use args for registry auth, I needed a dummy empty value for my registry-password secret, so I just did touch empty.

dagger call  publish \
--source https://github.com/spring-projects/spring-petclinic
--image-name fooooooo
--registry-address ttl.sh
--registry-password=file:./empty
--registry-username="jeremy"
--version=$RANDOM

Then it ran like this:

docker run -it --rm \
-p 8080:8080 \
ttl.sh/jeremy/fooooooo@sha256:921230645b8d665b455e69e16bcc2c69e63def8678f5887b39c3502018c93fbf

so I could see the pretty colors of the logs
image

and the app in my browser
image

So...I'll update the other snippets to specify the platform as well.

Todo:
consider returning a container instead and do the registry auth and publish in the CLI.
then we could also do dagger call ... service up

Signed-off-by: Jeremy Adams <jeremy@dagger.io>
@jpadams
Copy link
Contributor

jpadams commented May 25, 2024

Tested all snippet versions by making them the main of new go, python, typescript modules and running them. 👍

@jpadams jpadams merged commit e1b380e into dagger:main May 25, 2024
59 checks passed
@gerhard gerhard deleted the docs-191-spring branch June 11, 2024 14:48
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

Successfully merging this pull request may close these issues.

10 participants