├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── build ├── deprecated │ ├── build-helloworld-docker.yaml │ ├── build-helloworld-gcr.yaml │ ├── buildtemplate-buildpack-sample-java-app-gcr.yaml │ ├── buildtemplate-kaniko-helloworld-gcr.yaml │ └── docker-secret.yaml ├── docker-secret.yaml ├── service-account.yaml ├── task-build-docker-images-from-git-source.yaml ├── task-helloworld.yaml ├── taskrun-build-helloworld-docker.yaml ├── taskrun-build-helloworld-gcr.yaml ├── taskrun-build-kaniko-helloworld-gcr.yaml └── taskrun-helloworld.yaml ├── docs ├── bigquery-processing-pipeline.md ├── brokercreation.md ├── brokertrigger.md ├── changeconfig.md ├── clusterlocal.md ├── complexdelivery.md ├── complexdeliverywithreply.md ├── configureautoscaling.md ├── deprecated │ ├── buildpacksbuildtemplate.md │ ├── dockerbuild.md │ ├── helloworldbuild.md │ └── kanikobuildtemplate.md ├── eventregistry.md ├── grpc-csharp.md ├── grpc-python.md ├── grpc.md ├── hellotekton.md ├── helloworldeventing-csharp.md ├── helloworldeventing-python.md ├── helloworldeventing.md ├── helloworldserving.md ├── image-processing-pipeline.md ├── images │ ├── bigquery-processing-pipeline.png │ ├── broker-trigger-delivery.png │ ├── cloud-run-console.png │ ├── cloud-run.png │ ├── complex-delivery-reply.png │ ├── complex-delivery.png │ ├── dockerhub-auto.png │ ├── dockerhub.png │ ├── gcr-javaapp.png │ ├── gcr.png │ ├── grpc.png │ ├── image-processing-pipeline.png │ ├── serverless-on-google-cloud.png │ ├── serverless-with-knative-cloudrun.png │ ├── simple-delivery.png │ ├── twilio-webhook-custom.png │ └── twilio-webhook.png ├── pubsubeventing.md ├── scheduledeventing.md ├── simpledelivery.md ├── storageeventing.md ├── tekton-dockerbuild.md ├── tekton-gcrbuild.md ├── trafficsplitting.md ├── translationeventing-csharp.md ├── translationeventing-python.md ├── translationeventing.md ├── twiliointegration-csharp.md ├── twiliointegration-python.md ├── twiliointegration.md ├── visioneventing-csharp.md ├── visioneventing-python.md └── visioneventing.md ├── eventing ├── brokertrigger │ ├── service1.yaml │ ├── service2.yaml │ ├── service3.yaml │ ├── source.yaml │ ├── trigger1.yaml │ ├── trigger2.yaml │ └── trigger3.yaml ├── complex │ ├── channel.yaml │ ├── service1.yaml │ ├── service2.yaml │ ├── source.yaml │ ├── subscription1.yaml │ └── subscription2.yaml ├── complexwithreply │ ├── channel1.yaml │ ├── channel2.yaml │ ├── service1.yaml │ ├── service2.yaml │ ├── service3.yaml │ ├── source.yaml │ ├── subscription1.yaml │ ├── subscription2.yaml │ └── subscription3.yaml ├── event-display-with-reply │ └── csharp │ │ ├── Dockerfile │ │ ├── Program.cs │ │ ├── Properties │ │ └── launchSettings.json │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── event-display-with-reply.csproj ├── event-display │ ├── csharp │ │ ├── Dockerfile │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── event-display.csproj │ └── python │ │ ├── Dockerfile │ │ └── app.py ├── helloworld │ ├── curl-pod.yaml │ ├── kservice.yaml │ ├── service.yaml │ └── trigger.yaml ├── pictures │ ├── atamel.jpg │ ├── beach.jpg │ ├── bodrum.jpg │ ├── paris.jpg │ ├── river.jpg │ └── yachtclub.jpg ├── ping │ ├── source-broker.yaml │ ├── source.yaml │ └── trigger.yaml ├── pubsub │ ├── cloudpubsubsource-workload.yaml │ ├── cloudpubsubsource.yaml │ ├── kservice.yaml │ ├── service.yaml │ └── trigger.yaml ├── simple │ ├── service.yaml │ └── source.yaml ├── storage │ ├── cloudstoragesource.yaml │ ├── kservice.yaml │ ├── service.yaml │ └── trigger.yaml ├── translation │ ├── csharp │ │ ├── Dockerfile │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Startup.cs │ │ ├── TranslationRequest.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── translation.csproj │ ├── kservice.yaml │ ├── python │ │ ├── Dockerfile │ │ └── app.py │ ├── service.yaml │ └── trigger.yaml └── vision │ ├── csharp │ ├── Dockerfile │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── vision.csproj │ ├── kservice.yaml │ ├── python │ ├── Dockerfile │ └── app.py │ ├── service.yaml │ └── trigger.yaml ├── serving ├── grpc │ ├── csharp │ │ ├── GrpcGreeter │ │ │ ├── Dockerfile │ │ │ ├── GrpcGreeter.csproj │ │ │ ├── Program.cs │ │ │ ├── Properties │ │ │ │ └── launchSettings.json │ │ │ ├── Protos │ │ │ │ └── greet.proto │ │ │ ├── Services │ │ │ │ └── GreeterService.cs │ │ │ ├── Startup.cs │ │ │ ├── appsettings.Development.json │ │ │ └── appsettings.json │ │ └── GrpcGreeterClient │ │ │ ├── GrpcGreeterClient.csproj │ │ │ ├── Program.cs │ │ │ └── Protos │ │ │ └── greet.proto │ ├── python │ │ ├── Dockerfile │ │ ├── greet_client.py │ │ ├── greet_pb2.py │ │ ├── greet_pb2_grpc.py │ │ ├── greet_server.py │ │ └── protos │ │ │ └── greet.proto │ └── service.yaml ├── helloworld │ ├── csharp │ │ ├── Dockerfile │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── helloworld.csproj │ ├── python │ │ ├── Dockerfile │ │ └── app.py │ ├── service-local.yaml │ ├── service-v1-pinned.yaml │ ├── service-v1.yaml │ ├── service-v1v4-split.yaml │ ├── service-v2.yaml │ ├── service-v3.yaml │ └── service-v4.yaml ├── sleepingservice │ ├── csharp │ │ ├── Dockerfile │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── launchSettings.json │ │ ├── Startup.cs │ │ ├── appsettings.Development.json │ │ ├── appsettings.json │ │ └── sleepingservice.csproj │ ├── python │ │ ├── Dockerfile │ │ └── app.py │ └── service.yaml └── twilio │ ├── csharp │ ├── Dockerfile │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── SmsController.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── twiliosample.csproj │ ├── python │ ├── Dockerfile │ └── app.py │ └── service.yaml └── setup ├── README.md ├── check-versions ├── config ├── configure-https ├── create-gke-cluster ├── install-dataplane-serviceaccount ├── install-eventing ├── install-knative-gcp ├── install-serving └── install-tekton /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows 28 | [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). 29 | -------------------------------------------------------------------------------- /build/deprecated/build-helloworld-docker.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: build.knative.dev/v1alpha1 15 | kind: Build 16 | metadata: 17 | name: build-helloworld-docker 18 | spec: 19 | serviceAccountName: build-bot 20 | source: 21 | git: 22 | url: https://github.com/meteatamel/knative-tutorial.git 23 | revision: master 24 | subPath: serving/helloworld/csharp 25 | steps: 26 | - name: build-and-push 27 | image: "gcr.io/kaniko-project/executor:v0.6.0" 28 | args: 29 | - "--dockerfile=/workspace/Dockerfile" 30 | # Replace {username} with your actual DockerHub 31 | - "--destination=docker.io/{username}/helloworld:build" -------------------------------------------------------------------------------- /build/deprecated/build-helloworld-gcr.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: build.knative.dev/v1alpha1 15 | kind: Build 16 | metadata: 17 | name: build-helloworld-gcr 18 | spec: 19 | source: 20 | git: 21 | url: https://github.com/meteatamel/knative-tutorial.git 22 | revision: master 23 | subPath: serving/helloworld/csharp 24 | steps: 25 | - name: build-and-push 26 | image: "gcr.io/kaniko-project/executor:v0.6.0" 27 | args: 28 | - "--dockerfile=/workspace/Dockerfile" 29 | # Replace {PROJECT_ID} with your GCP Project's ID. 30 | - "--destination=gcr.io/{PROJECT_ID}/helloworld:build" -------------------------------------------------------------------------------- /build/deprecated/buildtemplate-buildpack-sample-java-app-gcr.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: build.knative.dev/v1alpha1 15 | kind: Build 16 | metadata: 17 | name: buildtemplate-buildpack-sample-java-app-gcr 18 | spec: 19 | source: 20 | git: 21 | url: https://github.com/buildpack/sample-java-app.git 22 | revision: master 23 | template: 24 | name: buildpacks-cnb 25 | arguments: 26 | - name: IMAGE 27 | # Replace {PROJECT_ID} with your GCP Project's ID. 28 | value: gcr.io/{PROJECT_ID}/sample-java-app:buildpack -------------------------------------------------------------------------------- /build/deprecated/buildtemplate-kaniko-helloworld-gcr.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: build.knative.dev/v1alpha1 15 | kind: Build 16 | metadata: 17 | name: buildtemplate-kaniko-helloworld-gcr 18 | spec: 19 | source: 20 | git: 21 | url: https://github.com/meteatamel/knative-tutorial.git 22 | revision: master 23 | subPath: serving/helloworld/csharp 24 | template: 25 | name: kaniko 26 | arguments: 27 | - name: IMAGE 28 | # Replace {PROJECT_ID} with your GCP Project's ID. 29 | value: gcr.io/{PROJECT_ID}/helloworld:kaniko -------------------------------------------------------------------------------- /build/deprecated/docker-secret.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: v1 15 | kind: Secret 16 | metadata: 17 | name: basic-user-pass 18 | annotations: 19 | build.knative.dev/docker-0: https://index.docker.io/v1/ 20 | type: kubernetes.io/basic-auth 21 | data: 22 | # Use 'echo -n "username" | base64' to generate this string 23 | username: dXNlcm5hbWU= 24 | # Use 'echo -n "password" | base64' to generate this string 25 | password: cGFzc3dvcmQ= -------------------------------------------------------------------------------- /build/docker-secret.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: v1 15 | kind: Secret 16 | metadata: 17 | name: basic-user-pass 18 | annotations: 19 | tekton.dev/docker-0: https://index.docker.io/v1/ 20 | type: kubernetes.io/basic-auth 21 | data: 22 | # Use 'echo -n "username" | base64' to generate this string 23 | username: dXNlcm5hbWU= 24 | # Use 'echo -n "password" | base64' to generate this string 25 | password: cGFzc3dvcmQ= -------------------------------------------------------------------------------- /build/service-account.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: v1 15 | kind: ServiceAccount 16 | metadata: 17 | name: build-bot 18 | secrets: 19 | - name: basic-user-pass -------------------------------------------------------------------------------- /build/task-build-docker-images-from-git-source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1beta1 15 | kind: Task 16 | metadata: 17 | name: build-docker-image-from-git-source 18 | spec: 19 | params: 20 | - name: pathToDockerFile 21 | type: string 22 | description: The path to the dockerfile to build 23 | default: $(resources.inputs.docker-source.path)/Dockerfile 24 | - name: pathToContext 25 | type: string 26 | description: | 27 | The build context used by Kaniko 28 | (https://github.com/GoogleContainerTools/kaniko#kaniko-build-contexts) 29 | default: $(resources.inputs.docker-source.path) 30 | resources: 31 | inputs: 32 | - name: docker-source 33 | type: git 34 | outputs: 35 | - name: builtImage 36 | type: image 37 | steps: 38 | - name: build-and-push 39 | image: gcr.io/kaniko-project/executor:v0.16.0 40 | # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential 41 | env: 42 | - name: "DOCKER_CONFIG" 43 | value: "/tekton/home/.docker/" 44 | command: 45 | - /kaniko/executor 46 | args: 47 | - --dockerfile=$(params.pathToDockerFile) 48 | - --destination=$(resources.outputs.builtImage.url) 49 | - --context=$(params.pathToContext) -------------------------------------------------------------------------------- /build/task-helloworld.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1beta1 15 | kind: Task 16 | metadata: 17 | name: echo-hello-world 18 | spec: 19 | steps: 20 | - name: echo 21 | image: ubuntu 22 | command: 23 | - echo 24 | args: 25 | - "Hello World" -------------------------------------------------------------------------------- /build/taskrun-build-helloworld-docker.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1alpha1 15 | kind: PipelineResource 16 | metadata: 17 | name: git-knative-tutorial 18 | spec: 19 | type: git 20 | params: 21 | - name: revision 22 | value: master 23 | - name: url 24 | # Point to your repo 25 | value: https://github.com/meteatamel/knative-tutorial 26 | --- 27 | apiVersion: tekton.dev/v1alpha1 28 | kind: PipelineResource 29 | metadata: 30 | name: image-docker-knative-tutorial 31 | spec: 32 | type: image 33 | params: 34 | - name: url 35 | # Replace meteatamel with your Docker ID 36 | value: docker.io/meteatamel/helloworld:tekton 37 | --- 38 | apiVersion: tekton.dev/v1beta1 39 | kind: TaskRun 40 | metadata: 41 | name: build-helloworld-docker 42 | spec: 43 | serviceAccountName: build-bot 44 | taskRef: 45 | name: build-docker-image-from-git-source 46 | params: 47 | - name: pathToDockerFile 48 | value: Dockerfile 49 | - name: pathToContext 50 | value: $(resources.inputs.docker-source.path)/serving/helloworld/csharp 51 | resources: 52 | inputs: 53 | - name: docker-source 54 | resourceRef: 55 | name: git-knative-tutorial 56 | outputs: 57 | - name: builtImage 58 | resourceRef: 59 | name: image-docker-knative-tutorial -------------------------------------------------------------------------------- /build/taskrun-build-helloworld-gcr.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1alpha1 15 | kind: PipelineResource 16 | metadata: 17 | name: git-knative-tutorial 18 | spec: 19 | type: git 20 | params: 21 | - name: revision 22 | value: master 23 | - name: url 24 | # Point to your repo 25 | value: https://github.com/meteatamel/knative-tutorial 26 | --- 27 | apiVersion: tekton.dev/v1alpha1 28 | kind: PipelineResource 29 | metadata: 30 | name: image-gcr-knative-tutorial 31 | spec: 32 | type: image 33 | params: 34 | - name: url 35 | # Replace knative-atamel with your GCP Project's ID. 36 | value: gcr.io/knative-atamel/helloworld:tekton 37 | --- 38 | apiVersion: tekton.dev/v1beta1 39 | kind: TaskRun 40 | metadata: 41 | name: build-helloworld-gcr 42 | spec: 43 | taskRef: 44 | name: build-docker-image-from-git-source 45 | params: 46 | - name: pathToDockerFile 47 | value: Dockerfile 48 | - name: pathToContext 49 | value: $(resources.inputs.docker-source.path)/serving/helloworld/csharp 50 | resources: 51 | inputs: 52 | - name: docker-source 53 | resourceRef: 54 | name: git-knative-tutorial 55 | outputs: 56 | - name: builtImage 57 | resourceRef: 58 | name: image-gcr-knative-tutorial -------------------------------------------------------------------------------- /build/taskrun-build-kaniko-helloworld-gcr.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1alpha1 15 | kind: TaskRun 16 | metadata: 17 | name: build-kaniko-helloworld-gcr 18 | spec: 19 | taskRef: 20 | name: kaniko 21 | inputs: 22 | resources: 23 | - name: source 24 | resourceSpec: 25 | type: git 26 | params: 27 | - name: url 28 | value: https://github.com/meteatamel/knative-tutorial 29 | params: 30 | - name: DOCKERFILE 31 | value: Dockerfile 32 | - name: CONTEXT 33 | value: serving/helloworld/csharp 34 | outputs: 35 | resources: 36 | - name: image 37 | resourceSpec: 38 | type: image 39 | params: 40 | - name: url 41 | value: gcr.io/knative-atamel/helloworld:kaniko-tekton -------------------------------------------------------------------------------- /build/taskrun-helloworld.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: tekton.dev/v1beta1 15 | kind: TaskRun 16 | metadata: 17 | name: echo-hello-world-task-run 18 | spec: 19 | taskRef: 20 | name: echo-hello-world -------------------------------------------------------------------------------- /docs/brokercreation.md: -------------------------------------------------------------------------------- 1 | # Broker Creation 2 | 3 | You can create Broker in the namespace in 2 ways: 4 | 5 | 1. Automatically by labelling the namespace. 6 | 2. Manually. 7 | 8 | ## Automatically 9 | 10 | Broker can be injected into a namespace by labelling it with 11 | `eventing.knative.dev/injection=enabled` but this requires 12 | Sugar Controller to be installed. 13 | 14 | If you installed Knative Eventing with 15 | instructions in [setup](setup), you have Sugar Controller installed: 16 | 17 | ```sh 18 | kubectl get pods -n knative-eventing 19 | 20 | sugar-controller-55c4fb657b-jrh52 1/1 Running 21 | ``` 22 | 23 | Create a Broker in the default namespace by labelling the namespace: 24 | 25 | ```sh 26 | kubectl label ns default eventing.knative.dev/injection=enabled 27 | ``` 28 | 29 | ## Manual 30 | 31 | Create a Broker in the default namespace: 32 | 33 | ```sh 34 | kubectl create -f - < 27 | 28 | Event Display received event: {"message":"Hello world from ping!"} 29 | ``` 30 | 31 | ## Broker 32 | 33 | Make sure there's a Broker in the default namespace by following instructions in 34 | [Broker Creation](brokercreation.md) page. 35 | 36 | ## Event source - Broker sink 37 | 38 | Next, setup `PingSource` to point to our Broker instead. 39 | 40 | Create a [source-broker.yaml](../eventing/ping/source-broker.yaml). 41 | 42 | In this case, we have the Broker in the default namespace as the sink. 43 | 44 | Create the event source: 45 | 46 | ```bash 47 | kubectl apply -f source-broker.yaml 48 | ``` 49 | 50 | You need to create a [trigger.yaml](../eventing/ping/trigger.yaml) to listen for events. 51 | 52 | Notice that we're filtering on Ping events. 53 | 54 | ```bash 55 | kubectl apply -f trigger.yaml 56 | ``` 57 | 58 | At this point, you should see scheduled events in the Event Display. 59 | -------------------------------------------------------------------------------- /docs/simpledelivery.md: -------------------------------------------------------------------------------- 1 | # Simple Delivery 2 | 3 | In Knative Eventing, you typically use Broker and Trigger to receive and filter messages. However, there are other simpler and more complex delivery models. 4 | 5 | Let's take a look at the simple delivery scenario where an Event Source sends messages directly to a Service: 6 | 7 | ![Simple Delivery](./images/simple-delivery.png) 8 | 9 | ## Service 10 | 11 | First, create the Knative Service that will be the target of our event. 12 | 13 | Define [service.yaml](../eventing/simple/service.yaml). 14 | 15 | It's a Knative Service that simply logs out received messages. 16 | 17 | Create the service: 18 | 19 | ```bash 20 | kubectl apply -f service.yaml 21 | ``` 22 | 23 | ## Source 24 | 25 | Knative supports a number of [Event Sources](https://knative.dev/docs/eventing/sources) to read all sorts of events in Knative. 26 | 27 | For this example, let's use Ping Source, an in-memory Event Source that fires events based on given cron schedule: 28 | 29 | Define [source.yaml](../eventing/simple/source.yaml): 30 | 31 | It sends a message every minute to an event sink, which is a Knative Service in this case. 32 | 33 | Create the source: 34 | 35 | ```bash 36 | kubectl apply -f source.yaml 37 | ``` 38 | 39 | ## Verify 40 | 41 | Check the running pods: 42 | 43 | ```bash 44 | kubectl get pods 45 | 46 | NAME READY STATUS RESTARTS AGE 47 | cronjobsource-source-3c465b71-4bbe-4611-a816-a73a75cf8681-66ps5 1/1 Running 0 2m54s 48 | service-x25xg-deployment-55f957448-rtljx 2/2 Running 0 2m57s 49 | ``` 50 | 51 | Check the logs of the service. You should see messages from the CronJobSource: 52 | 53 | ```bash 54 | kubectl logs service-x25xg-deployment-55f957448-rtljx -c user-container 55 | 56 | info: event_display.Startup[0] 57 | Event Display received event: {"message":"Hello world from cron!"} 58 | ``` 59 | -------------------------------------------------------------------------------- /docs/tekton-dockerbuild.md: -------------------------------------------------------------------------------- 1 | # Docker Hub Build 2 | 3 | In the [previous lab](tekton-helloworldbuild.md), we built and pushed a container image to Google Cloud Registry (GCR). In this lab, we will push to Docker Hub instead. It's more involved as we need to register secrets for Docker Hub. 4 | 5 | ## Register secrets for Docker Hub 6 | 7 | We need to first register a secret in Kubernetes for authentication with Docker Hub. 8 | 9 | Create a [docker-secret.yaml](../build/docker-secret.yaml) file for `Secret` manifest, which is used to store your Docker Hub credentials. 10 | 11 | Make sure to replace `BASE64_ENCODED_USERNAME` and `BASE64_ENCODED_PASSWORD` with your Base64 encoded DockerHub username and password. 12 | 13 | Create a [service-account.yaml](../build/service-account.yaml) for `Service Account` used to link the build process to the secret. 14 | 15 | Apply the `Secret` and `Service Account`: 16 | 17 | ```bash 18 | kubectl apply -f docker-secret.yaml 19 | kubectl apply -f service-account.yaml 20 | ``` 21 | 22 | ## Design the TaskRun 23 | 24 | Create a [taskrun-build-helloworld-docker.yaml](../build/taskrun-build-helloworld-docker.yaml) file. 25 | 26 | This is very similar to before, except we're using `build-bot` as `serviceAccountName` to authenticate with DockerHub. 27 | 28 | ## Run and watch the TaskRun 29 | 30 | You can start the build with: 31 | 32 | ```bash 33 | kubectl apply -f taskrun-build-helloworld-docker.yaml 34 | 35 | pipelineresource.tekton.dev/git-knative-tutorial unchanged 36 | pipelineresource.tekton.dev/image-docker-knative-tutorial created 37 | taskrun.tekton.dev/build-helloworld-docker created 38 | ``` 39 | 40 | Check that all the Tekton artifacts are created: 41 | 42 | ```bash 43 | kubectl get tekton-pipelines 44 | ``` 45 | 46 | Soon after, you'll see a pod created for the build: 47 | 48 | ```bash 49 | kubectl get pods 50 | 51 | NAME READY STATUS 52 | build-helloworld-docker-pod-a1d405 0/4 Init:2/3 53 | ``` 54 | 55 | You can see the progress of the build with: 56 | 57 | ```bash 58 | kubectl logs --follow --container=step-build-and-push 59 | ``` 60 | 61 | When the build is finished, you'll see the pod in `Completed` state: 62 | 63 | ```bash 64 | kubectl get pods 65 | 66 | NAME READY STATUS 67 | build-helloworld-docker-pod-a1d405 0/4 Completed 68 | ``` 69 | 70 | At this point, you should see the image pushed to Docker Hub: 71 | 72 | ![Docker Hub](./images/dockerhub.png) -------------------------------------------------------------------------------- /docs/tekton-gcrbuild.md: -------------------------------------------------------------------------------- 1 | # Google Container Registry Build 2 | 3 | In this step, let's utilize Tekton Pipelines to build containers and push to Google Container Registry (GCR). 4 | 5 | ## Design the Task 6 | 7 | [Kaniko](https://github.com/GoogleContainerTools/kaniko) is a tool to build container images from a Dockerfile, inside a container in Kubernetes cluster. The advantage is that Kaniko doesn't depend on a Docker daemon. Let's create a generic Task to use Kaniko. 8 | 9 | Take a look at [task-build-docker-images-from-git-source.yaml](../build/task-build-docker-images-from-git-source.yaml) file. 10 | 11 | This defines a generic Task to use Kaniko to build and push the image. 12 | 13 | Create the task: 14 | 15 | ```bash 16 | kubectl apply -f task-build-docker-images-from-git-source.yaml 17 | 18 | task.tekton.dev/build-docker-image-from-git-source created 19 | ``` 20 | 21 | ## Design the TaskRun 22 | 23 | Next, let's define a TaskRun to run the Task. 24 | 25 | Take a look at [taskrun-build-helloworld-gcr.yaml](../build/taskrun-build-helloworld-gcr.yaml) file. 26 | This TaskRun defines the source code to build, the location of the image to push to and it refers to the 27 | Task we defined previously. 28 | 29 | ## Run and watch the TaskRun 30 | 31 | You can start the TaskRun with: 32 | 33 | ```bash 34 | kubectl apply -f taskrun-build-helloworld-gcr.yaml 35 | 36 | pipelineresource.tekton.dev/git-knative-tutorial unchanged 37 | pipelineresource.tekton.dev/image-docker-knative-tutorial created 38 | taskrun.tekton.dev/build-helloworld-docker created 39 | ``` 40 | 41 | Check that all the Tekton artifacts are created: 42 | 43 | ```bash 44 | kubectl get tekton-pipelines 45 | 46 | NAME AGE 47 | pipelineresource.tekton.dev/git-knative-tutorial 12m 48 | pipelineresource.tekton.dev/image-docker-knative-tutorial 22s 49 | pipelineresource.tekton.dev/image-gcr-knative-tutorial 12m 50 | 51 | NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME 52 | taskrun.tekton.dev/build-helloworld-gcr True Succeeded 12m 10m 53 | 54 | NAME AGE 55 | task.tekton.dev/build-docker-image-from-git-source 13m 56 | ``` 57 | 58 | Soon after, you'll see a pod created for the build: 59 | 60 | ```bash 61 | kubectl get pods 62 | 63 | NAME READY STATUS RESTARTS AGE 64 | build-helloworld-docker-pod-a1d405 2/4 Running 0 61s 65 | ``` 66 | 67 | You can see the progress of the build with: 68 | 69 | ```bash 70 | kubectl logs --follow --container=step-build-and-push 71 | ``` 72 | 73 | When the build is finished, you'll see the pod in `Completed` state: 74 | 75 | ```bash 76 | kubectl get pods 77 | 78 | NAME READY STATUS 79 | build-helloworld-gcr-pod-3ed981 0/4 Completed 80 | ``` 81 | 82 | At this point, you should see the image pushed to GCR: 83 | 84 | ![Google Container Registry](./images/gcr.png) 85 | -------------------------------------------------------------------------------- /docs/translationeventing-csharp.md: -------------------------------------------------------------------------------- 1 | # Create Translation Handler - C# 2 | 3 | ## Create Translation Handler 4 | 5 | Let's start with creating an empty ASP.NET Core app: 6 | 7 | ```bash 8 | dotnet new web -o translation 9 | ``` 10 | 11 | Inside the `translation/csharp` folder, update [Startup.cs](../eventing/translation/csharp/Startup.cs) to match with what we have. 12 | 13 | Change the log level in `appsettings.json` to `Information`: 14 | 15 | ```json 16 | { 17 | "Logging": { 18 | "LogLevel": { 19 | "Default": "Information" 20 | } 21 | }, 22 | "AllowedHosts": "*" 23 | } 24 | ``` 25 | 26 | ## Handle translation protocol 27 | 28 | To encapsulate translation protocol, create a [TranslationRequest.cs](../eventing/translation/csharp/TranslationRequest.cs) class. 29 | 30 | ## Add Translation API 31 | 32 | Add Translation API NuGet package to our project: 33 | 34 | ```bash 35 | dotnet add package Google.Cloud.Translation.V2 36 | ``` 37 | 38 | [Startup.cs](../eventing/translation/csharp/Startup.cs) extracts `TranslationRequest` out of the request. 39 | 40 | ```csharp 41 | var translationRequest = JsonConvert.DeserializeObject(decodedData); 42 | ``` 43 | 44 | Once we have the translation request, we pass that to Translation API: 45 | 46 | ```csharp 47 | _logger.LogInformation("Calling Translation API"); 48 | 49 | var response = await TranslateText(translationRequest); 50 | _logger.LogInformation($"Translated text: {response.TranslatedText}"); 51 | if (response.DetectedSourceLanguage != null) 52 | { 53 | _logger.LogInformation($"Detected language: {response.DetectedSourceLanguage}"); 54 | } 55 | await context.Response.WriteAsync(response.TranslatedText); 56 | ``` 57 | 58 | You can see the full code in [Startup.cs](../eventing/translation/csharp/Startup.cs). 59 | 60 | Before building the Docker image, make sure the app has no compilation errors: 61 | 62 | ```bash 63 | dotnet build 64 | ``` 65 | 66 | ## Create Dockerfile 67 | 68 | Create a [Dockerfile](../eventing/translation/csharp/Dockerfile) for the image. 69 | 70 | ## What's Next? 71 | 72 | Back to [Integrate with Translation API](translationeventing.md) -------------------------------------------------------------------------------- /docs/translationeventing-python.md: -------------------------------------------------------------------------------- 1 | # Create Translation Handler - Python 2 | 3 | ## Create Translation Handler 4 | 5 | Adapt the previous message dumper sample by creating a new [app.py](../eventing/translation/python/app.py): 6 | 7 | ```python 8 | from flask import Flask, request 9 | ... 10 | 11 | @app.route('/', methods=['POST']) 12 | def pubsub_push(): 13 | translation_request = get_translation_request() 14 | translate_text(translation_request) 15 | return 'OK', 200 16 | 17 | 18 | def get_translation_request(): 19 | message = json.loads(request.data.decode('utf-8')) 20 | data = base64.b64decode(message['Data']) 21 | translation_request = json.loads(data) 22 | info(f'Decoded data: {translation_request}') 23 | return translation_request 24 | ``` 25 | 26 | Note: The translation request is base64-encoded in the `Data` field. 27 | 28 | ## Handle Translation Request 29 | 30 | Once we have the translation request, we can pass it to the Translation API: 31 | 32 | ```python 33 | from google.cloud import translate 34 | ... 35 | 36 | def translate_text(request): 37 | client = translate.Client() 38 | response = client.translate( 39 | request['text'], 40 | source_language=request['from'], 41 | target_language=request['to']) 42 | translated_text = response['translatedText'] 43 | info(f'Translated text: {translated_text}') 44 | if ('detectedSourceLanguage' in response): 45 | detected_language = response['detectedSourceLanguage'] 46 | info(f'Detected language: {detected_language}') 47 | ``` 48 | 49 | ## Create Dockerfile 50 | 51 | Create a [Dockerfile](../eventing/translation/python/Dockerfile) for the image: 52 | 53 | ```dockerfile 54 | FROM python:3.7-slim 55 | 56 | RUN pip install Flask gunicorn google.cloud.translate 57 | 58 | WORKDIR /app 59 | COPY . . 60 | 61 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 62 | ``` 63 | 64 | Note: `google.cloud.translate` client library is specified in addition to `Flask` & `gunicorn`. 65 | 66 | ## What's Next? 67 | 68 | Back to [Integrate with Translation API](translationeventing.md) 69 | -------------------------------------------------------------------------------- /docs/twiliointegration-csharp.md: -------------------------------------------------------------------------------- 1 | # Create Twilio SMS handler - C# 2 | 3 | ## Create SmsController 4 | 5 | Start with creating an empty ASP.NET Core app: 6 | 7 | ```bash 8 | dotnet new web -o twiliosample 9 | ``` 10 | 11 | Inside the `twilio` folder, change [Startup.cs](../serving/twilio/csharp/Startup.cs) to use controllers: 12 | 13 | ```csharp 14 | public void ConfigureServices(IServiceCollection services) 15 | { 16 | services.AddControllers(); 17 | } 18 | 19 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 20 | { 21 | if (env.IsDevelopment()) 22 | { 23 | app.UseDeveloperExceptionPage(); 24 | } 25 | 26 | app.UseRouting(); 27 | 28 | app.UseEndpoints(endpoints => 29 | { 30 | endpoints.MapDefaultControllerRoute(); 31 | }); 32 | } 33 | ``` 34 | 35 | Next, let's install [twilio-aspnet](https://github.com/twilio/twilio-aspnet) package: 36 | 37 | ```bash 38 | dotnet add package Twilio.AspNet.Core 39 | ``` 40 | 41 | Finally, we can create [SmsController.cs](../serving/twilio/csharp/SmsController.cs) to receive SMS messages from Twilio: 42 | 43 | ```csharp 44 | using Microsoft.AspNetCore.Mvc; 45 | using Twilio.AspNet.Common; 46 | using Twilio.AspNet.Core; 47 | using Twilio.TwiML; 48 | 49 | namespace twiliosample 50 | { 51 | 52 | public class SmsController : TwilioController 53 | { 54 | [HttpGet] 55 | public TwiMLResult Index(SmsRequest incomingMessage) 56 | { 57 | var messagingResponse = new MessagingResponse(); 58 | messagingResponse.Message("The Knative copy cat says: " + incomingMessage.Body); 59 | return TwiML(messagingResponse); 60 | } 61 | } 62 | } 63 | ``` 64 | 65 | `SmsController.cs` simply echoes back the received message. 66 | 67 | Make sure the app has no compilation errors: 68 | 69 | ```bash 70 | dotnet build 71 | ``` 72 | 73 | ## Create a Dockerfile 74 | 75 | Create a [Dockerfile](../serving/twilio/csharp/Dockerfile) for the image: 76 | 77 | ```dockerfile 78 | # Use Microsoft's official build .NET image. 79 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 80 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build 81 | WORKDIR /app 82 | 83 | # Install production dependencies. 84 | # Copy csproj and restore as distinct layers. 85 | COPY *.csproj ./ 86 | RUN dotnet restore 87 | 88 | # Copy local code to the container image. 89 | COPY . ./ 90 | WORKDIR /app 91 | 92 | # Build a release artifact. 93 | RUN dotnet publish -c Release -o out 94 | 95 | 96 | # Use Microsoft's official runtime .NET image. 97 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 98 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime 99 | WORKDIR /app 100 | COPY --from=build /app/out ./ 101 | 102 | # Run the web service on container startup. 103 | ENTRYPOINT ["dotnet", "twiliosample.dll"] 104 | ``` 105 | 106 | ## What's Next? 107 | 108 | [Back to Integrate with Twilio](twiliointegration.md) 109 | -------------------------------------------------------------------------------- /docs/twiliointegration-python.md: -------------------------------------------------------------------------------- 1 | # Create Twilio SMS handler - Python 2 | 3 | ## Create an SMS endpoint 4 | 5 | Create a Flask app ([app.py](../serving/twilio/python/app.py)) responding a Twilio message from `GET` requests on the `/sms` endpoint: 6 | 7 | ```python 8 | import os 9 | 10 | from flask import Flask, request 11 | from twilio.twiml.messaging_response import MessagingResponse 12 | 13 | app = Flask(__name__) 14 | 15 | 16 | @app.route('/sms', methods=['GET']) 17 | def sms_reply(): 18 | body = request.values.get('Body', '-') 19 | resp = MessagingResponse() 20 | resp.message(f'The Knative copy cat says: {body}') 21 | return str(resp) 22 | 23 | 24 | if __name__ == '__main__': 25 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 26 | ``` 27 | 28 | ## Create a Dockerfile 29 | 30 | Create a [Dockerfile](../serving/twilio/python/Dockerfile) for the image: 31 | 32 | ```dockerfile 33 | FROM python:3.7-slim 34 | 35 | RUN pip install Flask gunicorn twilio 36 | 37 | WORKDIR /app 38 | COPY . . 39 | 40 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 41 | ``` 42 | 43 | Note: The `twilio` client library is used in addition to `Flask` & `gunicorn`. 44 | 45 | ## What's Next? 46 | 47 | [Back to Integrate with Twilio](twiliointegration.md) 48 | -------------------------------------------------------------------------------- /docs/twiliointegration.md: -------------------------------------------------------------------------------- 1 | # Integrate with Twilio 2 | 3 | You can use [Twilio](https://www.twilio.com/) to embed voice, VoIP, and messaging into applications. In this lab, we will use a [Webhook](https://www.twilio.com/docs/glossary/what-is-a-webhook) to reply to SMS messages sent to a Twilio phone number. The Webhook is going to be a Knative service running on GKE. 4 | 5 | ## Twilio Setup 6 | 7 | You need to [create a Twilio account](https://www.twilio.com/try-twilio) and get a [Twilio phone number](https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account#get-your-first-twilio-phone-number). You need to make sure that the Twilio number is SMS enabled. 8 | 9 | In Twilio [console](https://www.twilio.com/console), click on the phone number and go to `Messaging` section. There's a Webhook defined for when a message comes in. We will change that to our Knative Service later: 10 | 11 | ![Twilio Webhook](./images/twilio-webhook.png) 12 | 13 | ## Create Twilio SMS handler 14 | 15 | Follow the instructions for your preferred language to create a service to handle SMS messages to our Twilio number: 16 | 17 | * [Create Twilio SMS Handler - C#](twiliointegration-csharp.md) 18 | 19 | * [Create Twilio SMS Handler - Python](twiliointegration-python.md) 20 | 21 | ## Build and push Docker image 22 | 23 | Build and push the Docker image (replace `{username}` with your actual DockerHub): 24 | 25 | ```bash 26 | docker build -t {username}/twilio:v1 . 27 | 28 | docker push {username}/twilio:v1 29 | ``` 30 | 31 | ## Deploy the Knative service 32 | 33 | Take a look at the [service.yaml](../serving/twilio/service.yaml) file. 34 | 35 | After the container is pushed, deploy the app. 36 | 37 | ```bash 38 | kubectl apply -f service.yaml 39 | ``` 40 | 41 | Check that the service is created: 42 | 43 | ```bash 44 | kubectl get ksvc twilio 45 | 46 | NAME URL LATESTCREATED LATESTREADY READY REASON 47 | twilio http://twilio.default.1.2.3.4.xip.io twilio-v96ms twilio-v96ms True 48 | ``` 49 | 50 | ## Test the service 51 | 52 | Let's first check that our service works as expected: 53 | 54 | ```bash 55 | export TWILIO_URL=$(kubectl get route twilio -o jsonpath="{.status.url}") 56 | echo $TWILIO_URL 57 | http://twilio.default.1.2.3.4.xip.io 58 | 59 | curl $TWILIO_URL/sms?Body=Hello+World! 60 | The Knative copy cat says: Hello World! 61 | ``` 62 | 63 | We can finally test our service by sending an SMS to our Twilio number. We need to setup Twilio Webhook first. 64 | 65 | In Twilio [console](https://www.twilio.com/console), click on the phone number and go to `Messaging` section. For Webhook defined for when a message comes in, change it to your Knative service name and XIP.IO domain: 66 | 67 | ![Twilio Webhook](./images/twilio-webhook-custom.png) 68 | 69 | Now, you can send an SMS message to your Twilio number and you should get a reply back from the Knative service! 70 | -------------------------------------------------------------------------------- /docs/visioneventing-csharp.md: -------------------------------------------------------------------------------- 1 | # Create Vision Handler - C# 2 | 3 | ## Create Vision Handler 4 | 5 | Let's start with creating an empty ASP.NET Core app: 6 | 7 | ```bash 8 | dotnet new web -o vision 9 | ``` 10 | 11 | Inside the `vision/csharp` folder, update [Startup.cs](../eventing/vision/csharp/Startup.cs) to match with what we have. 12 | 13 | Change the log level in `appsettings.json` to `Information`: 14 | 15 | ```json 16 | { 17 | "Logging": { 18 | "LogLevel": { 19 | "Default": "Information" 20 | } 21 | }, 22 | "AllowedHosts": "*" 23 | } 24 | ``` 25 | 26 | ## Add Vision API 27 | 28 | Add Vision API NuGet package to our project: 29 | 30 | ```bash 31 | dotnet add package Google.Cloud.Vision.V1 32 | ``` 33 | 34 | [Startup.cs](../eventing/vision/csharp/Startup.cs) checks for `storage#object` events. These events are emitted by Cloud Storage when a file is uploaded. 35 | 36 | ```csharp 37 | dynamic json = JValue.Parse(content); 38 | if (json == null) return; 39 | 40 | var kind = json.kind; 41 | if (kind == null || kind != "storage#object") return; 42 | ``` 43 | 44 | Next, we extract the Cloud Storage URL of the file from the event: 45 | 46 | ```csharp 47 | var storageUrl = (string)ConstructStorageUrl(json); 48 | 49 | private string ConstructStorageUrl(dynamic json) 50 | { 51 | return json == null? null 52 | : string.Format("gs://{0}/{1}", json.bucket, json.name); 53 | } 54 | ``` 55 | 56 | Finally, make a call to Vision API to extract labels from the image: 57 | 58 | ```csharp 59 | var labels = await ExtractLabelsAsync(storageUrl); 60 | 61 | var message = "This picture is labelled: " + labels; 62 | _logger.LogInformation(message); 63 | await context.Response.WriteAsync(message); 64 | 65 | private async Task ExtractLabelsAsync(string storageUrl) 66 | { 67 | var visionClient = ImageAnnotatorClient.Create(); 68 | var labels = await visionClient.DetectLabelsAsync(Image.FromUri(storageUrl), maxResults: 10); 69 | 70 | var orderedLabels = labels 71 | .OrderByDescending(x => x.Score) 72 | .TakeWhile((x, i) => i <= 2 || x.Score > 0.50) 73 | .Select(x => x.Description) 74 | .ToList(); 75 | 76 | return string.Join(",", orderedLabels.ToArray()); 77 | } 78 | ``` 79 | 80 | You can see the full code in [Startup.cs](../eventing/vision/csharp/Startup.cs). 81 | 82 | Before building the Docker image, make sure the app has no compilation errors: 83 | 84 | ```bash 85 | dotnet build 86 | ``` 87 | 88 | ## Create Dockerfile 89 | 90 | Create a [Dockerfile](../eventing/vision/csharp/Dockerfile) for the image. 91 | 92 | ## What's Next? 93 | 94 | Back to [Integrate with Vision API](visioneventing.md) 95 | -------------------------------------------------------------------------------- /docs/visioneventing-python.md: -------------------------------------------------------------------------------- 1 | # Create Vision Handler - Python 2 | 3 | ## Create Vision Handler 4 | 5 | Adapt the previous message dumper sample by creating a new [app.py](../eventing/vision/python/app.py): 6 | 7 | ```python 8 | from flask import Flask, request 9 | ... 10 | @app.route('/', methods=['POST']) 11 | def storage_event(): 12 | attr = json.loads(request.data)['Attributes'] 13 | if attr['eventType'] == 'OBJECT_FINALIZE': 14 | analyze_image(attr['bucketId'], attr['objectId']) 15 | return 'OK', 200 16 | ``` 17 | 18 | Note: When the file is created/updated, an event of type `OBJECT_FINALIZE` is received. Bucket and file names are respectively given by `bucketId` and `objectId` attributes. 19 | 20 | ## Handle Image Analysis 21 | 22 | Once we have the file info, we can pass it to the Vision API: 23 | 24 | ```python 25 | from google.cloud import vision 26 | ... 27 | def analyze_image(bucket_id, filename): 28 | client = vision.ImageAnnotatorClient() 29 | image = vision.types.Image() 30 | image.source.image_uri = f'gs://{bucket_id}/{filename}' 31 | response = client.label_detection(image=image) 32 | 33 | annots = response.label_annotations 34 | labels = ', '.join([a.description for a in annots if 0.5 <= a.score]) 35 | info(f'Picture labels: {labels}') 36 | ``` 37 | 38 | ## Create Dockerfile 39 | 40 | Create a [Dockerfile](../eventing/vision/python/Dockerfile) for the image: 41 | 42 | ```dockerfile 43 | FROM python:3.7-slim 44 | 45 | RUN pip install Flask gunicorn google.cloud.vision 46 | 47 | WORKDIR /app 48 | COPY . . 49 | 50 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 51 | ``` 52 | 53 | Note: `google.cloud.vision` client library is specified in addition to `Flask` & `gunicorn`. 54 | 55 | ## What's Next? 56 | 57 | Back to [Integrate with Vision API](visioneventing.md) 58 | -------------------------------------------------------------------------------- /eventing/brokertrigger/service1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service1 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/brokertrigger/service2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service2 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display-with-reply:v1 23 | -------------------------------------------------------------------------------- /eventing/brokertrigger/service3.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service3 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/brokertrigger/source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: eventing.knative.dev/v1beta1 24 | kind: Broker 25 | name: default -------------------------------------------------------------------------------- /eventing/brokertrigger/trigger1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger1 18 | spec: 19 | broker: default 20 | filter: 21 | attributes: 22 | type: dev.knative.sources.ping 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service1 28 | 29 | -------------------------------------------------------------------------------- /eventing/brokertrigger/trigger2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger2 18 | spec: 19 | broker: default 20 | filter: 21 | attributes: 22 | type: dev.knative.sources.ping 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service2 28 | 29 | -------------------------------------------------------------------------------- /eventing/brokertrigger/trigger3.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger3 18 | spec: 19 | broker: default 20 | filter: 21 | attributes: 22 | type: dev.knative.samples.hifromknative 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service3 28 | 29 | -------------------------------------------------------------------------------- /eventing/complex/channel.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: InMemoryChannel 16 | metadata: 17 | name: channel 18 | -------------------------------------------------------------------------------- /eventing/complex/service1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service1 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/complex/service2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service2 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/complex/source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: messaging.knative.dev/v1beta1 24 | kind: InMemoryChannel 25 | name: channel -------------------------------------------------------------------------------- /eventing/complex/subscription1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: Subscription 16 | metadata: 17 | name: subscription1 18 | spec: 19 | channel: 20 | apiVersion: messaging.knative.dev/v1beta1 21 | kind: InMemoryChannel 22 | name: channel 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service1 28 | -------------------------------------------------------------------------------- /eventing/complex/subscription2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: Subscription 16 | metadata: 17 | name: subscription2 18 | spec: 19 | channel: 20 | apiVersion: messaging.knative.dev/v1beta1 21 | kind: InMemoryChannel 22 | name: channel 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service2 28 | -------------------------------------------------------------------------------- /eventing/complexwithreply/channel1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: InMemoryChannel 16 | metadata: 17 | name: channel1 18 | -------------------------------------------------------------------------------- /eventing/complexwithreply/channel2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: InMemoryChannel 16 | metadata: 17 | name: channel2 -------------------------------------------------------------------------------- /eventing/complexwithreply/service1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service1 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/complexwithreply/service2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service2 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display-with-reply:v1 23 | -------------------------------------------------------------------------------- /eventing/complexwithreply/service3.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service3 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/complexwithreply/source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: messaging.knative.dev/v1beta1 24 | kind: InMemoryChannel 25 | name: channel1 -------------------------------------------------------------------------------- /eventing/complexwithreply/subscription1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: Subscription 16 | metadata: 17 | name: subscription1 18 | spec: 19 | channel: 20 | apiVersion: messaging.knative.dev/v1beta1 21 | kind: InMemoryChannel 22 | name: channel1 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service1 28 | -------------------------------------------------------------------------------- /eventing/complexwithreply/subscription2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: Subscription 16 | metadata: 17 | name: subscription2 18 | spec: 19 | channel: 20 | apiVersion: messaging.knative.dev/v1beta1 21 | kind: InMemoryChannel 22 | name: channel1 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service2 28 | reply: 29 | ref: 30 | apiVersion: messaging.knative.dev/v1beta1 31 | kind: InMemoryChannel 32 | name: channel2 33 | -------------------------------------------------------------------------------- /eventing/complexwithreply/subscription3.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: messaging.knative.dev/v1beta1 15 | kind: Subscription 16 | metadata: 17 | name: subscription3 18 | spec: 19 | channel: 20 | apiVersion: messaging.knative.dev/v1beta1 21 | kind: InMemoryChannel 22 | name: channel2 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | kind: Service 27 | name: service3 28 | -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "event-display-with-reply.dll"] -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace event_display_with_reply 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:43180", 7 | "sslPort": 44329 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "message_dumper": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /eventing/event-display-with-reply/csharp/event-display-with-reply.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /eventing/event-display/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "event-display.dll"] -------------------------------------------------------------------------------- /eventing/event-display/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace event_display 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /eventing/event-display/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:43180", 7 | "sslPort": 44329 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "message_dumper": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /eventing/event-display/csharp/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using CloudNative.CloudEvents; 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Hosting; 17 | using Microsoft.Extensions.DependencyInjection; 18 | using Microsoft.Extensions.Hosting; 19 | using Microsoft.Extensions.Logging; 20 | 21 | namespace event_display 22 | { 23 | public class Startup 24 | { 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | } 28 | 29 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger logger) 30 | { 31 | if (env.IsDevelopment()) 32 | { 33 | app.UseDeveloperExceptionPage(); 34 | } 35 | 36 | logger.LogInformation("Service is starting..."); 37 | 38 | app.UseRouting(); 39 | 40 | app.UseEndpoints(endpoints => 41 | { 42 | endpoints.MapPost("/", async context => 43 | { 44 | var cloudEvent = await context.Request.ReadCloudEventAsync(); 45 | 46 | logger.LogInformation("Received CloudEvent\n" + GetEventLog(cloudEvent)); 47 | }); 48 | }); 49 | } 50 | 51 | private string GetEventLog(CloudEvent cloudEvent) 52 | { 53 | return $"ID: {cloudEvent.Id}\n" 54 | + $"Source: {cloudEvent.Source}\n" 55 | + $"Type: {cloudEvent.Type}\n" 56 | + $"Subject: {cloudEvent.Subject}\n" 57 | + $"DataSchema: {cloudEvent.DataSchema}\n" 58 | + $"DataContentType: {cloudEvent.DataContentType}\n" 59 | + $"Time: {cloudEvent.Time?.ToUniversalTime():yyyy-MM-dd'T'HH:mm:ss.fff'Z'}\n" 60 | + $"SpecVersion: {cloudEvent.SpecVersion}\n" 61 | + $"Data: {cloudEvent.Data}"; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /eventing/event-display/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /eventing/event-display/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /eventing/event-display/csharp/event-display.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /eventing/event-display/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind 0.0.0.0:8080 --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /eventing/event-display/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import logging 16 | import os 17 | 18 | from flask import Flask, request 19 | 20 | app = Flask(__name__) 21 | 22 | 23 | @app.route('/', methods=['POST']) 24 | def pubsub_push(): 25 | content = request.data.decode('utf-8') 26 | info(f'Event Display received event: {content}') 27 | return 'OK', 200 28 | 29 | def info(msg): 30 | app.logger.info(msg) 31 | 32 | 33 | if __name__ != '__main__': 34 | # Redirect Flask logs to Gunicorn logs 35 | gunicorn_logger = logging.getLogger('gunicorn.error') 36 | app.logger.handlers = gunicorn_logger.handlers 37 | app.logger.setLevel(gunicorn_logger.level) 38 | info('Event Display starting') 39 | else: 40 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 41 | -------------------------------------------------------------------------------- /eventing/helloworld/curl-pod.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: v1 15 | kind: Pod 16 | metadata: 17 | labels: 18 | run: curl 19 | name: curl 20 | spec: 21 | containers: 22 | # This could be any image that we can SSH into and has curl. 23 | - image: radial/busyboxplus:curl 24 | imagePullPolicy: IfNotPresent 25 | name: curl 26 | resources: {} 27 | stdin: true 28 | terminationMessagePath: /dev/termination-log 29 | terminationMessagePolicy: File 30 | tty: true 31 | -------------------------------------------------------------------------------- /eventing/helloworld/kservice.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: event-display 18 | spec: 19 | template: 20 | metadata: 21 | annotations: 22 | autoscaling.knative.dev/minScale: "1" 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/event-display:v1 26 | -------------------------------------------------------------------------------- /eventing/helloworld/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: event-display 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: event-display 22 | template: 23 | metadata: 24 | labels: 25 | app: event-display 26 | spec: 27 | containers: 28 | - name: user-container 29 | image: docker.io/meteatamel/event-display:v1 30 | imagePullPolicy: Always 31 | ports: 32 | - containerPort: 8080 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: event-display 38 | spec: 39 | selector: 40 | app: event-display 41 | ports: 42 | - protocol: TCP 43 | port: 80 44 | targetPort: 8080 45 | -------------------------------------------------------------------------------- /eventing/helloworld/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-event-display 18 | spec: 19 | broker: default 20 | filter: 21 | attributes: 22 | type: event-display 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | #apiVersion: v1 27 | kind: Service 28 | name: event-display 29 | 30 | -------------------------------------------------------------------------------- /eventing/pictures/atamel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/atamel.jpg -------------------------------------------------------------------------------- /eventing/pictures/beach.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/beach.jpg -------------------------------------------------------------------------------- /eventing/pictures/bodrum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/bodrum.jpg -------------------------------------------------------------------------------- /eventing/pictures/paris.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/paris.jpg -------------------------------------------------------------------------------- /eventing/pictures/river.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/river.jpg -------------------------------------------------------------------------------- /eventing/pictures/yachtclub.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meteatamel/knative-tutorial/65447bcbf0dc718f0600bc461fbca92fbbdb1b4b/eventing/pictures/yachtclub.jpg -------------------------------------------------------------------------------- /eventing/ping/source-broker.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: eventing.knative.dev/v1beta1 24 | kind: Broker 25 | name: default 26 | -------------------------------------------------------------------------------- /eventing/ping/source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: serving.knative.dev/v1 24 | #apiVersion: v1 25 | kind: Service 26 | name: event-display -------------------------------------------------------------------------------- /eventing/ping/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-event-display 18 | spec: 19 | broker: default 20 | filter: 21 | attributes: 22 | type: dev.knative.sources.ping 23 | subscriber: 24 | ref: 25 | apiVersion: serving.knative.dev/v1 26 | #apiVersion: v1 27 | kind: Service 28 | name: event-display 29 | 30 | -------------------------------------------------------------------------------- /eventing/pubsub/cloudpubsubsource-workload.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: events.cloud.google.com/v1 15 | kind: CloudPubSubSource 16 | metadata: 17 | name: cloudpubsubsource-test 18 | spec: 19 | topic: testing 20 | sink: 21 | ref: 22 | apiVersion: eventing.knative.dev/v1 23 | kind: Broker 24 | name: default 25 | # If running in GKE, we will ask the metadata server, change this if required. 26 | project: knative-atamel 27 | # If running with workload identity enabled, update serviceAccountName. 28 | serviceAccountName: default-cre-dataplane 29 | # If running with secret, here is the default secret name and key, change this if required. 30 | # secret: 31 | # name: google-cloud-key 32 | # key: key.json 33 | -------------------------------------------------------------------------------- /eventing/pubsub/cloudpubsubsource.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: events.cloud.google.com/v1 15 | kind: CloudPubSubSource 16 | metadata: 17 | name: cloudpubsubsource-test 18 | spec: 19 | topic: testing 20 | sink: 21 | ref: 22 | apiVersion: eventing.knative.dev/v1 23 | kind: Broker 24 | name: default 25 | -------------------------------------------------------------------------------- /eventing/pubsub/kservice.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: event-display 18 | spec: 19 | template: 20 | metadata: 21 | annotations: 22 | autoscaling.knative.dev/minScale: "1" 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/event-display:v1 26 | -------------------------------------------------------------------------------- /eventing/pubsub/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: event-display 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: event-display 22 | template: 23 | metadata: 24 | labels: 25 | app: event-display 26 | spec: 27 | containers: 28 | - name: user-container 29 | image: docker.io/meteatamel/event-display:v1 30 | imagePullPolicy: Always 31 | ports: 32 | - containerPort: 8080 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: event-display 38 | spec: 39 | selector: 40 | app: event-display 41 | ports: 42 | - protocol: TCP 43 | port: 80 44 | targetPort: 8080 45 | -------------------------------------------------------------------------------- /eventing/pubsub/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-event-display-pubsub 18 | spec: 19 | broker: default 20 | subscriber: 21 | ref: 22 | apiVersion: serving.knative.dev/v1 23 | #apiVersion: v1 24 | kind: Service 25 | name: event-display 26 | 27 | -------------------------------------------------------------------------------- /eventing/simple/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: service 18 | spec: 19 | template: 20 | spec: 21 | containers: 22 | - image: docker.io/meteatamel/event-display:v1 23 | -------------------------------------------------------------------------------- /eventing/simple/source.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: sources.knative.dev/v1 15 | kind: PingSource 16 | metadata: 17 | name: source 18 | spec: 19 | schedule: "* * * * *" 20 | data: '{"message": "Hello world from ping!"}' 21 | sink: 22 | ref: 23 | apiVersion: serving.knative.dev/v1 24 | kind: Service 25 | name: service 26 | -------------------------------------------------------------------------------- /eventing/storage/cloudstoragesource.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: events.cloud.google.com/v1 15 | kind: CloudStorageSource 16 | metadata: 17 | name: cloud-storage-source 18 | spec: 19 | bucket: knative-atamel-storage 20 | sink: 21 | ref: 22 | apiVersion: eventing.knative.dev/v1 23 | kind: Broker 24 | name: default -------------------------------------------------------------------------------- /eventing/storage/kservice.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: event-display 18 | spec: 19 | template: 20 | metadata: 21 | annotations: 22 | autoscaling.knative.dev/minScale: "1" 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/event-display:v1 26 | -------------------------------------------------------------------------------- /eventing/storage/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: event-display 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: event-display 22 | template: 23 | metadata: 24 | labels: 25 | app: event-display 26 | spec: 27 | containers: 28 | - name: user-container 29 | image: docker.io/meteatamel/event-display:v1 30 | imagePullPolicy: Always 31 | ports: 32 | - containerPort: 8080 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: event-display 38 | spec: 39 | selector: 40 | app: event-display 41 | ports: 42 | - protocol: TCP 43 | port: 80 44 | targetPort: 8080 45 | -------------------------------------------------------------------------------- /eventing/storage/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-event-display-storage 18 | spec: 19 | broker: default 20 | subscriber: 21 | ref: 22 | apiVersion: serving.knative.dev/v1 23 | #apiVersion: v1 24 | kind: Service 25 | name: event-display 26 | 27 | -------------------------------------------------------------------------------- /eventing/translation/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "translation.dll"] 27 | -------------------------------------------------------------------------------- /eventing/translation/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace translation 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /eventing/translation/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:8640", 7 | "sslPort": 44343 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "translation": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /eventing/translation/csharp/TranslationRequest.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | namespace translation 15 | { 16 | 17 | // {text = 'Hello World', from='en', to='es'}: English to Spanish 18 | // {text = 'Hello World', from='', to='es'}: Detected language to Spanish 19 | // {text = 'Hello World', from='', to=''}: Error 20 | 21 | public class TranslationRequest 22 | { 23 | public string From; 24 | 25 | public string To; 26 | 27 | public string Text; 28 | } 29 | } -------------------------------------------------------------------------------- /eventing/translation/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /eventing/translation/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /eventing/translation/csharp/translation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /eventing/translation/kservice.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: translation 18 | spec: 19 | template: 20 | metadata: 21 | annotations: 22 | autoscaling.knative.dev/minScale: "1" 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/translation:v1 26 | -------------------------------------------------------------------------------- /eventing/translation/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn google.cloud.translate 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind 0.0.0.0:8080 --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /eventing/translation/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import logging 17 | import os 18 | 19 | from flask import Flask, request 20 | from google.cloud import translate 21 | 22 | app = Flask(__name__) 23 | 24 | 25 | @app.route('/', methods=['POST']) 26 | def pubsub_push(): 27 | translation_request = get_translation_request() 28 | translate_text(translation_request) 29 | return 'OK', 200 30 | 31 | 32 | def info(msg): 33 | app.logger.info(msg) 34 | 35 | 36 | def get_translation_request(): 37 | content = request.data.decode('utf-8') 38 | info(f'Translation received event: {content}') 39 | 40 | translation_request = json.loads(content) 41 | return translation_request 42 | 43 | 44 | def translate_text(request): 45 | client = translate.Client() 46 | response = client.translate( 47 | request['text'], 48 | source_language=request['from'], 49 | target_language=request['to']) 50 | translated_text = response['translatedText'] 51 | info(f'Translated text: {translated_text}') 52 | if ('detectedSourceLanguage' in response): 53 | detected_language = response['detectedSourceLanguage'] 54 | info(f'Detected language: {detected_language}') 55 | 56 | 57 | if __name__ != '__main__': 58 | # Redirect Flask logs to Gunicorn logs 59 | gunicorn_logger = logging.getLogger('gunicorn.error') 60 | app.logger.handlers = gunicorn_logger.handlers 61 | app.logger.setLevel(gunicorn_logger.level) 62 | info('Translation starting...') 63 | else: 64 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 65 | -------------------------------------------------------------------------------- /eventing/translation/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: translation 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: translation 22 | template: 23 | metadata: 24 | labels: 25 | app: translation 26 | spec: 27 | containers: 28 | - name: user-container 29 | image: docker.io/meteatamel/translation:v1 30 | imagePullPolicy: Always 31 | ports: 32 | - containerPort: 8080 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: translation 38 | spec: 39 | selector: 40 | app: translation 41 | ports: 42 | - protocol: TCP 43 | port: 80 44 | targetPort: 8080 45 | -------------------------------------------------------------------------------- /eventing/translation/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-translation 18 | spec: 19 | broker: default 20 | subscriber: 21 | ref: 22 | apiVersion: serving.knative.dev/v1 23 | #apiVersion: v1 24 | kind: Service 25 | name: translation 26 | 27 | -------------------------------------------------------------------------------- /eventing/vision/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "vision.dll"] -------------------------------------------------------------------------------- /eventing/vision/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace vision 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /eventing/vision/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:45637", 7 | "sslPort": 44338 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "vision": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /eventing/vision/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /eventing/vision/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /eventing/vision/csharp/vision.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /eventing/vision/kservice.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: vision 18 | spec: 19 | template: 20 | metadata: 21 | annotations: 22 | autoscaling.knative.dev/minScale: "1" 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/vision:v1 26 | -------------------------------------------------------------------------------- /eventing/vision/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn google.cloud.vision 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind 0.0.0.0:8080 --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /eventing/vision/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import logging 17 | import os 18 | 19 | from flask import Flask, request 20 | from google.cloud import vision 21 | 22 | app = Flask(__name__) 23 | 24 | 25 | @app.route('/', methods=['POST']) 26 | def storage_event(): 27 | content = request.data 28 | info(f'Vision received event: {content}') 29 | 30 | obj = json.loads(content) 31 | if obj['kind'] == 'storage#object': 32 | analyze_image(obj['bucket'], obj['name']) 33 | return 'OK', 200 34 | 35 | 36 | def analyze_image(bucket_id, filename): 37 | client = vision.ImageAnnotatorClient() 38 | image = vision.types.Image() 39 | image.source.image_uri = f'gs://{bucket_id}/{filename}' 40 | response = client.label_detection(image=image) 41 | 42 | annots = response.label_annotations 43 | labels = ', '.join([a.description for a in annots if 0.5 <= a.score]) 44 | info(f'Picture labels: {labels}') 45 | 46 | 47 | def info(msg): 48 | app.logger.info(msg) 49 | 50 | 51 | if __name__ != '__main__': 52 | # Redirect Flask logs to Gunicorn logs 53 | gunicorn_logger = logging.getLogger('gunicorn.error') 54 | app.logger.handlers = gunicorn_logger.handlers 55 | app.logger.setLevel(gunicorn_logger.level) 56 | info('Vision starting...') 57 | else: 58 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 59 | -------------------------------------------------------------------------------- /eventing/vision/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: apps/v1 15 | kind: Deployment 16 | metadata: 17 | name: vision 18 | spec: 19 | selector: 20 | matchLabels: 21 | app: vision 22 | template: 23 | metadata: 24 | labels: 25 | app: vision 26 | spec: 27 | containers: 28 | - name: user-container 29 | image: docker.io/meteatamel/vision:v1 30 | imagePullPolicy: Always 31 | ports: 32 | - containerPort: 8080 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: vision 38 | spec: 39 | selector: 40 | app: vision 41 | ports: 42 | - protocol: TCP 43 | port: 80 44 | targetPort: 8080 45 | -------------------------------------------------------------------------------- /eventing/vision/trigger.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: eventing.knative.dev/v1 15 | kind: Trigger 16 | metadata: 17 | name: trigger-vision 18 | spec: 19 | broker: default 20 | subscriber: 21 | ref: 22 | apiVersion: serving.knative.dev/v1 23 | #apiVersion: v1 24 | kind: Service 25 | name: vision 26 | 27 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official lightweight build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | # Use Microsoft's official runtime .NET image. 19 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 20 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime 21 | WORKDIR /app 22 | COPY --from=build /app/out ./ 23 | 24 | # Run the web service on container startup. 25 | ENTRYPOINT ["dotnet", "GrpcGreeter.dll"] -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/GrpcGreeter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace GrpcGreeter 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup(); 36 | webBuilder.UseUrls(url); 37 | }); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "GrpcGreeter": { 4 | "commandName": "Project", 5 | "launchBrowser": false, 6 | "applicationUrl": "http://localhost:50051", 7 | "environmentVariables": { 8 | "ASPNETCORE_ENVIRONMENT": "Development" 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Protos/greet.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | syntax = "proto3"; 15 | 16 | option csharp_namespace = "GrpcGreeter"; 17 | 18 | package Greet; 19 | 20 | // The greeting service definition. 21 | service Greeter { 22 | // Sends a greeting 23 | rpc SayHello (HelloRequest) returns (HelloReply) {} 24 | } 25 | 26 | // The request message containing the user's name. 27 | message HelloRequest { 28 | string name = 1; 29 | } 30 | 31 | // The response message containing the greetings. 32 | message HelloReply { 33 | string message = 1; 34 | } 35 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Services/GreeterService.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using System.Collections.Generic; 16 | using System.Linq; 17 | using System.Threading.Tasks; 18 | using Grpc.Core; 19 | 20 | namespace GrpcGreeter 21 | { 22 | public class GreeterService : Greeter.GreeterBase 23 | { 24 | public override Task SayHello(HelloRequest request, ServerCallContext context) 25 | { 26 | return Task.FromResult(new HelloReply 27 | { 28 | Message = "Hello " + request.Name 29 | }); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using Microsoft.AspNetCore.Builder; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.DependencyInjection; 17 | using Microsoft.Extensions.Hosting; 18 | 19 | namespace GrpcGreeter 20 | { 21 | public class Startup 22 | { 23 | // This method gets called by the runtime. Use this method to add services to the container. 24 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddGrpc(); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseRouting(); 39 | 40 | app.UseEndpoints(endpoints => 41 | { 42 | // Communication with gRPC endpoints must be made through a gRPC client. 43 | // To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909 44 | endpoints.MapGrpcService(); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Grpc": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeter/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "Kestrel": { 10 | "EndpointDefaults": { 11 | "Protocols": "Http2" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeterClient/GrpcGreeterClient.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeterClient/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using System.Net.Http; 16 | using System.Threading.Tasks; 17 | using GrpcGreeter; 18 | using Grpc.Net.Client; 19 | 20 | namespace GrpcGreeterClient 21 | { 22 | class Program 23 | { 24 | static async Task Main(string[] args) 25 | { 26 | AppContext.SetSwitch( 27 | "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", 28 | true); 29 | var httpClient = new HttpClient(); 30 | // The port number(50051) must match the port of the gRPC server. 31 | httpClient.BaseAddress = new Uri("http://localhost:50051"); 32 | //httpClient.BaseAddress = new Uri("http://grpc-greeter.default.35.205.12.104.nip.io"); 33 | var client = GrpcClient.Create(httpClient); 34 | var reply = await client.SayHelloAsync( 35 | new HelloRequest { Name = "GreeterClient" }); 36 | Console.WriteLine("Greeting: " + reply.Message); 37 | Console.WriteLine("Press any key to exit..."); 38 | Console.ReadKey(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /serving/grpc/csharp/GrpcGreeterClient/Protos/greet.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | syntax = "proto3"; 15 | 16 | option csharp_namespace = "GrpcGreeter"; 17 | 18 | package Greet; 19 | 20 | // The greeting service definition. 21 | service Greeter { 22 | // Sends a greeting 23 | rpc SayHello (HelloRequest) returns (HelloReply) {} 24 | } 25 | 26 | // The request message containing the user's name. 27 | message HelloRequest { 28 | string name = 1; 29 | } 30 | 31 | // The response message containing the greetings. 32 | message HelloReply { 33 | string message = 1; 34 | } 35 | -------------------------------------------------------------------------------- /serving/grpc/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install protobuf grpcio 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY greet_server.py greet_pb2.py greet_pb2_grpc.py ./ 11 | 12 | ENV PORT 8080 13 | CMD python greet_server.py -p $PORT 14 | -------------------------------------------------------------------------------- /serving/grpc/python/greet_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import argparse 16 | 17 | import grpc 18 | 19 | import greet_pb2 20 | import greet_pb2_grpc 21 | 22 | 23 | def run(target): 24 | with grpc.insecure_channel(target) as channel: 25 | stub = greet_pb2_grpc.GreeterStub(channel) 26 | response = stub.SayHello(greet_pb2.HelloRequest(name='GreeterClient')) 27 | print(f'Greeting: {response.message}') 28 | 29 | 30 | def get_target(server, port): 31 | prefix = 'http://' 32 | server = server[len(prefix):] if server.startswith(prefix) else server 33 | return f'{server}:{port}' 34 | 35 | 36 | if __name__ == '__main__': 37 | parser = argparse.ArgumentParser() 38 | parser.add_argument('-s', '--server', type=str, default='localhost') 39 | parser.add_argument('-p', '--port', type=int, default=50051) 40 | args = parser.parse_args() 41 | run(get_target(args.server, args.port)) 42 | -------------------------------------------------------------------------------- /serving/grpc/python/greet_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 16 | import grpc 17 | 18 | import greet_pb2 as greet__pb2 19 | 20 | 21 | class GreeterStub(object): 22 | # missing associated documentation comment in .proto file 23 | pass 24 | 25 | def __init__(self, channel): 26 | """Constructor. 27 | 28 | Args: 29 | channel: A grpc.Channel. 30 | """ 31 | self.SayHello = channel.unary_unary( 32 | '/Greet.Greeter/SayHello', 33 | request_serializer=greet__pb2.HelloRequest.SerializeToString, 34 | response_deserializer=greet__pb2.HelloReply.FromString, 35 | ) 36 | 37 | 38 | class GreeterServicer(object): 39 | # missing associated documentation comment in .proto file 40 | pass 41 | 42 | def SayHello(self, request, context): 43 | # missing associated documentation comment in .proto file 44 | pass 45 | context.set_code(grpc.StatusCode.UNIMPLEMENTED) 46 | context.set_details('Method not implemented!') 47 | raise NotImplementedError('Method not implemented!') 48 | 49 | 50 | def add_GreeterServicer_to_server(servicer, server): 51 | rpc_method_handlers = { 52 | 'SayHello': grpc.unary_unary_rpc_method_handler( 53 | servicer.SayHello, 54 | request_deserializer=greet__pb2.HelloRequest.FromString, 55 | response_serializer=greet__pb2.HelloReply.SerializeToString, 56 | ), 57 | } 58 | generic_handler = grpc.method_handlers_generic_handler( 59 | 'Greet.Greeter', rpc_method_handlers) 60 | server.add_generic_rpc_handlers((generic_handler,)) 61 | -------------------------------------------------------------------------------- /serving/grpc/python/greet_server.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import argparse 16 | from concurrent import futures 17 | import logging 18 | from time import sleep 19 | 20 | import grpc 21 | 22 | import greet_pb2 23 | import greet_pb2_grpc 24 | 25 | _ONE_DAY_IN_SECONDS = 60 * 60 * 24 26 | 27 | 28 | class Greeter(greet_pb2_grpc.GreeterServicer): 29 | def SayHello(self, request, context): 30 | logging.info(f'Request name[{request.name}]') 31 | return greet_pb2.HelloReply(message=f'Hello {request.name}') 32 | 33 | 34 | def serve(port): 35 | logging.info(f'Starting gRPC server on port[{port}]') 36 | server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) 37 | server.add_insecure_port(f'[::]:{port}') 38 | greet_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server) 39 | 40 | server.start() 41 | try: 42 | while True: 43 | sleep(_ONE_DAY_IN_SECONDS) 44 | except KeyboardInterrupt: 45 | server.stop(0) 46 | 47 | 48 | if __name__ == '__main__': 49 | logging.basicConfig(level=logging.INFO) 50 | parser = argparse.ArgumentParser() 51 | parser.add_argument('-p', '--port', type=int, default=50051) 52 | args = parser.parse_args() 53 | serve(args.port) 54 | -------------------------------------------------------------------------------- /serving/grpc/python/protos/greet.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | syntax = "proto3"; 15 | 16 | package Greet; 17 | 18 | service Greeter { 19 | rpc SayHello (HelloRequest) returns (HelloReply) {} 20 | } 21 | 22 | message HelloRequest { 23 | string name = 1; 24 | } 25 | 26 | message HelloReply { 27 | string message = 1; 28 | } 29 | -------------------------------------------------------------------------------- /serving/grpc/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: grpc-greeter 18 | namespace: default 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - image: docker.io/meteatamel/grpc-greeter:v1 24 | ports: 25 | - name: h2c 26 | containerPort: 8080 27 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "helloworld.dll"] 27 | 28 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace helloworld 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:21700", 7 | "sslPort": 44392 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "helloworld": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /serving/helloworld/csharp/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Hosting; 17 | using Microsoft.AspNetCore.Http; 18 | using Microsoft.Extensions.DependencyInjection; 19 | using Microsoft.Extensions.Hosting; 20 | 21 | namespace helloworld 22 | { 23 | public class Startup 24 | { 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | } 28 | 29 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 30 | { 31 | if (env.IsDevelopment()) 32 | { 33 | app.UseDeveloperExceptionPage(); 34 | } 35 | 36 | app.UseRouting(); 37 | 38 | app.UseEndpoints(endpoints => 39 | { 40 | endpoints.MapGet("/", async context => 41 | { 42 | var target = Environment.GetEnvironmentVariable("TARGET") ?? "World"; 43 | await context.Response.WriteAsync($"Hello {target}!!!\n"); 44 | }); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /serving/helloworld/csharp/helloworld.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /serving/helloworld/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /serving/helloworld/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | 17 | from flask import Flask 18 | 19 | app = Flask(__name__) 20 | 21 | 22 | @app.route('/') 23 | def hello_world(): 24 | target = os.environ.get('TARGET', 'World') 25 | return f'Hello {target}\n' 26 | 27 | 28 | if __name__ == '__main__': 29 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 30 | -------------------------------------------------------------------------------- /serving/helloworld/service-local.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld-local 18 | namespace: default 19 | labels: 20 | serving.knative.dev/visibility: cluster-local 21 | spec: 22 | template: 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/helloworld:v1 26 | env: 27 | - name: TARGET 28 | value: "v1" 29 | -------------------------------------------------------------------------------- /serving/helloworld/service-v1-pinned.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | metadata: 22 | name: helloworld-v1 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/helloworld:v1 26 | env: 27 | - name: TARGET 28 | value: "v1" 29 | traffic: 30 | - tag: current 31 | revisionName: helloworld-v1 32 | percent: 100 33 | - tag: latest 34 | latestRevision: true 35 | percent: 0 -------------------------------------------------------------------------------- /serving/helloworld/service-v1.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - image: docker.io/meteatamel/helloworld:v1 24 | env: 25 | - name: TARGET 26 | value: "v1" -------------------------------------------------------------------------------- /serving/helloworld/service-v1v4-split.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | metadata: 22 | name: helloworld-v4 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/helloworld:v1 26 | env: 27 | - name: TARGET 28 | value: "v4" 29 | traffic: 30 | - tag: current 31 | revisionName: helloworld-v1 32 | percent: 50 33 | - tag: candidate 34 | revisionName: helloworld-v4 35 | percent: 50 36 | - tag: latest 37 | latestRevision: true 38 | percent: 0 -------------------------------------------------------------------------------- /serving/helloworld/service-v2.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - image: docker.io/meteatamel/helloworld:v1 24 | env: 25 | - name: TARGET 26 | value: "v2" 27 | -------------------------------------------------------------------------------- /serving/helloworld/service-v3.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | spec: 22 | containers: 23 | - image: docker.io/meteatamel/helloworld:v3 24 | env: 25 | - name: TARGET 26 | value: "v3" 27 | -------------------------------------------------------------------------------- /serving/helloworld/service-v4.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: helloworld 18 | namespace: default 19 | spec: 20 | template: 21 | metadata: 22 | name: helloworld-v4 23 | spec: 24 | containers: 25 | - image: docker.io/meteatamel/helloworld:v1 26 | env: 27 | - name: TARGET 28 | value: "v4" 29 | traffic: 30 | - tag: current 31 | revisionName: helloworld-v1 32 | percent: 100 33 | - tag: latest 34 | latestRevision: true 35 | percent: 0 -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "sleepingservice.dll"] -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace sleepingservice 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:21700", 7 | "sslPort": 44392 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "sleepingservice": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System.Threading; 15 | using Microsoft.AspNetCore.Builder; 16 | using Microsoft.AspNetCore.Hosting; 17 | using Microsoft.AspNetCore.Http; 18 | using Microsoft.Extensions.DependencyInjection; 19 | using Microsoft.Extensions.Hosting; 20 | 21 | namespace sleepingservice 22 | { 23 | public class Startup 24 | { 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | } 28 | 29 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 30 | { 31 | if (env.IsDevelopment()) 32 | { 33 | app.UseDeveloperExceptionPage(); 34 | } 35 | 36 | app.UseRouting(); 37 | 38 | app.UseEndpoints(endpoints => 39 | { 40 | endpoints.MapGet("/", async context => 41 | { 42 | Thread.Sleep(4000); 43 | await context.Response.WriteAsync("Hello World!"); 44 | }); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /serving/sleepingservice/csharp/sleepingservice.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /serving/sleepingservice/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /serving/sleepingservice/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | from time import sleep 17 | 18 | from flask import Flask 19 | 20 | app = Flask(__name__) 21 | 22 | 23 | @app.route('/') 24 | def hello_world(): 25 | sleep(4) 26 | return 'Hello World!' 27 | 28 | 29 | if __name__ == '__main__': 30 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 31 | -------------------------------------------------------------------------------- /serving/sleepingservice/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: sleepingservice 18 | namespace: default 19 | spec: 20 | template: 21 | metadata: 22 | annotations: 23 | # Default: Knative concurrency-based autoscaling with 24 | # 100 requests in-flight per pod. 25 | autoscaling.knative.dev/class: kpa.autoscaling.knative.dev 26 | autoscaling.knative.dev/metric: concurrency 27 | # Changed target to 1 to showcase autoscaling 28 | autoscaling.knative.dev/target: "1" 29 | 30 | # Alternative: Kubernetes CPU-based autoscaling. 31 | # autoscaling.knative.dev/class: hpa.autoscaling.knative.dev 32 | # autoscaling.knative.dev/metric: cpu 33 | 34 | # Disable scale to zero with a minScale of 1. 35 | autoscaling.knative.dev/minScale: "1" 36 | # Limit max scaling to 5 pods. 37 | autoscaling.knative.dev/maxScale: "6" 38 | spec: 39 | containers: 40 | - image: docker.io/meteatamel/sleepingservice:v1 41 | -------------------------------------------------------------------------------- /serving/twilio/csharp/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Microsoft's official build .NET image. 2 | # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ 3 | FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build 4 | WORKDIR /app 5 | 6 | # Install production dependencies. 7 | # Copy csproj and restore as distinct layers. 8 | COPY *.csproj ./ 9 | RUN dotnet restore 10 | 11 | # Copy local code to the container image. 12 | COPY . ./ 13 | WORKDIR /app 14 | 15 | # Build a release artifact. 16 | RUN dotnet publish -c Release -o out 17 | 18 | 19 | # Use Microsoft's official runtime .NET image. 20 | # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ 21 | FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine AS runtime 22 | WORKDIR /app 23 | COPY --from=build /app/out ./ 24 | 25 | # Run the web service on container startup. 26 | ENTRYPOINT ["dotnet", "twiliosample.dll"] -------------------------------------------------------------------------------- /serving/twilio/csharp/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using System; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.Hosting; 17 | 18 | namespace twiliosample 19 | { 20 | public class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | CreateHostBuilder(args).Build().Run(); 25 | } 26 | 27 | public static IHostBuilder CreateHostBuilder(string[] args) 28 | { 29 | string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; 30 | string url = String.Concat("http://0.0.0.0:", port); 31 | 32 | return Host.CreateDefaultBuilder(args) 33 | .ConfigureWebHostDefaults(webBuilder => 34 | { 35 | webBuilder.UseStartup().UseUrls(url); 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /serving/twilio/csharp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:62259", 7 | "sslPort": 44342 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "twiliosample": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /serving/twilio/csharp/SmsController.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using Microsoft.AspNetCore.Mvc; 15 | using Twilio.AspNet.Common; 16 | using Twilio.AspNet.Core; 17 | using Twilio.TwiML; 18 | 19 | namespace twiliosample 20 | { 21 | public class SmsController : TwilioController 22 | { 23 | [HttpGet] 24 | public TwiMLResult Index(SmsRequest incomingMessage) 25 | { 26 | var messagingResponse = new MessagingResponse(); 27 | messagingResponse.Message("The Knative copy cat says: " + incomingMessage.Body); 28 | return TwiML(messagingResponse); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /serving/twilio/csharp/Startup.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | using Microsoft.AspNetCore.Builder; 15 | using Microsoft.AspNetCore.Hosting; 16 | using Microsoft.Extensions.DependencyInjection; 17 | using Microsoft.Extensions.Hosting; 18 | 19 | namespace twiliosample 20 | { 21 | public class Startup 22 | { 23 | public void ConfigureServices(IServiceCollection services) 24 | { 25 | services.AddControllers(); 26 | } 27 | 28 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 29 | { 30 | if (env.IsDevelopment()) 31 | { 32 | app.UseDeveloperExceptionPage(); 33 | } 34 | 35 | app.UseRouting(); 36 | 37 | app.UseEndpoints(endpoints => 38 | { 39 | endpoints.MapDefaultControllerRoute(); 40 | }); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /serving/twilio/csharp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /serving/twilio/csharp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /serving/twilio/csharp/twiliosample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /serving/twilio/python/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use an official lightweight Python image. 2 | # https://hub.docker.com/_/python 3 | FROM python:3.7-slim 4 | 5 | # Install production dependencies. 6 | RUN pip install Flask gunicorn twilio 7 | 8 | # Copy local code to the container image. 9 | WORKDIR /app 10 | COPY . . 11 | 12 | # Run the web service on container startup. Here we use the gunicorn 13 | # webserver, with one worker process and 8 threads. 14 | # For environments with multiple CPU cores, increase the number of workers 15 | # to be equal to the cores available. 16 | CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app 17 | -------------------------------------------------------------------------------- /serving/twilio/python/app.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import os 16 | 17 | from flask import Flask, request 18 | from twilio.twiml.messaging_response import MessagingResponse 19 | 20 | app = Flask(__name__) 21 | 22 | 23 | @app.route('/sms', methods=['GET']) 24 | def sms_reply(): 25 | body = request.values.get('Body', '-') 26 | resp = MessagingResponse() 27 | resp.message(f'The Knative copy cat says: {body}') 28 | return str(resp) 29 | 30 | 31 | if __name__ == '__main__': 32 | app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080))) 33 | -------------------------------------------------------------------------------- /serving/twilio/service.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | apiVersion: serving.knative.dev/v1 15 | kind: Service 16 | metadata: 17 | name: twilio 18 | namespace: default 19 | spec: 20 | template: 21 | metadata: 22 | annotations: 23 | autoscaling.knative.dev/minScale: "1" 24 | spec: 25 | containers: 26 | - image: docker.io/meteatamel/twilio:v1 27 | -------------------------------------------------------------------------------- /setup/README.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | These are the steps to set Knative and its dependencies. 4 | 5 | ## Configuration 6 | 7 | Edit [config](config) file for your setup. 8 | 9 | ## Create a GKE cluster 10 | 11 | ```sh 12 | ./create-gke-cluster 13 | ``` 14 | 15 | ## Install Istio & Knative Serving 16 | 17 | ```sh 18 | ./install-serving 19 | ``` 20 | 21 | ## Install Knative Eventing 22 | 23 | ```sh 24 | ./install-eventing 25 | ``` 26 | 27 | You probably need a Broker in the default namespace with Knative Eventing. 28 | You can follow instructions in [Broker Creation](../docs/brokercreation.md) page to do that. 29 | 30 | ## Install Knative GCP 31 | 32 | If you intend to read Google Cloud events, install [Knative GCP](https://github.com/google/knative-gcp) components. 33 | 34 | There are 2 ways of setting up authentication in Knative GCP: 35 | 36 | 1. Kubernetes secrets 37 | 2. Workload identity (recommended) 38 | 39 | Pick one of the mechanisms and use appropriate scripts. 40 | 41 | Install Knative GCP: 42 | 43 | ```sh 44 | # Kubernetes secrets 45 | ./install-knative-gcp 46 | 47 | # Workload identity 48 | ./install-knative-gcp workload 49 | ``` 50 | 51 | Configure a Pub/Sub enabled Service Account for Data Plane: 52 | 53 | ```sh 54 | # Kubernetes secrets 55 | ./install-dataplane-serviceaccount 56 | 57 | # Workload identity 58 | ./install-dataplane-serviceaccount workload 59 | ``` 60 | 61 | ## Install Tekton Pipelines 62 | 63 | Install Tekton Pipelines, if you want to run build samples: 64 | 65 | ```sh 66 | ./install-tekton 67 | ``` 68 | 69 | ------- 70 | 71 | Thanks to [Mark Chmarny](https://twitter.com/mchmarny) for the initial scripts 72 | and [James Ward](https://twitter.com/_JamesWard) for HTTPS configuration 73 | instructions. 74 | -------------------------------------------------------------------------------- /setup/check-versions: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -v 4 | 5 | # Check Kubernetes version 6 | kubectl version --short | grep server -i 7 | 8 | # Check Istio version by looking at the image version 9 | kubectl get pod -l app=istio-ingressgateway -n istio-system -oyaml | grep istio/proxyv2 -m 1 10 | 11 | # Check Knative Serving version 12 | kubectl get namespace knative-serving -o 'go-template={{index .metadata.labels "serving.knative.dev/release"}}' 13 | 14 | # Check Knative Eventing version 15 | kubectl get namespace knative-eventing -o 'go-template={{index .metadata.labels "eventing.knative.dev/release"}}' 16 | 17 | # Check Knative-GCP version 18 | kubectl get namespace cloud-run-events -o 'go-template={{index .metadata.labels "events.cloud.google.com/release"}}' 19 | 20 | # Check Tekton version 21 | kubectl get pod -l app=tekton-pipelines-controller -n tekton-pipelines -o jsonpath='{.items[*].metadata.labels.version}' -------------------------------------------------------------------------------- /setup/config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export KNATIVE_SERVING_VERSION="1.0.0" 4 | 5 | export KNATIVE_EVENTING_VERSION="1.0.0" 6 | 7 | export KNATIVE_GCP_VERSION="0.23.0" 8 | 9 | export TEKTON_VERSION="0.22.0" 10 | 11 | export PROJECT_ID="knative-atamel" 12 | 13 | export CLUSTER_NAME="knative-100" 14 | 15 | export CLUSTER_REGION="europe-west1" 16 | 17 | export CLUSTER_ZONE="${CLUSTER_REGION}-b" 18 | 19 | export CLUSTER_START_NODE_SIZE=3 20 | 21 | export CLUSTER_MAX_NODE_SIZE=10 22 | 23 | export CLUSTER_NODE_MACHINE_TYPE="n1-standard-4" 24 | 25 | export CLUSTER_MASTER_VERSION="latest" -------------------------------------------------------------------------------- /setup/configure-https: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -v 4 | 5 | DIR="$(dirname "$0")" 6 | . "${DIR}/config" 7 | 8 | # FIXME: Does not work 100% yet. 9 | 10 | # Configure HTTPS with Knative Serving 11 | # Ref: https://knative.dev/docs/serving/using-a-tls-cert/ 12 | 13 | # Install cert manager 14 | # Ref: https://cert-manager.io/docs/installation/kubernetes/ 15 | kubectl apply --validate=false -f \ 16 | "https://github.com/jetstack/cert-manager/releases/download/v${KNATIVE_VERSION}/cert-manager.yaml" 17 | 18 | kubectl wait --for=condition=Available -n cert-manager deployments/cert-manager-webhook 19 | 20 | # ClusterIssuer for HTTP-01 challenge 21 | # Ref: https://knative.dev/docs/serving/using-auto-tls/ 22 | kubectl apply -f - <