-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
18 changed files
with
728 additions
and
0 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,45 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: Build Demo App | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'demo-app/**' | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- 'demo-app/**' | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./demo-app | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'zulu' | ||
- name: Build | ||
run: mvn --batch-mode --update-snapshots package | ||
|
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,61 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: Spring Rest JPA Release | ||
on: | ||
push: | ||
tags: | ||
- "demo-app/v*" | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./demo-app | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'zulu' | ||
- name: Build | ||
run: mvn --batch-mode --update-snapshots package | ||
- name: Docker login | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Version from tag | ||
id: version-from-tag | ||
run: echo version=${GITHUB_REF_NAME//demo-app\/} >> $GITHUB_OUTPUT | ||
- name: Docker Extract metadata | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/google/spring-demo-app | ||
tags: | | ||
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=${{ steps.version-from-tag.outputs.version }} | ||
- name: Docker build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: ./demo-app | ||
file: ./demo-app/Dockerfile | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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,19 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM azul/zulu-openjdk-alpine:17-latest | ||
VOLUME /tmp | ||
ARG JAR_FILE=target/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar /app.jar ${0} ${@}"] |
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 @@ | ||
# spring-demo-app | ||
|
||
The folder contains source code of a simple Java application that uses Spring Boot framework | ||
and exposes the REST endpoint. The data is fetched from the relational database with | ||
Java Persistence API. | ||
|
||
## Usage | ||
|
||
The service exposes below endpoints: | ||
|
||
* `/books` returns collection of books | ||
|
||
In the addition to above, Spring Boot actuator endpoints are exposed per configuration. | ||
|
||
### Source code | ||
|
||
Prerequisites: | ||
|
||
* [JDK](https://openjdk.org/projects/jdk/17/) 17 or newer | ||
* [Maven](https://maven.apache.org/download.cgi) | ||
|
||
Build application from the source code. | ||
|
||
```sh | ||
mvn package | ||
java -jar target/spring-demo-app-0.0.1-SNAPSHOT.jar | ||
``` | ||
|
||
### Container image | ||
|
||
1. Adjust `application.yaml` according to your needs | ||
2. Run the container | ||
|
||
```sh | ||
docker run -d --name spring-demo-app \ | ||
-p 8080:8080 \ | ||
-v "`pwd`/application.yaml:/application.yaml" \ | ||
ghcr.io/google/spring-demo-app:latest | ||
``` | ||
|
||
### Kubernetes | ||
|
||
1. Adjust `application.yaml` according to your needs | ||
2. Adjust `kustomization.yaml` according to your needs | ||
3. Customize and apply Kubernetes manifests | ||
|
||
```sh | ||
kubectl kustomize | kubectl apply -f | ||
``` |
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,32 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
spring: | ||
datasource: | ||
url: jdbc:h2:mem:mydb | ||
username: sa | ||
password: password | ||
driverClassName: org.h2.Driver | ||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
database-platform: org.hibernate.dialect.H2Dialect | ||
defer-datasource-initialization: true | ||
management: | ||
endpoints: | ||
web: | ||
exposure: | ||
include: | ||
- health | ||
- prometheus |
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,26 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: monitoring.googleapis.com/v1 | ||
kind: PodMonitoring | ||
metadata: | ||
name: spring-demo-app | ||
spec: | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: spring-demo-app | ||
endpoints: | ||
- port: http | ||
path: /actuator/prometheus | ||
interval: 5s |
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,82 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: spring-demo-app | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: spring-demo-app | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app.kubernetes.io/name: spring-demo-app | ||
template: | ||
metadata: | ||
labels: | ||
app.kubernetes.io/name: spring-demo-app | ||
spec: | ||
serviceAccountName: spring-demo-app | ||
containers: | ||
- name: spring-demo-app | ||
image: ghcr.io/google/spring-demo-app:latest | ||
args: | ||
- --spring.config.location=file:/config/application.yaml | ||
env: | ||
- name: JAVA_OPTS | ||
value: -XX:MaxRAMPercentage=75 | ||
volumeMounts: | ||
- name: spring-demo-app-config | ||
mountPath: /config | ||
ports: | ||
- name: http | ||
containerPort: 8080 | ||
startupProbe: | ||
periodSeconds: 2 | ||
failureThreshold: 60 | ||
httpGet: | ||
path: /actuator/health | ||
port: http | ||
scheme: HTTP | ||
livenessProbe: | ||
httpGet: | ||
path: /actuator/health | ||
port: http | ||
scheme: HTTP | ||
resources: | ||
limits: | ||
cpu: "1" | ||
memory: 512Mi | ||
requests: | ||
cpu: 500m | ||
memory: 512Mi | ||
volumes: | ||
- name: spring-demo-app-config | ||
configMap: | ||
name: spring-demo-app-config | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: spring-demo-app | ||
spec: | ||
selector: | ||
app.kubernetes.io/name: spring-demo-app | ||
ports: | ||
- port: 8080 | ||
targetPort: http |
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,28 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- examples/spring-demo-app.yaml | ||
# Uncomment for Google Managed Prometheus metrics scraping | ||
#- examples/spring-app-demo-gmp.yaml | ||
|
||
namespace: demo | ||
|
||
configMapGenerator: | ||
- name: spring-demo-app-config | ||
files: | ||
- application.yaml |
Oops, something went wrong.