Skip to content

Commit

Permalink
Create springboot sample 2.0.0 version (#37)
Browse files Browse the repository at this point in the history
* Create new sample version

Signed-off-by: thepetk <[email protected]>

* Update devfile version

* Update port to 8080

Signed-off-by: thepetk <[email protected]>

---------

Signed-off-by: thepetk <[email protected]>
  • Loading branch information
thepetk authored Nov 28, 2023
1 parent 2f8d1e8 commit beac7d1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 51 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Creating an application with a Spring Boot code sample

**Note:** The Spring Boot code sample uses the **8081** HTTP port.
**Note:** The Spring Boot code sample version `v2.0.0` uses the **8080** HTTP port.

Before you begin creating an application with this `devfile` code sample, it's helpful to understand the relationship between the `devfile` and `Dockerfile` and how they contribute to your build. You can find these files at the following URLs:

* [Spring Boot `devfile.yaml`](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/devfile.yaml)
* [Spring Boot `Dockerfile`](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/docker/Dockerfile)
- [Spring Boot `devfile.yaml`](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/devfile.yaml)
- [Spring Boot `Dockerfile`](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/docker/Dockerfile)

1. The `devfile.yaml` file has an [`image-build` component](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/devfile.yaml#L21-L27) that points to your `Dockerfile`.
2. The [`docker/Dockerfile`](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/docker/Dockerfile) contains the instructions you need to build the code sample as a container image.
3. The `devfile.yaml` [`kubernetes-deploy` component](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/devfile.yaml#L28-L41) points to a `deploy.yaml` file that contains instructions for deploying the built container image.
4. The `devfile.yaml` [`deploy` command](https://github.com/devfile-samples/devfile-sample-java-springboot-basic/blob/main/devfile.yaml#L43-L56) completes the [outerloop](https://devfile.io/docs/2.2.0/innerloop-vs-outerloop) deployment phase by pointing to the `image-build` and `kubernetes-deploy` components to create your application.

### Additional resources
* For more information about Spring Boot, see [Spring Boot](https://spring.io/projects/spring-boot).
* For more information about devfiles, see [Devfile.io](https://devfile.io/).
* For more information about the deployment outerloop, see [Devfile.io: Innerloop versus outerloop](https://devfile.io/docs/2.2.0/innerloop-vs-outerloop).
* For more information about Dockerfiles, see [Dockerfile reference](https://docs.docker.com/engine/reference/builder/).

- For more information about Spring Boot, see [Spring Boot](https://spring.io/projects/spring-boot).
- For more information about devfiles, see [Devfile.io](https://devfile.io/).
- For more information about the deployment outerloop, see [Devfile.io: Innerloop versus outerloop](https://devfile.io/docs/2.2.0/innerloop-vs-outerloop).
- For more information about Dockerfiles, see [Dockerfile reference](https://docs.docker.com/engine/reference/builder/).
52 changes: 15 additions & 37 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schemaVersion: 2.2.0
metadata:
name: java-springboot
version: 1.2.1
version: 2.0.0
attributes:
alpha.dockerimage-port: 8081
displayName: Spring Boot®
Expand All @@ -17,39 +17,17 @@ metadata:
parent:
id: java-springboot
registryUrl: 'https://registry.devfile.io'
version: 1.2.0
components:
- name: image-build
image:
imageName: java-springboot-image:latest
dockerfile:
uri: docker/Dockerfile
buildContext: .
rootRequired: false
- name: kubernetes-deploy
attributes:
deployment/replicas: 1
deployment/cpuRequest: 10m
deployment/memoryRequest: 180Mi
deployment/container-port: 8081
kubernetes:
uri: deploy.yaml
endpoints:
- name: http-8081
targetPort: 8081
path: /
commands:
- id: build-image
apply:
component: image-build
- id: deployk8s
apply:
component: kubernetes-deploy
- id: deploy
composite:
commands:
- build-image
- deployk8s
group:
kind: deploy
isDefault: true
version: 2.1.0
components:
- name: deploy
attributes:
deployment/replicas: 1
deployment/cpuRequest: 10m
deployment/memoryRequest: 180Mi
deployment/container-port: 8080
kubernetes:
uri: kubernetes/deploy.yaml
endpoints:
- name: http-8080
targetPort: 8080
path: /
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Then run the container using:
#
# docker run -i --rm -p 8081:8081 springboot/sample-demo
# docker run -i --rm -p 8080:8080 springboot/sample-demo
####
FROM registry.access.redhat.com/ubi8/openjdk-17:1.15-1.1682053058 AS builder

Expand All @@ -27,6 +27,6 @@ RUN mv target/$(cat .env-id)-$(cat .env-version).jar target/export-run-artifact.

FROM registry.access.redhat.com/ubi8/openjdk-17-runtime:1.15-1.1682053056
COPY --from=builder /home/jboss/project/target/export-run-artifact.jar /deployments/export-run-artifact.jar
EXPOSE 8081
ENTRYPOINT ["/opt/jboss/container/java/run/run-java.sh", "--server.port=8081"]
EXPOSE 8080
ENTRYPOINT ["/opt/jboss/container/java/run/run-java.sh", "--server.port=8080"]

8 changes: 4 additions & 4 deletions deploy.yaml → kubernetes/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
image: java-springboot-image:latest
ports:
- name: http
containerPort: 8081
containerPort: 8080
protocol: TCP
resources:
requests:
Expand All @@ -30,9 +30,9 @@ metadata:
name: my-java-springboot-svc
spec:
ports:
- name: http-8081
port: 8081
- name: http-8080
port: 8080
protocol: TCP
targetPort: 8081
targetPort: 8080
selector:
app: java-springboot-app

0 comments on commit beac7d1

Please sign in to comment.