-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5b8227
commit 6d4cc8e
Showing
24 changed files
with
384 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Create Maven Cache | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
create-maven-cache: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
|
||
- name: Install imgpkg | ||
shell: bash | ||
run: | | ||
wget -nv -O- https://github.com/carvel-dev/imgpkg/releases/download/v0.42.2/imgpkg-linux-amd64 > /tmp/imgpkg | ||
chmod 755 /tmp/imgpkg | ||
- name: Download Spring Boot application | ||
shell: bash | ||
run: | | ||
mkdir -p demo | ||
curl --silent --fail https://start.spring.io/starter.tgz -d dependencies=webflux,actuator -d javaVersion=17 | tar -C demo -xzvf - | ||
- name: Generate dependencies | ||
shell: bash | ||
run: | | ||
(cd demo && ./mvnw dependency:go-offline) | ||
- name: Build and publish | ||
shell: bash | ||
run: | | ||
/tmp/imgpkg push -i ghcr.io/${{github.repository}}-maven:latest -f $HOME/.m2 --registry-username=${{github.actor}} --registry-password=${{secrets.GITHUB_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
.cache | ||
.config | ||
.docker | ||
.bash_history | ||
.gitconfig | ||
.kube | ||
.lesshst | ||
.local | ||
.ssh | ||
.theia | ||
.webdav | ||
.yarn | ||
*.swp | ||
.vscode |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.dockerignore | ||
.git | ||
.github | ||
.gitignore | ||
Dockerfile | ||
Makefile | ||
LICENSE | ||
README.md | ||
resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This Dockerfile is used where you need to create a custom workshop base | ||
# image which incorporates additional application binaries or tools. Select | ||
# the appropriate Educates workshop base image in the `FROM` line. | ||
|
||
FROM ghcr.io/vmware-tanzu-labs/educates-jdk17-environment:2.0 | ||
|
||
# Include here any steps to build your custom workshop base image. See the | ||
# documentation on best practices for building a custom workshop base image. | ||
|
||
# ... | ||
|
||
# Uncomment the following if you wish to also copy workshop content files | ||
# into the custom workshop base image, rather than workshop content files | ||
# being published using a separate OCI image artefact or other mechanism. | ||
|
||
COPY --chown=1001:0 . /home/eduk8s/ | ||
RUN mv /home/eduk8s/workshop /opt/workshop | ||
RUN fix-permissions /home/eduk8s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Spring Boot on Kubernetes | ||
========================= | ||
|
||
Introduction to Spring Boot on Kubernetes. |
Empty file.
15 changes: 15 additions & 0 deletions
15
workshops/lab-spring-boot-on-k8s/resources/trainingportal.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: training.educates.dev/v1beta1 | ||
kind: TrainingPortal | ||
metadata: | ||
name: lab-spring-boot-on-k8s | ||
spec: | ||
portal: | ||
registration: | ||
type: anonymous | ||
updates: | ||
workshop: true | ||
workshops: | ||
- name: lab-spring-boot-on-k8s | ||
capacity: 1 | ||
expires: 60m | ||
orphaned: 5m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...lab-spring-boot-on-k8s/workshop/content/exercises/01-creating-an-application.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
The first thing we need to do is create a Spring Boot application. To do this we are going to to use the Spring Initializr web site. | ||
|
||
![](spring-initializr-web-site.png) | ||
|
||
The purpose of the Spring Initializr web site is to allow you to enter in details about the Spring Boot application you want to create. This includes the name of the application, the tooling you want to use, and any dependencies. When you click on generate it will automatically start a download of application source code for a Spring Boot application satisfying those requirements. You can then unpack that on your local computer and start working. | ||
|
||
Normally to do this you would go to [start.spring.io](https://start.spring.io/), however for this workshop we have integrated the web site into a tab of the workshop session dashboard. This is done so that rather than downloading the Spring Boot application you create with it to your own local machine, it will download it into the workshop environment. | ||
|
||
Select the **Initializr** tab in the workshop session dashboard. | ||
|
||
```dashboard:open-dashboard | ||
name: Initializr | ||
``` | ||
|
||
For this workshop environment you must ensure Java 17 is selected under the project metadata on Spring Initializr. | ||
|
||
Because of later commands we will run, we also want to generate a Maven project rather Gradle, so click on **Maven** under the **Project** category to select it. | ||
|
||
You can leave as is the other defaults for the project metadata as the workshop is scripted to already expect the project name to be `demo`. | ||
|
||
Now click on **Add Dependencies**, search for `Spring Reactive Web`{{copy}} and add it. | ||
|
||
Click again on **Add Dependencies** and this time search for `Spring Boot Actuator`{{copy}} and add it. | ||
|
||
We are ready to generate the Spring Boot application code. Remember you need to be using the Spring Initializr integrated into the workshop session dashboard. | ||
|
||
Click on **Create**. | ||
|
||
This should send you back to the terminal and you can see where the Spring Boot application was downloaded and extracted into the workshop environment. | ||
|
||
You can see the result by running: | ||
|
||
```terminal:execute | ||
command: tree demo | ||
``` | ||
|
||
To verify that the application code has been generated successfully, open up the main Java source code file for the application. | ||
|
||
```editor:open-file | ||
file: ~/exercises/demo/src/main/java/com/example/demo/DemoApplication.java | ||
``` |
62 changes: 62 additions & 0 deletions
62
...ab-spring-boot-on-k8s/workshop/content/exercises/02-building-the-application.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
We are now ready to build the application source code. We will first do this direct into the local directory. | ||
|
||
Change to the ``demo`` sub directory. | ||
|
||
```terminal:execute | ||
command: cd ~/exercises/demo | ||
``` | ||
|
||
Then run Maven to start the build. | ||
|
||
```terminal:execute | ||
command: ./mvnw install | ||
``` | ||
|
||
> NOTE: It can take a couple of minutes the first time, but once the dependencies are all cached, subsequent builds would be faster. | ||
When the build has completed, build artefacts including the application JAR file, can be found in the `target` sub directory. | ||
|
||
```terminal:execute | ||
command: tree target | ||
``` | ||
|
||
To test that the application works, run Java with the application JAR file: | ||
|
||
```terminal:execute | ||
command: java -jar target/*.jar | ||
``` | ||
|
||
Because we added the `actuator` module as a dependency, a number of HTTP endpoints already exist. | ||
|
||
To test the application and see what endpoints were added, run: | ||
|
||
```terminal:execute | ||
command: curl -s localhost:8080/actuator | jq . | ||
session: 2 | ||
``` | ||
|
||
The output should be similar to the following: | ||
|
||
``` | ||
{ | ||
"_links": { | ||
"self": { | ||
"href": "http://localhost:8080/actuator", | ||
"templated": false | ||
}, | ||
"health-path": { | ||
"href": "http://localhost:8080/actuator/health/{*path}", | ||
"templated": true | ||
}, | ||
"health": { | ||
"href": "http://localhost:8080/actuator/health", | ||
"templated": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
We no longer need the local instance of the application, so you can kill it: | ||
|
||
```terminal:interrupt | ||
``` |
49 changes: 49 additions & 0 deletions
49
...ab-spring-boot-on-k8s/workshop/content/exercises/03-containerize-application.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
In order to be able to deploy the application to Kubernetes, we need to create a container image which bundles up the application. | ||
|
||
To create the container image, we are going to use the Maven `spring-boot:build-image` command. This will build us a container image without needing to worry about a `Dockerfile`. | ||
|
||
```terminal:execute | ||
command: ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName={{ registry_host }}/springguides/demo | ||
``` | ||
|
||
To test that the container image works run: | ||
|
||
```terminal:execute | ||
command: docker run -p 8080:8080 {{ registry_host }}/springguides/demo | ||
``` | ||
|
||
You should see the startup messages for the Spring Boot application. | ||
|
||
``` | ||
. ____ _ __ _ _ | ||
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ | ||
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ | ||
\\/ ___)| |_)| | | | | || (_| | ) ) ) ) | ||
' |____| .__|_| |_|_| |_\__, | / / / / | ||
=========|_|==============|___/=/_/_/_/ | ||
:: Spring Boot :: (v2.7.1) | ||
2022-06-29 06:35:55.608 INFO 1 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.3.1 on 91d914f953e9 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace) | ||
2022-06-29 06:35:55.610 INFO 1 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default" | ||
2022-06-29 06:35:56.543 INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator' | ||
2022-06-29 06:35:56.849 INFO 1 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8080 | ||
2022-06-29 06:35:56.862 INFO 1 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.506 seconds (JVM running for 1.754) | ||
``` | ||
|
||
To test the application, run: | ||
|
||
```terminal:execute | ||
command: curl localhost:8080/actuator/health | ||
session: 2 | ||
``` | ||
|
||
The output should be: | ||
|
||
``` | ||
{"status":"UP"} | ||
``` | ||
|
||
Kill the application once more. | ||
|
||
```terminal:interrupt | ||
``` |
Oops, something went wrong.