From a28782b7d8fbe10ceb9eb88a70aafd3c8cf97f06 Mon Sep 17 00:00:00 2001 From: Thomas Vitale Date: Sun, 5 May 2024 17:12:45 +0200 Subject: [PATCH] Update docs on live reload Signed-off-by: Thomas Vitale --- 01-java/README.md | 4 ++++ 02-container-image/README.md | 2 +- 04-tilt/README.md | 20 +++++++++++++++++++ 05-skaffold/README.md | 38 ++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/01-java/README.md b/01-java/README.md index 3acf789..5f9b157 100644 --- a/01-java/README.md +++ b/01-java/README.md @@ -40,3 +40,7 @@ Run the application on the local JVM as follows. Now, try making some changes to the application (for example, updating the REST API) and save. Spring Boot Developer Tools will automatically reload the application with the new classes. + +If you use Visual Studio Code, the live reload functionality works without any additional configuration. + +If you use IntelliJ IDEA, refer to the [official documentation](https://www.jetbrains.com/help/idea/spring-boot.html#application-update-policies) to enable support for Spring Boot DevTools in the IDE. diff --git a/02-container-image/README.md b/02-container-image/README.md index 8566654..a441796 100644 --- a/02-container-image/README.md +++ b/02-container-image/README.md @@ -68,6 +68,6 @@ You can also debug the application from your IDE. Check out the configuration in ## Live Reload Paketo, the Cloud Native Buildpacks implementation we used above, provides support for live-reload. -You can enable it via the `BP_LIVE_RELOAD_ENABLED` environment variable, as demonstrated in `live-reload/book-service/build.gradle`. +You can enable it via the `BP_LIVE_RELOAD_ENABLED` environment variable, as demonstrated in `live-reload/book-service/build.gradle`. For more information, refer to the [official documentation](https://paketo.io/docs/howto/java/#enable-process-reloading). Then, you would need a tool like Spring Boot Developer Tools to take care of loading into the images the changed classes every time they are updated. We'll use the live reload capabilities provided by Buildpacks when working with Tilt. diff --git a/04-tilt/README.md b/04-tilt/README.md index 6f3ee04..cedb1f1 100644 --- a/04-tilt/README.md +++ b/04-tilt/README.md @@ -25,6 +25,26 @@ tilt up Now you can work with the application, save your changes, and they will be automatically loaded into the container running in Kubernetes. You can also debug it by attaching a remote debugger from your IDE to the Pod. +The Tilt setup in the `Tiltfile` is tuned to work with Visual Studio Code without any additional configuration. + +If you use IntelliJ IDEA, refer to the [official documentation](https://www.jetbrains.com/help/idea/spring-boot.html#application-update-policies) to enable live reload in the IDE. You also need to update the `Tiltfile` and change the folders monitored by Tilt for the live reload functionality. For more information on how it works, refer to the Paketo [official documentation](https://paketo.io/docs/howto/java/#enable-process-reloading). + +```python +custom_build( + # Name of the container image + ref = 'book-service', + # Command to build the container image + command = './gradlew bootBuildImage --imageName $EXPECTED_REF', + # Files to watch that trigger a new build + deps = [ 'build.gradle', './build/classes/java/main', './build/resources/main' ], + # Enables live reload + live_update = [ + sync('./build/classes/java/main', '/workspace/BOOT-INF/classes'), + sync('./build/resources/main', '/workspace/BOOT-INF/classes') + ] +) +``` + ## Clean-up When you're done, delete the cluster as follows. diff --git a/05-skaffold/README.md b/05-skaffold/README.md index 8e60b5f..59bfe83 100644 --- a/05-skaffold/README.md +++ b/05-skaffold/README.md @@ -28,6 +28,44 @@ skaffold dev --port-forward Now you can work with the application, save your changes, and they will be automatically loaded into the container running in Kubernetes. You can also debug it by attaching a remote debugger from your IDE to the Pod by starting Skaffold with `skaffold debug`. +The Skaffold setup in the `skaffold.yml` file is tuned to work with Visual Studio Code without any additional configuration. + +If you use IntelliJ IDEA, refer to the [official documentation](https://www.jetbrains.com/help/idea/spring-boot.html#application-update-policies) to enable live reload in the IDE. You also need to update the `skaffold.yml` file and change the folders monitored by Skaffold for the live reload functionality. For more information on how it works, refer to the Paketo [official documentation](https://paketo.io/docs/howto/java/#enable-process-reloading). + +```yaml +apiVersion: skaffold/v4beta10 +kind: Config +metadata: + name: book-service +build: + artifacts: + - image: book-service + buildpacks: + # Change to docker.io/paketobuildpacks/builder-jammy-base on ARM64 + builder: docker.io/dashaun/builder:base + trustBuilder: true + env: + - BP_JVM_VERSION=21 + - BP_LIVE_RELOAD_ENABLED=true + dependencies: + paths: + - build.gradle + - src/main/resources + - build/classes/java/main + - build/resources/main + sync: + manual: + - src: "src/main/resources/**/*" + dest: /workspace/BOOT-INF/classes + strip: src/main/resources/ + - src: "build/classes/java/main/**/*" + dest: /workspace/BOOT-INF/classes + strip: build/classes/java/main/ + - src: "build/resources/main/**/*" + dest: /workspace/BOOT-INF/classes + strip: build/resources/main/ +``` + ## Clean-up When you're done, delete the cluster as follows.