Skip to content

Commit

Permalink
Update Spring Boot, Gradle, and Java
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasVitale committed Sep 1, 2024
1 parent 76a489f commit 6f70ee2
Show file tree
Hide file tree
Showing 97 changed files with 332 additions and 946 deletions.
153 changes: 137 additions & 16 deletions .github/workflows/commit-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
runs-on: ubuntu-24.04
permissions:
contents: read
security-events: write
steps:
- name: Checkout source code
uses: actions/checkout@v4
Expand All @@ -27,6 +26,7 @@ jobs:
cd 06-knative/basic/book-service
chmod +x gradlew
./gradlew build
package:
name: Package and Publish
if: ${{ github.ref == 'refs/heads/main' }}
Expand All @@ -35,27 +35,148 @@ jobs:
permissions:
contents: read
packages: write
security-events: write
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Pack
uses: buildpacks/github-actions/[email protected]
with:
java-version: 22
distribution: temurin
cache: gradle
- name: Build container image
run: |
cd 06-knative/basic/book-service
chmod +x gradlew
./gradlew bootBuildImage \
--imageName ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
- name: Authenticate with the container registry
pack-version: 0.34.2

- name: Login to container registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
registry: ${{ env.REGISTRY }}

- name: Build and publish OCI image
run: |
pack build ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} \
--builder docker.io/paketobuildpacks/builder-jammy-buildpackless-tiny \
--buildpack gcr.io/paketo-buildpacks/java \
--env BP_JVM_VERSION=22 \
--path 06-knative/basic/book-service \
--platform ${{ matrix.platform }} \
--report-output-dir ./report.toml \
--publish
- name: Export digest
run: |
mkdir -p /tmp/digests
digest=$(grep 'digest' report.toml | sed 's/.*= "\(.*\)"/\1/')
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.IMAGE_NAME }}-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
needs: [ package ]
runs-on: ubuntu-24.04
permissions:
attestations: write
contents: read
id-token: write
packages: write
outputs:
image-digest: ${{ steps.image-info.outputs.digest }}
image-name: ${{ steps.image-info.outputs.name }}
steps:

- name: Prepare
run: |
timestamp=$(date +%Y%m%d-%H%M%S)
echo "TIMESTAMP=${timestamp}" >> $GITHUB_ENV
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-${{ env.IMAGE_NAME }}-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install Cosign
uses: sigstore/[email protected]

- name: Generate Docker meta information
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.licenses=Apache-2.0
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.version=${{ github.sha }}
org.opencontainers.image.url=${{ github.server_url }}/${{ github.repository }}
tags: |
type=raw,value=${{ env.TIMESTAMP }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=long
- name: Login to container registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.IMAGE_PUSH_TOKEN }}
- name: Publish container image
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
registry: ${{ env.REGISTRY }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.meta.outputs.version }}
- name: Setup Arkade
uses: alexellis/setup-arkade@v2

- name: Install crane
uses: alexellis/arkade-get@master
with:
crane: v0.19.2

- name: Get OCI image digest
id: image-info
run: |
image_digest=$(crane digest ${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.meta.outputs.version }})
echo $image_digest
echo "IMAGE_DIGEST=${image_digest}" >> $GITHUB_ENV
- name: Sign image
run: |
cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE }}@${{ env.IMAGE_DIGEST }}
- name: Generate SLSA Build Attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE }}
subject-digest: ${{ env.IMAGE_DIGEST }}
push-to-registry: true
github-token: ${{ secrets.push-token }}
8 changes: 4 additions & 4 deletions 01-java/basic/book-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'com.thomasvitale'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion = JavaLanguageVersion.of(22)
}
}

Expand All @@ -22,7 +22,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework:spring-webflux'
}

tasks.named('test') {
Expand Down
Binary file modified 01-java/basic/book-service/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions 01-java/basic/book-service/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions 01-java/basic/book-service/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void main(String[] args) {
@Bean
RouterFunction<ServerResponse> routerFunction() {
return RouterFunctions.route()
.GET("/", request -> ServerResponse.ok().body("Welcome to the BookService!"))
.GET("/books", request -> ServerResponse.ok().body(List.of(
.GET("/", _ -> ServerResponse.ok().body("Welcome to the BookService!"))
.GET("/books", _ -> ServerResponse.ok().body(List.of(
new Book("The Hobbit"),
new Book("The Lord of the Rings"),
new Book("His Dark Materials")
Expand Down
8 changes: 4 additions & 4 deletions 01-java/live-reload/book-service/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
}

group = 'com.thomasvitale'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
languageVersion = JavaLanguageVersion.of(22)
}
}

Expand All @@ -24,7 +24,7 @@ dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
testImplementation 'org.springframework:spring-webflux'
}

tasks.named('test') {
Expand Down
Binary file modified 01-java/live-reload/book-service/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions 01-java/live-reload/book-service/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions 01-java/live-reload/book-service/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.thomasvitale.bookservice;

import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;

import java.util.List;

@SpringBootApplication
public class BookServiceApplication {

Expand All @@ -19,8 +19,8 @@ public static void main(String[] args) {
@Bean
RouterFunction<ServerResponse> routerFunction() {
return RouterFunctions.route()
.GET("/", request -> ServerResponse.ok().body("Welcome to the BookService!"))
.GET("/books", request -> ServerResponse.ok().body(List.of(
.GET("/", _ -> ServerResponse.ok().body("Welcome to the BookService!"))
.GET("/books", _ -> ServerResponse.ok().body(List.of(
new Book("The Hobbit"),
new Book("The Lord of the Rings"),
new Book("His Dark Materials")
Expand Down
Loading

0 comments on commit 6f70ee2

Please sign in to comment.