Skip to content

Commit

Permalink
feat: improve build, deployment and documentation
Browse files Browse the repository at this point in the history
Add a combined manifest that allows pushing all samples at the same time.

Update build and test instructions.

Minor fixes for updated dependencies.
  • Loading branch information
raghunathd8 authored and peanball committed Aug 15, 2023
1 parent 669a4aa commit 5a3f231
Show file tree
Hide file tree
Showing 48 changed files with 942 additions and 229 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Pipfile
Pipfile.lock
.bundle
**/ruby-*/vendor
.idea
.gradle
http2/.gradle
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ The following samples are available in the respective subdirectories:

The samples provided in this repository are intended to run in a Cloud Foundry environment. Each of the samples may contain further information on specific technical requirements.

Samples are provided in different programming languages and require the respective runtime environment for development.
Samples are provided in the following programming languages and require the respective runtime environment for development:
* go
* java
* node
* python
* ruby
## Download and Installation

These samples are provided as source code and should be seen as starting point or reference on how to approach or solve a particular requirement.
Expand Down
113 changes: 44 additions & 69 deletions http2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,107 +11,82 @@ Note: due to the lack of H2C support in popular frameworks, the Ruby and Python

## Downloading the Samples

Clone this repo and go to the app you want to test
Clone this repo

```shell
# Skip this if you cloned the repository already
> git clone https://github.com/SAP-samples/cf-routing-samples
> cd cf-routing-samples/http2

# Depending on the app you want to try, go into that respective directory, e.g. go-http2
> cd go-http2
```

### How to deploy H2C apps

Make sure you have [CF CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html) version 8 or higher installed

## Deploying all the apps at once
### Pre-requisites
Set the desired domain in [vars.yml](vars.yml) file:
```shell
> cf version
cf version 8.0.0+e8d41cf8e.2021-09-16
```

Clone this repo and go to the app you want to test

```shell
> git clone https://github.com/SAP-samples/cf-routing-samples
> cd cf-routing-samples/http2
```

Build the app (Java apps only)

```shell
> ./gradlew build
```

Choose a name and push the application without adding a route

```shell
> cf push --no-route http2-example-app-go

# For the Java app, specify the path to the distribution zip
> cf push --no-route http2-example-app-java --buildpack java_buildpack --path app/build/distributions/app.zip
# edit the vars.yml file and replace <domain.for.app.routes> with required domain
# my.cf.app.domain is used as an example for demonstration
> vi vars.yml
> cat vars.yml
domain: my.cf.app.domain
```

Map an HTTP2 route with the application

#### For java app do the following
```shell
> export CF_APPS_DOMAIN=my-apps.cf.example.com
> cf map-route http2-example-app-go $CF_APPS_DOMAIN --hostname http2-example-app-go --destination-protocol http2
# please make sure that the openjdk@11 is installed and gradle wrapper is pointing to it
> ./gradlew clean build
```

Check the app is working

### Deploy all apps
```shell
> curl https://http2-example-app-go.$CF_APPS_DOMAIN /
Hello! This Go application is speaking plain text HTTP2 (H2C) with the CF routing layer
# run the following commands in cf environment
> cd http2
> export DOMAIN=my.cf.app.domain
> cf push --manifest apps-manifest.yml --var domain=$DOMAIN --vars-file gradle.properties
```

### How to deploy gRPC apps

Make sure you have [CF CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html) version 8 or higher installed
## Deploying apps individually
* Make sure you have [CF CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html) version 8 or higher installed

```shell
> cf version
cf version 8.0.0+e8d41cf8e.2021-09-16
```

Build the app (Java apps only)

```shell
> ./gradlew build
```

Choose a name and push the application without adding a route

```shell
> cf push --no-route grpc-example-app-go

# For the Java app, specify the path to the distribution zip
> cf push --no-route grpc-example-app-java --buildpack java_buildpack --path app/build/distributions/app.zip
```

Map an HTTP2 route with the application. It must be a route on an apps domain supporting mutual TLS (mTLS) and you must have the client certificate and private key available on your machine

* And set the desired domain in [vars.yml](vars.yml) file
### How to deploy H2C apps
* Go: [go-http2](go-http2)
* Java: [java-http2](java-http2) (Note: refer [pre-requisites](#For java app do the following) for Java)
* Node: [node-http2](node-http2)
* Python: [python-http2](python-http2)
* Ruby: [ruby-http2](ruby-http2)
#### Check H2C apps
```shell
> export CF_MTLS_APPS_DOMAIN=my-mtls-apps.cf.example.com
> cf map-route grpc-example-app-go $CF_MTLS_APPS_DOMAIN --hostname grpc-example-app-go --destination-protocol http2
# format: https://<language>-http2-test.my.cf.app.domain
> export DOMAIN=my.cf.app.domain
> curl -v --http2-prior-knowledge https://go-http2-test.my.cf.app.$DOMAIN
> curl -v --http2-prior-knowledge https://java-http2-test.my.cf.app.$DOMAIN
> curl -v --http2-prior-knowledge https://node-http2-test.my.cf.app.$DOMAIN
> curl -v --http2-prior-knowledge https://python-http2-test.my.cf.app.$DOMAIN
> curl -v --http2-prior-knowledge https://ruby-http2-test.my.cf.app.$DOMAIN
```

### How to deploy gRPC apps
* Go: [go-grpc](go-grpc)
* Java: [java-grpc](java-grpc) (Note: refer [pre-req](#For java app do the following) for Java)
* Node: [node-grpc](node-grpc)
* Python: [python-grpc](python-grpc)
* Ruby: [ruby-grpc](ruby-grpc)
#### Check gRPC apps
Download grpcurl from https://github.com/fullstorydev/grpcurl/releases and put it in your path

Make a gRPC request using grpcurl

```shell
# following example with mtls
> export MTLS_CERT_PATH=path/to/mtls_client_certificate.pem
> export MTLS_KEY_PATH=path/to/mtls_client_private_key.pem
> grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH grpc-example-app-go.$CF_MTLS_APPS_DOMAIN:443 example.Example.Run
> grpcurl -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH go-grpc-test.my.cf.app.domain:443 example.Example.Run
{
"message": "Hello! This Go application is speaking gRPC"
}

# Alternative grpcurl for apps which don't support reflection (such as Node.js)
> grpcurl -proto example.proto -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH grpc-example-app-node.$CF_MTLS_APPS_DOMAIN:443 Example.Run
> grpcurl -proto path/to/example.proto -insecure -cert $MTLS_CERT_PATH -key $MTLS_KEY_PATH node-grpc-test.my.cf.app.domain:443 Example.Run
{
"message": "Hello! This Node.JS application is speaking gRPC"
}
Expand Down
114 changes: 114 additions & 0 deletions http2/apps-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
version: 1
stack: &stack
stack: cflinuxfs4
go_defaults: &go_defaults
disk_quota: 32M
memory: 32M
java_defaults: &java_defaults
disk_quota: 768M
memory: 768M
node_defaults: &node_defaults
disk_quota: 256M
memory: 256M
ruby_defaults: &ruby_defaults
disk_quota: 256M
memory: 256M
python_defaults: &python_defaults
disk_quota: 512M
memory: 512M
applications:
- name: go-grpc-test
<<: *stack
<<: *go_defaults
path: ./go-grpc/
buildpacks:
- go_buildpack
routes:
- route: go-grpc-test.((domain))
protocol: http2
- name: go-http2-test
<<: *stack
<<: *go_defaults
path: ./go-http2/
buildpacks:
- go_buildpack
routes:
- route: go-http2-test.((domain))
protocol: http2
- name: java-grpc-test
<<: *stack
<<: *java_defaults
path: ./java-grpc/app/build/distributions/app-((version)).zip
buildpacks:
- java_buildpack
routes:
- route: java-grpc-test.((domain))
protocol: http2
env:
JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ }}'
- name: java-http2-test
<<: *stack
<<: *java_defaults
path: ./java-http2/app/build/distributions/app-((version)).zip
buildpacks:
- java_buildpack
routes:
- route: java-http2-test.((domain))
protocol: http2
env:
JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ }}'
- name: node-grpc-test
<<: *stack
<<: *node_defaults
path: ./node-grpc/
buildpacks:
- https://github.com/cloudfoundry/nodejs-buildpack
routes:
- route: node-grpc-test.((domain))
protocol: http2
- name: node-http2-test
<<: *stack
<<: *node_defaults
path: ./node-http2/
buildpacks:
- https://github.com/cloudfoundry/nodejs-buildpack
routes:
- route: node-http2-test.((domain))
protocol: http2
- name: python-grpc-test
<<: *stack
<<: *python_defaults
path: ./python-grpc/
buildpacks:
- https://github.com/cloudfoundry/python-buildpack
routes:
- route: python-grpc-test.((domain))
protocol: http2
- name: python-http2-test
<<: *stack
<<: *python_defaults
path: ./python-http2/
buildpacks:
- https://github.com/cloudfoundry/python-buildpack
routes:
- route: python-http2-test.((domain))
protocol: http2
- name: ruby-grpc-test
<<: *stack
<<: *ruby_defaults
path: ./ruby-grpc/
buildpacks:
- https://github.com/cloudfoundry/ruby-buildpack
routes:
- route: ruby-grpc-test.((domain))
protocol: http2
- name: ruby-http2-test
<<: *stack
<<: *ruby_defaults
path: ./ruby-http2/
buildpacks:
- https://github.com/cloudfoundry/ruby-buildpack
routes:
- route: ruby-http2-test.((domain))
protocol: http2
12 changes: 12 additions & 0 deletions http2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id "org.cyclonedx.bom" version "1.6.1"
}

allprojects {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
23 changes: 21 additions & 2 deletions http2/go-grpc/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
# Go gRPC Sample

Example gRPC server implemented in Go
## Deploying the Go app
### Deploy the app using the manifest file
Deploy the app
```shell
> export DOMAIN=my.cf.app.domain
> cf push -f app-manifest.yml --var domain=$DOMAIN
```

### Deploy the app without the manifest file
```shell
> cf push --no-route go-grpc-test --buildpack go_buildpack
# my.cf.app.domain is used as an example for demonstration purpose
> cf map-route go-grpc-test my.cf.app.domain --hostname go-grpc-test --app-protocol http2
```

## Running Locally
## Testing the Go app
`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl).
```shell
> grpcurl go-grpc-test.my.cf.app.domain:443 example.Example.Run
```

## Building and running on the local machine

1. `go build`
2. `PORT=8080 ./go-grpc`
3. `grpcurl -vv -plaintext localhost:8080 example.Example.Run`

`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl).

### Renerating code

The generated code is created using the Protoc compiler, which needs to be [installed separately](https://grpc.io/docs/protoc-installation/).
Expand Down
10 changes: 10 additions & 0 deletions http2/go-grpc/app-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applications:
- name: go-grpc-test
buildpacks:
- go_buildpack
disk_quota: 32M
memory: 32M
routes:
- route: go-grpc-test.((domain))
protocol: http2
22 changes: 21 additions & 1 deletion http2/go-http2/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# HTTP/2 H2C Sample

Example HTTP/2 server implemented in Go
## Deploying the go app
### Deploy the app using the manifest file

Deploy the app
```shell
> export DOMAIN=my.cf.app.domain
> cf push -f app-manifest.yml --var domain=$DOMAIN
```

### Deploy the app without the manifest file
```shell
> cf push --no-route go-http2-test --buildpack go_buildpack
# my.cf.app.domain is used as an example for demonstration purpose
> cf map-route go-http2-test my.cf.app.domain --hostname go-http2-test --app-protocol http2
```

## Testing the Go app
```shell
> curl -v --http2-prior-knowledge https://go-http2-test.my.cf.app.domain
```

The app supports HTTP/1.1 and HTTP/2 H2C if requested explicitly, i.e. no connection upgrade.

## Running Locally
## Building and running on the local machine

1. `go build`
2. `PORT=8080 ./go-http2`
Expand Down
10 changes: 10 additions & 0 deletions http2/go-http2/app-manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applications:
- name: go-http2-test
buildpacks:
- go_buildpack
disk_quota: 32M
memory: 32M
routes:
- route: go-http2-test.((domain))
protocol: http2
1 change: 1 addition & 0 deletions http2/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 1.0.0
Binary file added http2/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit 5a3f231

Please sign in to comment.