Skip to content

Commit

Permalink
Updated versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoralespou committed Jul 12, 2024
1 parent a5b8227 commit 6d4cc8e
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 73 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/create-maven-cache.yaml
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}}
4 changes: 1 addition & 3 deletions .github/workflows/publish-workshop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ jobs:
publish-workshop:
runs-on: ubuntu-latest

if: ${{github.repository != 'vmware-tanzu-labs/educates-workshop-templates'}}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Create release
uses: vmware-tanzu-labs/educates-github-actions/publish-workshop@v4
uses: vmware-tanzu-labs/educates-github-actions/publish-workshop@v6
with:
token: ${{secrets.GITHUB_TOKEN}}
13 changes: 12 additions & 1 deletion .gitignore
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
43 changes: 0 additions & 43 deletions Makefile

This file was deleted.

9 changes: 0 additions & 9 deletions vendir.lock.yml

This file was deleted.

12 changes: 0 additions & 12 deletions vendir.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
image: jdk17-environment:*
files:
- image:
url: $(image_repository)/labs-spring-workshops-files:latest
url: $(image_repository)/labs-spring-workshops-files:$(workshop_version)
includePaths:
- /workshops/lab-containerizing-spring/workshop/**
newRootPath: workshops/lab-containerizing-spring
Expand Down
4 changes: 2 additions & 2 deletions workshops/lab-creating-a-spring-app/resources/workshop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ spec:
image: jdk17-environment:*
files:
- image:
url: $(image_repository)/labs-spring-workshops-files:latest
url: $(image_repository)/labs-spring-workshops-files:$(workshop_version)
includePaths:
- /workshops/lab-creating-a-spring-app/workshop/**
newRootPath: workshops/lab-creating-a-spring-app
- path: .m2
image:
url: ghcr.io/vmware-tanzu-labs/lab-spring-boot-on-k8s-maven:latest
url: ghcr.io/educates/lab-spring-boot-on-k8s-maven:latest
session:
resources:
memory: 1Gi
Expand Down
9 changes: 9 additions & 0 deletions workshops/lab-spring-boot-on-k8s/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.dockerignore
.git
.github
.gitignore
Dockerfile
Makefile
LICENSE
README.md
resources
18 changes: 18 additions & 0 deletions workshops/lab-spring-boot-on-k8s/Dockerfile
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
4 changes: 4 additions & 0 deletions workshops/lab-spring-boot-on-k8s/README.md
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 workshops/lab-spring-boot-on-k8s/resources/trainingportal.yaml
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
4 changes: 2 additions & 2 deletions workshops/lab-spring-boot-on-k8s/resources/workshop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ spec:
image: jdk17-environment:*
files:
- image:
url: ghcr.io/vmware-tanzu-labs/lab-spring-boot-on-k8s-files:4.0
url: $(image_repository)/lab-spring-boot-on-k8s-files:$(workshop_version)
includePaths:
- /workshop/**
- /exercises/**
- /README.md
- path: .m2
image:
url: ghcr.io/vmware-tanzu-labs/lab-spring-boot-on-k8s-maven:latest
url: ghcr.io/educates/lab-spring-boot-on-k8s-maven:latest
session:
namespaces:
budget: large
Expand Down
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
```
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
```
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
```
Loading

0 comments on commit 6d4cc8e

Please sign in to comment.