Update Dapr in your development environment on Windows 10

By Philippe Beraud, France

Distributed Application Runtime, a.k.a. Dapr, is a portable, event-driven runtime that makes it easy for enterprise developers to build resilient, microservice stateless and stateful applications that run on the cloud and edge and embraces the diversity of languages and developer frameworks.

As of this writing, Dapr is currently under community development in alpha phase. Dapr is thus NOT expected to be used for production workloads until its 1.0 stable release.

Consequently, you can thus expect continuous releases of new versions of the Dapr runtime as well as the Dapr Command Line Interface (CLI). And such, these releases can (potentially) introduce a series of breaking changes.

As a direct illustration, Dapr 0.4.0 has been released on February 13th 2020. As stated on the Dapr repo at https://github.com/dapr/dapr/releases, this release of Dapr not only includes new components, security improvements, API level enhancements, new CLI features, stability and bug fixes, a richer Java SDK, docs and samples updates, but it also contains breaking changes. If you're upgrading from an older version of Dapr to 0.4.0, this walkthrough will guide you through the upgrade of Dapr on your Windows 10 local machine to ensure a smooth upgrade. You know, the one where you don't get red errors on the terminal. We all hate that, right? For the sake of this walkthrough, the below assumes that you completed with an older version of Dapr, here the previous one 0.3.0, all the relevant step-by-step instructions as per: • The walkthrough Set up on Windows 10 a development environment for Dapr. -or- • The guide Understanding and leveraging the Distributed Application Runtime (Dapr) – A starter guide for developers. (This guide is part of the series New perspectives for cloud-native applications with the Open Application Model (OAM), and the Distributed Application Runtime (Dapr) available on the Microsoft Download Center (https://aka.ms/CloudNativeAppsFuture). Also ensure to check out Upgrading to Dapr 0.4.0 on the Dapr repo.

Updating Dapr CLI on Windows 10

Updating Dapr CLI locally To update Dapr CLI locally with the latest version available, perform the following steps: 1. Open a PowerShell console prompt: 2. Navigate to the previously created Dapr directory:

PS C:\> cd C:\dapr:

3. Uninstall Dapr using the CLI you currently have. For example, version 0.3.0 in our illustration:

PS C:\> dapr uninstall --all

4. Get the latest Dapr CLI:

C:\> -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex" WARNING: Dapr is detected - c:\dapr\dapr.exe CLI version: 0.3.0 Runtime version: 0.3.0 Reinstalling Dapr... Creating c:\dapr directory Downloading c:\dapr\dapr_windows_amd64.zip ... Extracting c:\dapr\dapr_windows_amd64.zip... CLI version: 0.4.1 Runtime version: 0.3.0 Clean up c:\dapr\dapr_windows_amd64.zip... Try to add c:\dapr to User Path Environment variable... Skipping to add c:\dapr to User Path - C:\Users\philber\AppData\Local\Programs\Python\Python38- 32\Scripts\;C:\Users\philber\AppData\Local\Programs\Python\Python38- 32\;C:\Users\philber\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\philber\AppDa ta\Local\Programs\Python\Python37\;C:\Users\philber\AppData\Local\Microsoft\WindowsApps;C:\ Users\philber\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\philber\AppData\Local\GitHubDesktop\bin;c:\dapr;C:\Users\philber\go\bin;C :\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin;C:\Users\philber\AppData\Local \Microsoft\WindowsApps;C:\Users\philber\AppData\Local\Programs\Azure Data Studio\bin;C:\Program Files\Multipass\bin;C:\Users\philber\AppData\Roaming\;

Dapr CLI is installed successfully. To get started with Dapr, please visit https://github.com/dapr/docs/tree/master/getting- started . Ensure that Docker Desktop is set to Linux containers mode when you run Dapr in self hosted mode.

Updating Dapr CLI on WSL2 If you previously opted to configure WSL2 along with Docker Desktop WSL2 backend, perform the following steps: 1. From your Windows 10 local machine, open a Windows command line prompt. 2. List the installed Linux distros:

C:\> wsl -l

3. Open a Bash terminal console on the installed Linux distro integrated with Docker Desktop.

For example, Ubuntu-18.04 in our illustration:

C:\> wsl -d Ubuntu-18.04

4. Uninstall Dapr using the CLI you currently have. For example, version 0.3.0 in our illustration:

$ dapr uninstall --all

5. Get the latest Dapr CLI:

$ cd /usr/local/bin $ wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash Your system is linux_amd64

Dapr CLI is detected: CLI version: 0.3.0 Runtime version: 0.3.0 Reinstalling Dapr CLI - /usr/local/bin/dapr...

Downloading https://github.com/dapr/cli/releases/download/v0.4.1/dapr_linux_amd64.tar.gz ... tar: dapr: time stamp 2020-02-14 07:39:09 is 26206.8134531 s in the future [sudo] password for philber: dapr installed into /usr/local/bin successfully. CLI version: 0.4.1 Runtime version: 0.3.0

To get started with Dapr, please visit https://github.com/dapr/docs/tree/master/getting- started

So let’s new update the Dapr runtime.

Updating the Dapr runtime

Updating Dapr runtime in standalone mode locally Perform the following steps: 1. Open a PowerShell console as an Administrator. 2. Run the following command:

PS C:\> dapr init Making the jump to hyperspace... Downloading binaries and setting up components... Installing Dapr to c:\dapr Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting- started

Wait for the update to complete, and you're good to go! You are now running the new version of Dapr, here version 0.4.0. To see the various commands it supports, run the following command:

PS C:\> dapr help

______/ /______/ __ / __ '/ __ \/ ___/ / /_/ / /_/ / /_/ / / \__,_/\__,_/ .___/_/ /_/

======A serverless runtime for hyperscale, distributed systems

Usage: dapr [command]

Available Commands: components List all Dapr components configurations List all Dapr configurations help Help about any command init Setup dapr in or Standalone modes invoke Invokes a Dapr app with an optional payload (deprecated, use invokePost) invokeGet Issue HTTP GET to Dapr app invokePost Issue HTTP POST to Dapr app with an optional payload list List all Dapr instances logs Gets Dapr sidecar logs for an app in Kubernetes mtls Check if mTLS is enabled in a Kubernetes cluster publish Publish an event to multiple consumers run Launches Dapr and your app side by side stop Stops a running Dapr instance and its associated app uninstall Removes a Dapr installation

Flags: -h, --help help for dapr

Use "dapr [command] --help" for more information about a command.

Note the new command mtls with the newly introduced supported of automatic mTLS between Dapr instances.

You can uninstall Dapr if you want to:

PS C:\> dapr uninstall

Updating Dapr runtime in standalone mode in WSL2 Conversely, from the Bash terminal console, run the following commands:

$ sudo dapr init ⌛ Making the jump to hyperspace... ↘ ↘ Downloading binaries and setting up components... Installing Dapr to /usr/local/bin ✅ Downloading binaries and setting up components... ✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting- started

Likewise, wait for the update to complete. You are now running the new version of Dapr, here version 0.4.0.

To uninstall Dapr if you want to, run the following commands:

$ dapr uninstall

Verifying Dapr runtime on a Kubernetes cluster with Dapr CLI Installing Dapr runtime with Dapr CLi is intended for a Dev/Test setup. The default namespace on a Kubernetes cluster will indeed be used. To now verify the installation of Dapr runtime with Dapr CLI, perform the following steps: 1. Connect to your cluster environment. See section § Connecting to a Kubernetes cluster of the walkthrough Set up on Windows 10 a development environment for Dapr. 2. From the Bash terminal console, if you previously installed Dapr on your Kubernetes cluster using the Dapr CLI, run the following command:

$ dapr uninstall –kubernetes

It's fine to ignore any errors that might show up. Wait until Dapr is uninstalled. 3. Now install Dapr in a dev/test setup:

$ sudo dapr init --kubernetes ⌛ Making the jump to hyperspace... ℹ️ Note: this installation is recommended for testing purposes. For production environments, please use Helm

✅ Deploying the Dapr Operator to your cluster... ✅ Success! Dapr has been installed. To verify, run 'kubectl get pods -w' in your terminal. To get started, go here: https://aka.ms/dapr-getting-started

4. Now verify that Dapr is successfully installed. Ensure that the dapr-operator, dapr- placement, dapr-sentry, and dapr-sidecar-injector pods are running in the default namespace:

$ kubectl get pods -w NAME READY STATUS RESTARTS AGE dapr-operator-67f46f77d6-62h7j 1/1 Running 0 106s dapr-placement-8565b98564-llprm 1/1 Running 0 106s dapr-sentry-77fd797cd5-xnxsx 1/1 Running 0 106s dapr-sidecar-injector-b4f8b8d68-6hrc6 1/1 Running 0 106s

Note the presence of the new dapr-sentry pod with version 0.4.0. You are now running the new version of Dapr. To uninstall Dapr if you want to, run the following command:

$ dapr uninstall --kubernetes

Verifying Dapr runtime on a Kubernetes cluster with Helm 3 Whenever you need a non-default namespace for your applications or want to test Dapr on non- default namespace, Helm, the Kubernetes package manager opening up to the world of all available charts, i.e. curated applications for Kubernetes, has to be used instead. Perform the following steps: 1. Connect to your cluster environment. See section § Connecting to a Kubernetes cluster of the walkthrough Set up on Windows 10 a development environment for Dapr. 2. From the Bash terminal console, if you previously installed Dapr using Helm 3 as per above walkthrough, run the following command:

$ helm uninstall dapr

Wait until Dapr is uninstalled, and make sure the dapr-system namespace is gone. 3. Recreate the dapr-system namespace:

$ kubectl create namespace dapr-system namespace/dapr-system created

4. Install the Dapr chart on your cluster in the (new) dapr-system namespace:

$ helm install dapr dapr/dapr --namespace dapr-system NAME: dapr LAST DEPLOYED: Tue Jan 28 02:19:10 2020 NAMESPACE: dapr-system STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Thank you for installing Dapr: High-performance, lightweight serverless runtime for cloud and edge

Your release is named dapr.

To get started with Dapr, we recommend using our samples page: https://github.com/dapr/samples

For more information on running Dapr, visit: https://dapr.io

5. Once the chart installation is complete, verify that Dapr is successfully installed. Ensure that the dapr-operator, dapr-placement, dapr-sentry, and dapr-sidecar-injector pods are running in the dapr-system namespace:

$ kubectl get pods -n dapr-system -w NAME READY STATUS RESTARTS AGE dapr-operator-7c6799878d-9rpsv 1/1 Running 0 40s dapr-placement-76c99b79bb-nlk4x 1/1 Running 0 39s dapr-sentry-5644b86cf9-6jwvq 1/1 Running 0 40s dapr-sidecar-injector-84c5578f8d-vdf2k 1/1 Running 0 39s

You can now uninstall the Dapr runtime with Helm 3:

$ helm uninstall dapr -n dapr-system release "dapr" uninstalled

Updating the Dapr samples

The Dapr samples’ repo on GitHub contains a series of samples that highlight Dapr capabilities and that are of great help to get started building applications. As of this writing, they have also been updated with in particular the addition of a seventh sample that walks you through the steps of setting up the OAuth middleware to enable OAuth authorization on a Web API without modifying the application ! ;-) To update the Dapr samples’ repo on your Windows 10 local machine, perform the following steps: 1. Open a CLI console for the targeted environment locally or in WSL2. 2. Navigate to the folder where you previously cloned the repo. 3. To retrieve remote modification and merge it to your worktree, run either the following commands: git pull origin master

-or- git pull --rebase origin master

You may get conflicts if you have made commits since you last pulled. Following is an illustration of a typical output of the first command: remote: Enumerating objects: 112, done. remote: Counting objects: 100% (112/112), done. remote: Compressing objects: 100% (63/63), done. remote: Total 112 (delta 63), reused 78 (delta 48), pack-reused 0 Receiving objects: 100% (112/112), 29.02 KiB | 358.00 KiB/s, done. Resolving deltas: 100% (63/63), completed with 21 local objects. From https://github.com/dapr/samples * branch master -> FETCH_HEAD 1b27fb7..aef9626 master -> origin/master Updating 1b27fb7..aef9626 Fast-forward .github/workflows/build.yml | 4 +- 1.hello-world/README.md | 16 +- 1.hello-world/app.js | 3 +- 2.hello-kubernetes/README.md | 17 +- 2.hello-kubernetes/deploy/node.yaml | 2 +- 2.hello-kubernetes/deploy/python.yaml | 2 +- 2.hello-kubernetes/makefile | 11 +- 2.hello-kubernetes/node/Dockerfile | 2 +- 2.hello-kubernetes/node/app.js | 63 +++ 2.hello-kubernetes/node/package.json | 16 + 2.hello-kubernetes/python/Dockerfile | 2 +- 2.hello-kubernetes/python/app.py | 23 + 3.distributed-calculator/README.md | 4 +- 3.distributed-calculator/deploy/dotnet-subtractor.yaml | 2 +- 3.distributed-calculator/deploy/go-adder.yaml | 2 +- 3.distributed-calculator/deploy/node-divider.yaml | 2 +- 3.distributed-calculator/deploy/python-multiplier.yaml | 2 +- 3.distributed-calculator/deploy/react-calculator.yaml | 2 +- 3.distributed-calculator/react-calculator/package-lock.json | 1408 ------3.distributed-calculator/react-calculator/server.js | 6 +- 3.distributed-calculator/react-calculator/yarn.lock | 933 ------4.pub-sub/deploy/node-subscriber.yaml | 2 +- 4.pub-sub/deploy/python-subscriber.yaml | 2 +- 4.pub-sub/deploy/react-form.yaml | 2 +- 4.pub-sub/react-form/package-lock.json | 1389 ------5.bindings/README.md | 2 +- 5.bindings/deploy/node.yaml | 2 +- 5.bindings/deploy/python.yaml | 2 +- 6.functions-and-keda/setup.ps1 | 24 +- 7.middleware/README.md | 96 ++++ 7.middleware/deploy/echoapp.yaml | 27 + 7.middleware/deploy/ingress.yaml | 14 + 7.middleware/deploy/oauth2.yaml | 21 + 7.middleware/deploy/pipeline.yaml | 13 + 7.middleware/echoapp/Dockerfile | 6 + 7.middleware/echoapp/app.js | 20 + 7.middleware/echoapp/package.json | 16 + 7.middleware/img/Architecture_Diagram.png | Bin 0 -> 24490 bytes 7.middleware/img/webpage.png | Bin 0 -> 2183 bytes 7.middleware/makefile | 52 ++ README.md | 15 +- 41 files changed, 440 insertions(+), 3787 deletions(-) create mode 100644 2.hello-kubernetes/node/app.js create mode 100644 2.hello-kubernetes/node/package.json create mode 100644 2.hello-kubernetes/python/app.py delete mode 100644 3.distributed-calculator/react-calculator/package-lock.json delete mode 100644 3.distributed-calculator/react-calculator/yarn.lock delete mode 100644 4.pub-sub/react-form/package-lock.json create mode 100644 7.middleware/README.md create mode 100644 7.middleware/deploy/echoapp.yaml create mode 100644 7.middleware/deploy/ingress.yaml create mode 100644 7.middleware/deploy/oauth2.yaml create mode 100644 7.middleware/deploy/pipeline.yaml create mode 100644 7.middleware/echoapp/Dockerfile create mode 100644 7.middleware/echoapp/app.js create mode 100644 7.middleware/echoapp/package.json create mode 100644 7.middleware/img/Architecture_Diagram.png create mode 100644 7.middleware/img/webpage.png create mode 100644 7.middleware/makefile

4. To view remote changes, run the following command instead: git fetch origin master

This will retrieve remote changes to local.

This concludes this walkthrough. At this stage, yous should now be good to go with the new version of Dapr and enjoy it!