Skip to content

Commit

Permalink
Add Java Spring Boot to quickstart
Browse files Browse the repository at this point in the history
<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind bug
/kind feature
/kind cleanup
/kind tests

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->

/kind documentation

**What does this PR do / why we need it:**

Adds a Java Spring Boot example to the quickstart

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

Closes redhat-developer#5746

**PR acceptance criteria:**

- [X] Documentation

**How to test changes / Special notes to the reviewer:**

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
  • Loading branch information
cdrage committed Jun 1, 2022
1 parent 0e32d3a commit 1c12e16
Showing 1 changed file with 267 additions and 6 deletions.
273 changes: 267 additions & 6 deletions docs/website/versioned_docs/version-3.0.0/user-guides/quickstart.md
Expand Up @@ -93,6 +93,18 @@ Restore succeeded.
```

</TabItem>
<TabItem value="java" label="Java (Spring Boot)">

For Java, we will use the [Spring Initializr](https://start.spring.io/) to generate the example source code:

1. Navigate to [start.spring.io](https://start.spring.io/)
2. Select **11** under **Java**
2. Click on "Add" under "Dependencies"
3. Select "Spring Web"
4. Click "Generate" to generate and download the source code

Finally, open a terminal and navigate to the directory.
</TabItem>
</Tabs>

Your source code has now been generated and created in the directory.
Expand Down Expand Up @@ -137,9 +149,6 @@ Your new component 'my-nodejs-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.
```

A `devfile.yaml` has now been added to your directory and now you're ready to start development.

</TabItem>
<TabItem value="dotnet" label=".NET">

Expand Down Expand Up @@ -179,10 +188,47 @@ To start editing your component, use 'odo dev' and open this folder in your favo
Changes will be directly reflected on the cluster.
```

A `devfile.yaml` has now been added to your directory and now you're ready to start development.
</TabItem>
<TabItem value="java" label="Java (Spring Boot)">

Let's run `odo init` and select Java Spring Boot:

```console
$ odo init
__
/ \__ Initializing new component
\__/ \ Files: Source code detected, a Devfile will be determined based upon source code autodetection
/ \__/ odo version: v3.0.0-alpha2
\__/

Interactive mode enabled, please answer the following questions:
Based on the files in the current directory odo detected
Language: java
Project type: spring
The devfile "java-springboot" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? Yes
✓ Downloading devfile "java-springboot" from registry "DefaultDevfileRegistry" [1s]
Current component configuration:
Container "m2":
Opened ports:
Environment variables:
Container "tools":
Opened ports:
- 8080
Environment variables:
- DEBUG_PORT = 5858
? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: my-java-springboot-app

Your new component 'my-java-springboot-app' is ready in the current directory.
To start editing your component, use 'odo dev' and open this folder in your favorite IDE.
Changes will be directly reflected on the cluster.
```
</TabItem>
</Tabs>

A `devfile.yaml` has now been added to your directory and now you're ready to start development.

## Step 2. Developing your application continuously (`odo dev`)

Now that we've generated our code as well as our Devfile, let's start on development.
Expand Down Expand Up @@ -243,6 +289,34 @@ Press Ctrl+c to exit `odo dev` and delete resources from the cluster
```


</TabItem>
<TabItem value="java" label="Java (Spring Boot)">

Let's run `odo dev` to start development on your Java Spring Boot application:

```console
$ odo dev
__
/ \__ Developing using the my-java-springboot-app Devfile
\__/ \ Namespace: default
/ \__/ odo version: v3.0.0-alpha2
\__/

↪ Deploying to the cluster in developer mode
✓ Waiting for Kubernetes resources [5s]
✓ Added storage m2 to my-java-springboot-app
✓ Syncing files into the container [734ms]
✓ Building your application in container on cluster [21s]
✓ Executing the application [1s]

Your application is now running on the cluster
- Forwarding from 127.0.0.1:40001 -> 8080

Watching for changes in the current directory /Users/user/java
Press Ctrl+c to exit `odo dev` and delete resources from the cluster
```


</TabItem>
</Tabs>

Expand Down Expand Up @@ -463,7 +537,7 @@ $ odo deploy
/ \__/ odo version: v3.0.0-alpha2
\__/

↪ Building & Pushing Container: MYUSERNAME/test
↪ Building & Pushing Container: MYUSERNAME/nodejs-odo-example
• Building image locally ...
✓ Building image locally [880ms]
• Pushing image to container registry ...
Expand Down Expand Up @@ -661,7 +735,7 @@ $ odo deploy
/ \__/ odo version: v3.0.0-alpha2
\__/

↪ Building & Pushing Container: MYUSERNAME/test
↪ Building & Pushing Container: MYUSERNAME/dotnet-odo-example
• Building image locally ...
✓ Building image locally [880ms]
• Pushing image to container registry ...
Expand All @@ -684,6 +758,193 @@ Your Devfile has been successfully deployed

Your application has now been deployed to the Kubernetes cluster with Deployment, Service, and Ingress resources.

Test your application by visiting the `DOMAIN_NAME` variable that you had set in the `devfile.yaml`.

</TabItem>
<TabItem value="java" label="Java (Spring Boot)">

#### 1. Containerize the application

In order to deploy our application, we must containerize it in order to build and push to a registry. Create the following `Dockerfile` in the same directory:

```dockerfile
```

#### 2. Modify the Devfile

Let's modify the `devfile.yaml` and add the respective deployment code.

`odo deploy` uses Devfile schema **2.2.0**. Change the schema to reflect the change:

```yaml
# Deploy "kind" ID's use schema 2.2.0+
schemaVersion: 2.2.0
```

Add the `variables` section:

```yaml
# Add the following variables code anywhere in devfile.yaml
# This MUST be a container registry you are able to access
variables:
CONTAINER_IMAGE: quay.io/MYUSERNAME/java-springboot-odo-example
RESOURCE_NAME: my-java-springboot-app
CONTAINER_PORT: "8080"
DOMAIN_NAME: java-springboot.example.com
```

Add the commands used to deploy:

```yaml
# This is the main "composite" command that will run all below commands
- id: deploy
composite:
commands:
- build-image
- k8s-deployment
- k8s-service
- k8s-ingress
group:
isDefault: true
kind: deploy

# Below are the commands and their respective components that they are "linked" to deploy
- id: build-image
apply:
component: outerloop-build
- id: k8s-deployment
apply:
component: outerloop-deployment
- id: k8s-service
apply:
component: outerloop-service
- id: k8s-ingress
apply:
component: outerloop-ingress
```

Add the Kubernetes Service and Ingress inline code to `components`:
```yaml
components:

# This will build the container image before deployment
- name: outerloop-build
image:
dockerfile:
buildContext: ${PROJECT_SOURCE}
rootRequired: false
uri: ./Dockerfile
imageName: "{{CONTAINER_IMAGE}}"

# This will create a Deployment in order to run your container image across
# the cluster.
- name: outerloop-deployment
kubernetes:
inlined: |
kind: Deployment
apiVersion: apps/v1
metadata:
name: {{RESOURCE_NAME}}
spec:
replicas: 1
selector:
matchLabels:
app: {{RESOURCE_NAME}}
template:
metadata:
labels:
app: {{RESOURCE_NAME}}
spec:
containers:
- name: {{RESOURCE_NAME}}
image: {{CONTAINER_IMAGE}}
ports:
- name: http
containerPort: {{CONTAINER_PORT}}
protocol: TCP
resources:
limits:
memory: "1024Mi"
cpu: "500m"
# This will create a Service so your Deployment is accessible.
# Depending on your cluster, you may modify this code so it's a
# NodePort, ClusterIP or a LoadBalancer service.
- name: outerloop-service
kubernetes:
inlined: |
apiVersion: v1
kind: Service
metadata:
name: {{RESOURCE_NAME}}
spec:
ports:
- name: "{{CONTAINER_PORT}}"
port: {{CONTAINER_PORT}}
protocol: TCP
targetPort: {{CONTAINER_PORT}}
selector:
app: {{RESOURCE_NAME}}
type: ClusterIP
# Let's create an Ingress so we can access the application via a domain name
- name: outerloop-ingress
kubernetes:
inlined: |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{RESOURCE_NAME}}
spec:
rules:
- host: "{{DOMAIN_NAME}}"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: {{RESOURCE_NAME}}
port:
number: {{CONTAINER_PORT}}
```


#### 3. Run the `odo deploy` command

Now we're ready to run `odo deploy`:

```console
$ odo deploy
__
/ \__ Deploying the application using my-java-springboot-app Devfile
\__/ \ Namespace: default
/ \__/ odo version: v3.0.0-alpha2
\__/

↪ Building & Pushing Container: MYUSERNAME/java-springboot-example
• Building image locally ...
✓ Building image locally [880ms]
• Pushing image to container registry ...
✓ Pushing image to container registry [5s]

↪ Deploying Kubernetes Component: java-springboot-example
✓ Searching resource in cluster
✓ Creating kind Deployment [48ms]

↪ Deploying Kubernetes Component: java-springboot-example
✓ Searching resource in cluster
✓ Creating kind Service [51ms]

↪ Deploying Kubernetes Component: java-springboot-example
✓ Searching resource in cluster
✓ Creating kind Ingress [49ms]

Your Devfile has been successfully deployed
```

Your application has now been deployed to the Kubernetes cluster with Deployment, Service, and Ingress resources.

Test your application by visiting the `DOMAIN_NAME` variable that you had set in the `devfile.yaml`.

</TabItem>
Expand Down

0 comments on commit 1c12e16

Please sign in to comment.