Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit ff913c7

Browse files
committed
CodeReady Workspace quick guide
Signed-off-by: Jacob Berger <jacob.berger@ibm.com>
1 parent ece920f commit ff913c7

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
layout: guide
3+
summary-title: "Codewind in CodeReady Workspaces"
4+
title: "Getting Started with Codewind in CodeReady Workspaces"
5+
categories: guides
6+
guide_description: "Take advantage of Codewind's tools to help build high quality cloud native applications regardless of which IDE or language you use."
7+
permalink: codewind-crw-quick-guide.html
8+
duration: 10 minutes
9+
tags: Codewind, CodeReady Workspaces, Openshift, Kubernetes, containers, microservice
10+
---
11+
12+
## Objectives
13+
* Install CodeReady Workspaces and Codewind
14+
* Develop a simple microservice, using Eclipse Codewind on CodeReady Workspaces
15+
16+
## Overview
17+
Eclipse Codewind enables you to develop microservice applications from application stacks in an integrated developer environment (IDE). CodeReady Workspaces provides a containerized IDE for cloud native application development on an OpenShift cluster.
18+
19+
## Developing with CodeReady Workspaces
20+
CodeReady workspaces uses Kubernetes and containers to provide a preconfigured environment. CodeReady Workspaces allows you to create, build, and test your code in OpenShift containers but makes you feel like you are working on an IDE on your local machine.
21+
22+
### Prerequisite
23+
CodeReady Workspaces requires at least two 1Gi ReadWriteOnce (RWO) persistent volumes on the cluster to install and a 1Gi RWO volume for each created workspace.
24+
25+
Each Codewind workspace also requires at least on 1Gi ReadWriteMany (RWX) persistent volume.
26+
27+
### Installing CodeReady Workspaces
28+
To install CodeReady Workspaces, set `Spec.codeReadyWorkspaces.enable: true` in the Kabanero custom resource (Kabanero CR) instance and apply it.
29+
30+
To edit the Kabanero CR, you can run `oc edit kabanero -n kabanero` from the command line.
31+
32+
The following sample shows a Kabanero CR instance configuration:
33+
34+
```yaml
35+
apiVersion: kabanero.io/v1alpha2
36+
kind: Kabanero
37+
metadata:
38+
name: kabanero
39+
spec:
40+
version: "0.6.0"
41+
codeReadyWorkspaces:
42+
enable: true
43+
operator:
44+
customResourceInstance:
45+
tlsSupport: true
46+
selfSignedCert: true
47+
stacks:
48+
repositories:
49+
- name: central
50+
https:
51+
url: https://github.com/kabanero-io/collections/releases/download/0.6.0/kabanero-index.yaml
52+
```
53+
54+
### Configuring CodeReady Workspaces
55+
The Kabanero CR instance provides additional fields allowing you to configure your installation of CodeReady Workspaces.
56+
57+
* If you want to install CodeReady Workspaces with TLS Support, set `Spec.codeReadyWorkspaces.operator.customResourceInstance.tlsSupport` to `true`.
58+
**Note:** If your OpenShift cluster's router is set up with self-signed certificates, `Spec.codeReadyWorkspaces.operator.instance.selfSignedCert` must also be set to `true`.
59+
* If you want to use your OpenShift accounts with CodeReady Workspaces, set up permanent users (accounts other than kube:admin) and then set `Spec.codeReadyWorkspaces.operator.customResourceInstance.openShiftOAuth` to `true`.
60+
* To view the full list of configurable fields, see [Kabanero Custom Resource](../configuration/kabanero-cr-config.html).
61+
62+
### Installing Codewind
63+
When CodeReady Workspaces is installed on your OpenShift cluster, complete the following steps:
64+
65+
1. Log in to CodeReady Workspaces.
66+
2. Click **Create Workspace**.
67+
3. For **Name**, give your workspace some meaningful name.
68+
4. For **Select Stack**, select `Codewind`.
69+
5. Click **Create & Open** to create and start Codewind in CodeReady Workspaces.
70+
71+
CodeReady Workspaces starts Codewind and installs the Codewind plugins. This process might take a couple of minutes for all of the necessary components to be pulled and started.
72+
73+
See (Codewind on Che documentation)[https://www.eclipse.org/codewind/mdt-che-installinfo.html] for additional information and next steps.
74+
75+
### Configuring Codewind to use application stacks
76+
Configure Codewind to use Appsody templates so you can focus exclusively on your code. These templates include an Eclipse MicroProfile stack that you can use to follow this guide. Complete the following steps to select the Appsody templates:
77+
78+
1. Under the Explorer pane, select `Codewind`.
79+
2. Right-click `Local`.
80+
3. Select `Template Source Manager`.
81+
4. Enable `Appsody Stacks - incubator` and `Default templates`.
82+
83+
You have now configured Codewind to use Appsody templates and can proceed to develop your microservice within Codewind.
84+
85+
If your organization uses customized application stacks and has given you a URL that points to an `index.json` file, you can add it to Codewind:
86+
87+
1. Return to `Codewind` and right-click `Local`.
88+
2. Select `Template Source Manager`.
89+
3. Click the `Add New +` button to add your URL.
90+
4. Add your URL in the pop up window and save your changes.
91+
92+
### Creating an Appsody project
93+
Throughout the application lifestyle, Appsody helps you develop containerized applications and leverage containers curated for your usage. If you want more context about Appsody, visit the [Appsody welcome page](https://appsody.dev/docs).
94+
95+
1. Under the Explorer pane, select `Codewind`.
96+
2. Expand `Codewind` by clicking the drop-down arrow.
97+
3. Hover over the `Projects` entry underneath Codewind in the Explorer pane, and press the `+` icon to create a project.
98+
* **Note:** Make sure Docker is running. Otherwise, you get an error.
99+
4. Choose the `Appsody Open Liberty default template (Appsody Stacks - incubator)`.
100+
5. Name your project `appsody-calculator`.
101+
* If you don't see Appsody templates, find and select `Template Source Manager` and enable `Appsody Stacks - incubator`.
102+
* The templates are refreshed, and the Appsody templates are available.
103+
6. Press `Enter`.
104+
* To monitor your project's progress, right-click your project, and select `Show all logs`. Then an `Output` tab is displayed where you see your project's build logs.
105+
106+
Your project is complete when you see your application status is running and your build status is successful.
107+
108+
### Accessing the application endpoint in a browser
109+
1. Return to your project under the Explorer pane.
110+
2. Select the Open App icon next to your project's name, or right-click your project and select `Open App`.
111+
112+
Your application is now opened in a browser, showing the welcome to your Appsody microservice page.
113+
114+
### Adding a REST service to your application
115+
1. Go to your project's workspace under the Explorer tab.
116+
2. Navigate to `src->main->java->dev->appsody->starter`.
117+
3. Right-click `starter` and select `New File`.
118+
4. Create a file, name it `Calculator.java`, and press `Enter`. This file is your JAX-RS resource.
119+
5. Populate the file with the following code and then **save** the file:
120+
121+
```java
122+
package dev.appsody.starter;
123+
124+
import javax.ws.rs.core.Application;
125+
import javax.ws.rs.GET;
126+
import javax.ws.rs.Path;
127+
import javax.ws.rs.Produces;
128+
import javax.ws.rs.core.MediaType;
129+
import javax.ws.rs.core.Response;
130+
131+
import javax.ws.rs.PathParam;
132+
133+
@Path("/calculator")
134+
public class Calculator extends Application {
135+
136+
@GET
137+
@Path("/aboutme")
138+
@Produces(MediaType.TEXT_PLAIN)
139+
public String aboutme() {
140+
return "You can add (+), subtract (-), and multiply (*) with this simple calculator.";
141+
}
142+
143+
@GET
144+
@Path("/{op}/{a}/{b}")
145+
@Produces(MediaType.TEXT_PLAIN)
146+
public Response calculate(@PathParam("op") String op, @PathParam("a") String a, @PathParam("b") String b) {
147+
int numA = Integer.parseInt(a);
148+
int numB = Integer.parseInt(b);
149+
150+
switch (op) {
151+
case "+":
152+
return Response.ok(a + "+" + b + "=" + (Integer.toString((numA + numB)))).build();
153+
154+
case "-":
155+
return Response.ok(a + "-" + b + "=" + (Integer.toString((numA - numB)))).build();
156+
157+
case "*":
158+
return Response.ok(a + "*" + b + "=" + (Integer.toString((numA * numB)))).build();
159+
160+
default:
161+
return Response.ok("Invalid operation. Please Try again").build();
162+
}
163+
}
164+
}
165+
```
166+
167+
Any changes you make to your code are automatically built and re-deployed by Codewind and you can view them in your browser.
168+
169+
### Working with the example calculator microservice
170+
You now can work with the example calculator microservice.
171+
172+
1. Use the exposed port number you saw when you first opened the application.
173+
2. Make sure to remove the `< >` symbol in the URL.
174+
3. `http://127.0.0.1:<port>/starter/calculator/aboutme`
175+
4. You see the following response:
176+
177+
```
178+
You can add (+), subtract (-), and multiply (*) with this simple calculator.
179+
```
180+
181+
You can also try a few of the sample calculator functions:
182+
183+
* `http://127.0.0.1:<port>/starter/calculator/{op}/{a}/{b}`, where you can input one of the available operations `(+, _, *)`, and an integer a, and an integer b.
184+
* So for `http://127.0.0.1:<port>/starter/calculator/+/10/3` you see: `10+3=13`.
185+
186+
## What you have learned
187+
Now that you have completed this quick guide, you have learned to:
188+
189+
1. Install CodeReady Workspaces and Codewind
190+
2. Develop your own microservice using Codewind on CodeReady Workspaces
191+
192+
## Next Steps
193+
See other quick guides to learn how to develop with Codewind:
194+
195+
* [Codewind in Eclipse](codewind-eclipse-quick-guide.html)
196+
* [Codewind in VS Code](https://www.eclipse.org/codewind/codewind-vscode-quick-guide.html)

0 commit comments

Comments
 (0)