Skip to content

Commit

Permalink
add CRW instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
andykrohg committed Jan 5, 2022
1 parent f528d0d commit d5bb6ca
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 3 deletions.
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ Backend service that provides WebRTC signaling for connecting clients together.
* User registration and management
* A basic chat feature whereby a user can send a message to all other connected users
* Generic message handling for signaling and ICE negotiation to support a WebRTC session between two users

## Getting started
### Running the application in dev mode

You can run your application in dev mode that enables live coding using:
```shell script
./mvnw quarkus:dev
```

#### Connecting using the GUI
Once the app is running, open http://localhost:8080 in your browser. Enter your desired username where indicated, and send a message to the socket using the Chat box at the bottom of the page.

Expand All @@ -30,6 +27,37 @@ Once you're connected, send a message to chat using JSON, like this:
{"type":"message", "text":"This is a test message"}
```

### Setting up a development environment in CodeReady Workspaces
This repository is currently private, so in order to import it with CodeReady Workspaces, you'll need to create a credential secret.
1. Set variables for your github username and a [personal access token](https://github.com/settings/tokens) with full **repo** permissions.
```bash
GITHUB_USERNAME=andykrohg
GITHUB_TOKEN=ghp_000000000000000000000
```
2. Switch to (or create) the namespace where your workspaces will be provisioned, which by default is `${username}-codeready`. For example:
```bash
oc project user1-codeready
```
2. Create a secret to hold your git credentials. The annotations will inform the CodeReady Server that it needs to mount the secret into your workspace once it's created.
```bash
oc apply -f - << EOF
apiVersion: v1
kind: Secret
metadata:
name: git-credentials-secret
labels:
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: workspace-secret
annotations:
che.eclipse.org/automount-workspace-secret: 'true'
che.eclipse.org/mount-path: /home/theia/.git-credentials
che.eclipse.org/mount-as: file
che.eclipse.org/git-credential: 'true'
stringData:
credentials: https://$GITHUB_USERNAME:[email protected]
EOF
```
3. Create a new workspace using the `devfile.yaml` in this repository.
## Message Schema
The server expects most messages to take the form of a JSON object, giving particular regard to the following attributes:
* **type**: the message type. Supported values:
Expand Down
117 changes: 117 additions & 0 deletions devfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
apiVersion: 1.0.0
metadata:
name: clivrt-signaling-svc
projects:
- name: clivrt-signaling-svc
source:
location: 'https://github.com/collabinator/clivrt-signaling-svc.git'
type: git
components:
- id: redhat/quarkus-java11/latest
type: chePlugin
- mountSources: true
endpoints:
- name: quarkus-development-server
port: 8080
- attributes:
path: /hello/greeting/che-user
name: hello-greeting-endpoint
port: 8080
- attributes:
public: 'false'
name: debug
port: 5005
- attributes:
public: 'false'
name: tests
port: 8081
memoryLimit: 512Mi
type: dockerimage
volumes:
- name: m2
containerPath: /home/jboss/.m2
alias: maven
image: 'registry.redhat.io/codeready-workspaces/plugin-java11-rhel8@sha256:f90e09397caa4dd5cd3476e495adfc0096272c0ba746a6e32215175c541ae058'
env:
- value: '-XX:MaxRAMPercentage=50.0 -XX:+UseParallelGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xms20m -Djava.security.egd=file:/dev/./urandom -Duser.home=/home/jboss'
name: JAVA_OPTS
- value: $(JAVA_OPTS)
name: MAVEN_OPTS
commands:
- name: 1. Package the application
actions:
- workdir: '${CHE_PROJECTS_ROOT}/clivrt-signaling-svc'
type: exec
command: mvn package
component: maven
- name: 2. Start Quarkus in devmode (hot deploy + debug)
actions:
- workdir: '${CHE_PROJECTS_ROOT}/clivrt-signaling-svc'
type: exec
command: 'mvn compile quarkus:dev -Dquarkus.http.host=0.0.0.0 -Dquarkus.live-reload.instrumentation=false'
component: maven
- name: 3. Share this workspace
actions:
- workdir: '${CHE_PROJECTS_ROOT}/clivrt-signaling-svc'
type: exec
command: |
read -p "ENTER your OpenShift username: " OCP_USERNAME
read -p "ENTER your OpenShift password: " -s OCP_PASSWORD
echo
# Login to OpenShift with the provided credentials, and grab the token
oc login --insecure-skip-tls-verify=true -u $OCP_USERNAME -p $OCP_PASSWORD $KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
OCP_TOKEN=$(oc whoami -t)
echo
# Read username
read -p "ENTER the username of the person with whom you want to share this workspace: " OTHER_CRW_USER
echo
KEYCLOAK_URL=http://keycloak.openshift-workspaces.svc:8080
# Download jq to tmp folder
curl -L -s https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -o /tmp/jq
chmod +x /tmp/jq
# Swap OCP Token for CRW Token
CRW_TOKEN=$(curl -X POST -s -d "client_id=codeready-public" --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" -d "subject_token=${OCP_TOKEN}" -d "subject_issuer=openshift-v4" --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:access_token" ${KEYCLOAK_URL}/auth/realms/codeready/protocol/openid-connect/token | /tmp/jq -r .access_token)
# Get target user's GUID from their username
CHE_USER_ID=$(curl -s -H "Authorization: Bearer ${CRW_TOKEN}" "${CHE_API}/user/find?name=${OTHER_CRW_USER}" | /tmp/jq -r .id)
# Remove jq
rm -f /tmp/jq
# Grant read, use, and run permissions for this workspace for the indicated user
curl -X POST --header 'Content-Type: application/json' -H "Authorization: Bearer ${CRW_TOKEN}" -H 'Accept: text/html' -d '{
"actions": [
"read",
"use",
"run"
],
"userId": "'$CHE_USER_ID'",
"domainId": "workspace",
"instanceId": "'$CHE_WORKSPACE_ID'"
}' "${CHE_API}/permissions" && \
echo "✅ Successfully shared workspace with user $OTHER_CRW_USER"
component: maven
- name: Attach remote debugger
actions:
- referenceContent: |
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"request": "attach",
"name": "Attach to Remote Quarkus App",
"hostName": "localhost",
"port": 5005
}
]
}
type: vscode-launch

0 comments on commit d5bb6ca

Please sign in to comment.