diff --git a/.gitignore b/.gitignore index e34ee94..762b101 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ Pipfile Pipfile.lock .bundle **/ruby-*/vendor +.idea +.gradle +http2/.gradle diff --git a/README.md b/README.md index 2aa25dd..29403ee 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/http2/README.md b/http2/README.md index dc23f2d..ed9dffb 100644 --- a/http2/README.md +++ b/http2/README.md @@ -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 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://-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" } diff --git a/http2/apps-manifest.yml b/http2/apps-manifest.yml new file mode 100644 index 0000000..b610b4f --- /dev/null +++ b/http2/apps-manifest.yml @@ -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 diff --git a/http2/build.gradle b/http2/build.gradle new file mode 100644 index 0000000..4da6dbf --- /dev/null +++ b/http2/build.gradle @@ -0,0 +1,12 @@ +plugins { + id "org.cyclonedx.bom" version "1.6.1" +} + +allprojects { + repositories { + mavenCentral() + maven { + url "https://plugins.gradle.org/m2/" + } + } +} diff --git a/http2/go-grpc/README.md b/http2/go-grpc/README.md index 5253045..cd21b34 100644 --- a/http2/go-grpc/README.md +++ b/http2/go-grpc/README.md @@ -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/). diff --git a/http2/go-grpc/app-manifest.yml b/http2/go-grpc/app-manifest.yml new file mode 100644 index 0000000..23c233b --- /dev/null +++ b/http2/go-grpc/app-manifest.yml @@ -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 diff --git a/http2/go-http2/README.md b/http2/go-http2/README.md index 9201e3d..5eb0afd 100644 --- a/http2/go-http2/README.md +++ b/http2/go-http2/README.md @@ -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` diff --git a/http2/go-http2/app-manifest.yml b/http2/go-http2/app-manifest.yml new file mode 100644 index 0000000..d03c4a6 --- /dev/null +++ b/http2/go-http2/app-manifest.yml @@ -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 diff --git a/http2/gradle.properties b/http2/gradle.properties new file mode 100644 index 0000000..8f1bfe8 --- /dev/null +++ b/http2/gradle.properties @@ -0,0 +1 @@ +version: 1.0.0 \ No newline at end of file diff --git a/http2/gradle/wrapper/gradle-wrapper.jar b/http2/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..033e24c Binary files /dev/null and b/http2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/http2/gradle/wrapper/gradle-wrapper.properties b/http2/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9f4197d --- /dev/null +++ b/http2/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/http2/gradlew b/http2/gradlew new file mode 100755 index 0000000..fcb6fca --- /dev/null +++ b/http2/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/http2/gradlew.bat b/http2/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/http2/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/http2/java-grpc/.gitattributes b/http2/java-grpc/.gitattributes index 00a51af..097f9f9 100644 --- a/http2/java-grpc/.gitattributes +++ b/http2/java-grpc/.gitattributes @@ -1,6 +1,9 @@ # # https://help.github.com/articles/dealing-with-line-endings/ # -# These are explicitly windows files and should use crlf +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf *.bat text eol=crlf diff --git a/http2/java-grpc/README.md b/http2/java-grpc/README.md index d6ff935..d4aadfe 100644 --- a/http2/java-grpc/README.md +++ b/http2/java-grpc/README.md @@ -1,7 +1,30 @@ # Java gRPC Sample Example gRPC server implemented in Java -## Running Locally +## Deploying the Java app +### Pre-requisite for Java app +Please follow [the install setup for Java](../README.md#for-java-app-do-the-following) first before deploying this java 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 java-grpc-test --buildpack java_buildpack --path ./app/build/distributions/app.zip +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route java-grpc-test my.cf.app.domain --hostname java-grpc-test --app-protocol http2 +``` + +## Testing the Java app +`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl). +```shell +> grpcurl -proto app/src/main/proto/example.proto java-grpc-test.my.cf.app.domain:443 example.Example.Run +``` +## Building and running on the local machine 1. `./gradlew build` 2. `PORT=8080 ./gradlew run` diff --git a/http2/java-grpc/app-manifest.yml b/http2/java-grpc/app-manifest.yml new file mode 100644 index 0000000..ce80c27 --- /dev/null +++ b/http2/java-grpc/app-manifest.yml @@ -0,0 +1,13 @@ +--- +applications: + - name: java-grpc-test + disk_quota: 768M + memory: 768M + path: ./app/build/distributions/app.zip + buildpacks: + - java_buildpack + routes: + - route: java-grpc-test.((domain)) + protocol: http2 + env: + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ }}' \ No newline at end of file diff --git a/http2/java-grpc/app/src/main/java/java/grpc/App.java b/http2/java-grpc/app/src/main/java/java/grpc/App.java index 1ccd93d..074bddd 100644 --- a/http2/java-grpc/app/src/main/java/java/grpc/App.java +++ b/http2/java-grpc/app/src/main/java/java/grpc/App.java @@ -63,7 +63,7 @@ public static void main(String[] args) throws IOException, InterruptedException static class ExampleImpl extends ExampleGrpc.ExampleImplBase { @Override public void run(Request req, StreamObserver responseObserver) { - Response response = Response.newBuilder().setMessage("Hello! This Go application is speaking gRPC").build(); + Response response = Response.newBuilder().setMessage("Hello! This Java application is speaking gRPC").build(); responseObserver.onNext(response); responseObserver.onCompleted(); } diff --git a/http2/java-grpc/gradle/wrapper/gradle-wrapper.jar b/http2/java-grpc/gradle/wrapper/gradle-wrapper.jar index 7454180..033e24c 100644 Binary files a/http2/java-grpc/gradle/wrapper/gradle-wrapper.jar and b/http2/java-grpc/gradle/wrapper/gradle-wrapper.jar differ diff --git a/http2/java-grpc/gradle/wrapper/gradle-wrapper.properties b/http2/java-grpc/gradle/wrapper/gradle-wrapper.properties index 2e6e589..9f4197d 100644 --- a/http2/java-grpc/gradle/wrapper/gradle-wrapper.properties +++ b/http2/java-grpc/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/http2/java-grpc/gradlew b/http2/java-grpc/gradlew index 1b6c787..fcb6fca 100755 --- a/http2/java-grpc/gradlew +++ b/http2/java-grpc/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/http2/java-grpc/gradlew.bat b/http2/java-grpc/gradlew.bat index 107acd3..93e3f59 100644 --- a/http2/java-grpc/gradlew.bat +++ b/http2/java-grpc/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/http2/java-grpc/settings.gradle b/http2/java-grpc/settings.gradle index e3409c7..3b93d7c 100644 --- a/http2/java-grpc/settings.gradle +++ b/http2/java-grpc/settings.gradle @@ -9,3 +9,4 @@ rootProject.name = 'java-grpc' include('app') + diff --git a/http2/java-http2/README.md b/http2/java-http2/README.md index c2ef3f5..40fa835 100644 --- a/http2/java-http2/README.md +++ b/http2/java-http2/README.md @@ -1,10 +1,31 @@ # Java HTTP/2 H2C Sample Example HTTP/2 server implemented in Java +## Deploying the java app +### Pre-requisite for Java app +Please follow [the install setup for Java](../README.md#for-java-app-do-the-following) first before deploying this java 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 java-http2-test --buildpack java_buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route java-http2-test my.cf.app.domain --hostname java-http2-test --app-protocol http2 +``` + +## Testing the Java app +```shell +> curl -v --http2-prior-knowledge https://java-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. `./gradlew build` 2. `PORT=8080 ./gradlew run` diff --git a/http2/java-http2/app-manifest.yml b/http2/java-http2/app-manifest.yml new file mode 100644 index 0000000..b9867b3 --- /dev/null +++ b/http2/java-http2/app-manifest.yml @@ -0,0 +1,13 @@ +--- +applications: + - name: java-http2-test + disk_quota: 768M + memory: 768M + path: ./app/build/distributions/app.zip + buildpacks: + - java_buildpack + routes: + - route: java-http2-test.((domain)) + protocol: http2 + env: + JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ }}' diff --git a/http2/java-http2/gradle/wrapper/gradle-wrapper.jar b/http2/java-http2/gradle/wrapper/gradle-wrapper.jar index 7454180..033e24c 100644 Binary files a/http2/java-http2/gradle/wrapper/gradle-wrapper.jar and b/http2/java-http2/gradle/wrapper/gradle-wrapper.jar differ diff --git a/http2/java-http2/gradle/wrapper/gradle-wrapper.properties b/http2/java-http2/gradle/wrapper/gradle-wrapper.properties index 2e6e589..9f4197d 100644 --- a/http2/java-http2/gradle/wrapper/gradle-wrapper.properties +++ b/http2/java-http2/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/http2/java-http2/gradlew b/http2/java-http2/gradlew index 1b6c787..fcb6fca 100755 --- a/http2/java-http2/gradlew +++ b/http2/java-http2/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +130,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +213,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/http2/java-http2/gradlew.bat b/http2/java-http2/gradlew.bat index 107acd3..93e3f59 100644 --- a/http2/java-http2/gradlew.bat +++ b/http2/java-http2/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/http2/node-grpc/README.md b/http2/node-grpc/README.md index 3e43440..1212800 100644 --- a/http2/node-grpc/README.md +++ b/http2/node-grpc/README.md @@ -1,8 +1,27 @@ # Node.js gRPC Sample Example gRPC server implemented in Node.JS +## Deploying the Node 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 node-grpc-test --buildpack https://github.com/cloudfoundry/nodejs-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route node-grpc-test my.cf.app.domain --hostname node-grpc-test --app-protocol http2 +``` -## Running Locally +## Testing the Node app +`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl). +```shell +> grpcurl -proto example.proto node-grpc-test.my.cf.app.domain:443 Example.Run +``` + +## Building and running on the local machine 1. `npm install` 2. `PORT=8080 npm start` diff --git a/http2/node-grpc/app-manifest.yml b/http2/node-grpc/app-manifest.yml new file mode 100644 index 0000000..ef71063 --- /dev/null +++ b/http2/node-grpc/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: node-grpc-test + disk_quota: 256M + memory: 256M + buildpacks: + - https://github.com/cloudfoundry/nodejs-buildpack + routes: + - route: node-grpc-test.((domain)) + protocol: http2 diff --git a/http2/node-http2/README.md b/http2/node-http2/README.md index 466366d..ca86c03 100644 --- a/http2/node-http2/README.md +++ b/http2/node-http2/README.md @@ -1,10 +1,29 @@ # Node.JS HTTP/2 H2C Sample Example HTTP/2 server implemented in JavaScript / Node.js +## Deploying the Node 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 node-http2-test --buildpack https://github.com/cloudfoundry/nodejs-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route node-http2-test my.cf.app.domain --hostname node-http2-test --app-protocol http2 +``` + +## Testing the Node app +```shell +> curl -v --http2-prior-knowledge https://node-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. `npm install` 2. `PORT=8080 npm start` diff --git a/http2/node-http2/app-manifest.yml b/http2/node-http2/app-manifest.yml new file mode 100644 index 0000000..c917a44 --- /dev/null +++ b/http2/node-http2/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: node-http2-test + disk_quota: 256M + memory: 256M + buildpacks: + - https://github.com/cloudfoundry/nodejs-buildpack + routes: + - route: node-http2-test.((domain)) + protocol: http2 diff --git a/http2/python-grpc/README.md b/http2/python-grpc/README.md index ab78fc8..f93e834 100644 --- a/http2/python-grpc/README.md +++ b/http2/python-grpc/README.md @@ -1,8 +1,28 @@ # Python gRPC Sample Example gRPC server implemented in Python +## Deploying the Python 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 python-grpc-test --buildpack https://github.com/cloudfoundry/python-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route python-grpc-test my.cf.app.domain --hostname python-grpc-test --app-protocol http2 +``` + +## Testing the Python app +`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl). +```shell +> grpcurl -proto example.proto python-grpc-test.my.cf.app.domain:443 Example.Run +``` -## Running Locally +## Building and running on the local machine 1. `pipenv install -r requirements.txt` 2. `PORT=8080 pipenv run python3 main.py` 3. `grpcurl -proto example.proto -plaintext localhost:8080 Example.Run` diff --git a/http2/python-grpc/app-manifest.yml b/http2/python-grpc/app-manifest.yml new file mode 100644 index 0000000..403fe27 --- /dev/null +++ b/http2/python-grpc/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: python-grpc-test + disk_quota: 512M + memory: 512M + buildpacks: + - https://github.com/cloudfoundry/python-buildpack + routes: + - route: python-grpc-test.((domain)) + protocol: http2 diff --git a/http2/python-grpc/example_pb2.py b/http2/python-grpc/example_pb2.py index 8ee67b7..dc98aad 100644 --- a/http2/python-grpc/example_pb2.py +++ b/http2/python-grpc/example_pb2.py @@ -3,9 +3,9 @@ # source: example.proto """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -13,117 +13,18 @@ -DESCRIPTOR = _descriptor.FileDescriptor( - name='example.proto', - package='', - syntax='proto3', - serialized_options=None, - create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rexample.proto\"\t\n\x07Request\"\x1b\n\x08Response\x12\x0f\n\x07message\x18\x01 \x01(\t2\'\n\x07\x45xample\x12\x1c\n\x03Run\x12\x08.Request\x1a\t.Response\"\x00\x62\x06proto3' -) +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rexample.proto\"\t\n\x07Request\"\x1b\n\x08Response\x12\x0f\n\x07message\x18\x01 \x01(\t2\'\n\x07\x45xample\x12\x1c\n\x03Run\x12\x08.Request\x1a\t.Response\"\x00\x62\x06proto3') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'example_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: - - -_REQUEST = _descriptor.Descriptor( - name='Request', - full_name='Request', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=17, - serialized_end=26, -) - - -_RESPONSE = _descriptor.Descriptor( - name='Response', - full_name='Response', - filename=None, - file=DESCRIPTOR, - containing_type=None, - create_key=_descriptor._internal_create_key, - fields=[ - _descriptor.FieldDescriptor( - name='message', full_name='Response.message', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=b"".decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=28, - serialized_end=55, -) - -DESCRIPTOR.message_types_by_name['Request'] = _REQUEST -DESCRIPTOR.message_types_by_name['Response'] = _RESPONSE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Request = _reflection.GeneratedProtocolMessageType('Request', (_message.Message,), { - 'DESCRIPTOR' : _REQUEST, - '__module__' : 'example_pb2' - # @@protoc_insertion_point(class_scope:Request) - }) -_sym_db.RegisterMessage(Request) - -Response = _reflection.GeneratedProtocolMessageType('Response', (_message.Message,), { - 'DESCRIPTOR' : _RESPONSE, - '__module__' : 'example_pb2' - # @@protoc_insertion_point(class_scope:Response) - }) -_sym_db.RegisterMessage(Response) - - - -_EXAMPLE = _descriptor.ServiceDescriptor( - name='Example', - full_name='Example', - file=DESCRIPTOR, - index=0, - serialized_options=None, - create_key=_descriptor._internal_create_key, - serialized_start=57, - serialized_end=96, - methods=[ - _descriptor.MethodDescriptor( - name='Run', - full_name='Example.Run', - index=0, - containing_service=None, - input_type=_REQUEST, - output_type=_RESPONSE, - serialized_options=None, - create_key=_descriptor._internal_create_key, - ), -]) -_sym_db.RegisterServiceDescriptor(_EXAMPLE) - -DESCRIPTOR.services_by_name['Example'] = _EXAMPLE - + DESCRIPTOR._options = None + _globals['_REQUEST']._serialized_start=17 + _globals['_REQUEST']._serialized_end=26 + _globals['_RESPONSE']._serialized_start=28 + _globals['_RESPONSE']._serialized_end=55 + _globals['_EXAMPLE']._serialized_start=57 + _globals['_EXAMPLE']._serialized_end=96 # @@protoc_insertion_point(module_scope) diff --git a/http2/python-grpc/requirements.txt b/http2/python-grpc/requirements.txt index a8cb2f5..ccef780 100644 --- a/http2/python-grpc/requirements.txt +++ b/http2/python-grpc/requirements.txt @@ -1,2 +1,2 @@ -grpcio-reflection==1.43.0 -grpcio==1.53.0 +grpcio-reflection==1.56.2 +grpcio==1.56.2 diff --git a/http2/python-grpc/runtime.txt b/http2/python-grpc/runtime.txt new file mode 100644 index 0000000..431fc7e --- /dev/null +++ b/http2/python-grpc/runtime.txt @@ -0,0 +1 @@ +python-3.11.4 diff --git a/http2/python-http2/README.md b/http2/python-http2/README.md index 6d849be..5082e59 100644 --- a/http2/python-http2/README.md +++ b/http2/python-http2/README.md @@ -1,10 +1,29 @@ # Python HTTP/2 H2C Sample Example HTTP/2 server implemented in Python +## Deploying the python 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 python-http2-test --buildpack https://github.com/cloudfoundry/python-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route python-http2-test my.cf.app.domain --hostname python-http2-test --app-protocol http2 +``` + +## Testing the Python app +```shell +> curl -v --http2-prior-knowledge https://python-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. `pipenv install -r requirements.txt` 2. `PORT=8080 pipenv run python3 main.py` diff --git a/http2/python-http2/app-manifest.yml b/http2/python-http2/app-manifest.yml new file mode 100644 index 0000000..6ce60dd --- /dev/null +++ b/http2/python-http2/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: python-http2-test + disk_quota: 512M + memory: 512M + buildpacks: + - https://github.com/cloudfoundry/python-buildpack + routes: + - route: python-http2-test.((domain)) + protocol: http2 diff --git a/http2/python-http2/requirements.txt b/http2/python-http2/requirements.txt index 5201d9c..85edb71 100644 --- a/http2/python-http2/requirements.txt +++ b/http2/python-http2/requirements.txt @@ -1 +1 @@ -hyper==0.7.0 +h2==4.1.0 diff --git a/http2/python-http2/runtime.txt b/http2/python-http2/runtime.txt new file mode 100644 index 0000000..431fc7e --- /dev/null +++ b/http2/python-http2/runtime.txt @@ -0,0 +1 @@ +python-3.11.4 diff --git a/http2/ruby-grpc/README.md b/http2/ruby-grpc/README.md index eafe2d5..e32bb8c 100644 --- a/http2/ruby-grpc/README.md +++ b/http2/ruby-grpc/README.md @@ -1,8 +1,28 @@ # Ruby gRPC Sample Example gRPC server implemented in Ruby +## Deploying the Ruby 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 ruby-grpc-test --buildpack https://github.com/cloudfoundry/ruby-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route ruby-grpc-test my.cf.app.domain --hostname ruby-grpc-test --app-protocol http2 +``` + +## Testing the Ruby app +`grpcurl` needs to be [installed separately](https://github.com/fullstorydev/grpcurl). +```shell +> grpcurl -proto example.proto ruby-grpc-test.my.cf.app.domain:443 Example.Run +``` -## Running Locally +## Building and running on the local machine 1. `bundle install --path vendor/bundle` 2. `PORT=8080 bundle exec ruby server.rb` 3. `grpcurl -proto example.proto -plaintext localhost:8080 Example.Run` diff --git a/http2/ruby-grpc/app-manifest.yml b/http2/ruby-grpc/app-manifest.yml new file mode 100644 index 0000000..ab68556 --- /dev/null +++ b/http2/ruby-grpc/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: ruby-grpc-test + disk_quota: 256M + memory: 256M + buildpacks: + - https://github.com/cloudfoundry/ruby-buildpack + routes: + - route: ruby-grpc-test.((domain)) + protocol: http2 diff --git a/http2/ruby-http2/README.md b/http2/ruby-http2/README.md index 31d5bd6..7eed30b 100644 --- a/http2/ruby-http2/README.md +++ b/http2/ruby-http2/README.md @@ -1,10 +1,29 @@ # Python HTTP/2 H2C Sample Example HTTP/2 server implemented in Python +## Deploying the ruby 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 ruby-http2-test --buildpack https://github.com/cloudfoundry/ruby-buildpack +# my.cf.app.domain is used as an example for demonstration purpose +> cf map-route ruby-http2-test my.cf.app.domain --hostname ruby-http2-test --app-protocol http2 +``` + +## Testing the Ruby app +```shell +> curl -v --http2-prior-knowledge https://ruby-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. `bundle install --path vendor/bundle` 2. `PORT=8080 bundle exec ruby server.rb` diff --git a/http2/ruby-http2/app-manifest.yml b/http2/ruby-http2/app-manifest.yml new file mode 100644 index 0000000..bd957e8 --- /dev/null +++ b/http2/ruby-http2/app-manifest.yml @@ -0,0 +1,10 @@ +--- +applications: + - name: ruby-http2-test + disk_quota: 256M + memory: 256M + buildpacks: + - https://github.com/cloudfoundry/ruby-buildpack + routes: + - route: ruby-http2-test.((domain)) + protocol: http2 diff --git a/http2/settings.gradle b/http2/settings.gradle new file mode 100644 index 0000000..d18aed2 --- /dev/null +++ b/http2/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'sample-apps-composite' + +include('java-grpc:app') +include('java-http2:app') \ No newline at end of file diff --git a/http2/vars.yml b/http2/vars.yml new file mode 100644 index 0000000..2d25844 --- /dev/null +++ b/http2/vars.yml @@ -0,0 +1,2 @@ +domain: +