Project: Dapr (App Definition and Development / Application Definition & Image Build)
File: developing-dapr.md

There are several options for getting an environment up and running for Dapr development: Using pre-configured for Dapr development is often the quickest path to get started with a development environment for Dapr. () If you are using , you can configured for Dapr development. the necessary tools and frameworks for developing Dapr on your device. Contributing to Dapr often requires working with multiple repositories at once. We recommend creating a folder for Dapr and cloning all forked repositories in that folder. For instructions on how to fork a repo, . The process is the same, just for different repositories. ```sh mkdir dapr git clone https://github.com/dapr/dapr.git dapr/dapr ``` You can build Dapr binaries with the `make` tool. On Windows, the `make` commands must be run under . These instructions also require that a `make` alias has been created for `mingw32-make.exe` according to the . When running `make`, you need to be at the root of the `dapr/dapr` repo directory, for example: `$GOPATH/src/github.com/dapr/dapr`. Once built, the release binaries will be found in `./dist/{os}{arch}/release/`, where `{os}{arch}` is your current OS and architecture. For example, running `make build` on an Intel-based macOS will generate the directory `./dist/darwin_amd64/release`. To build for your current local environment: ```sh cd dapr/dapr make build ``` To cross-compile for a different platform, use the `GOOS` and `GOARCH` environmental variables: ```sh make build GOOS=windows GOARCH=amd64 ``` For example, developers on Windows who prefer to develop in can use the Linux development environment to cross-compile binaries like `daprd.exe` that run on Windows natively. You can individually build the daprd binary: ```sh cd cmd/daprd go build -tags=allcomponents -v ./daprd ... mv daprd ~/.dapr/bin/daprd dapr version # see `Runtime version: edge` to ensure you are using the newly built binary dapr run ... # this will use the newly-built binary ``` ```sh make test ``` ```sh make check ``` This command will: format, test and lint all the code check if you forgot to `git commit` something Note: To run linter locally, please use golangci-lint version v1.51.2, otherwise you might encounter errors. You can download version v1.55.2 . We recommend using VS Code with the for your productivity. If you want to use other code editors, please refer to the list of . This section introduces how to start debugging with the Delve

Please refer to the for more details. To start the Dapr runtime with a debugger, you need to use build tags to include the components you want to debug. The following build tags are available: allcomponents - (default) includes all components in Dapr sidecar stablecomponents - includes all stable components in Dapr sidecar ```bash $ cd dapr/dapr/cmd/daprd $ dlv debug . --build-flags=--tags=allcomponents Type 'help' for list of commands. (dlv) break main.main (dlv) continue ``` This is useful to debug Dapr when the process is running. Build Dapr binaries for debugging. Use the `DEBUG=1` option to generate Dapr binaries without code optimization in `./dist/{os}_{arch}/debug/` ```bash make DEBUG=1 build ``` Create a component YAML file under `./dist/{os}_{arch}/debug/components` (for example a statestore component YAML). Start the Dapr runtime ```bash /dist/{os}_{arch}/debug/daprd ``` Find the process ID (e.g. `PID` displayed by the `ps` command for `daprd`) and attach the debugger ```bash dlv attach {PID} ``` Build the daprd binary `go build -tags=allcomponents -v` from `/cmd/daprd`. Proceed to run client code necessary for testing purposes and set break points as needed. Specify the package that you want to test when running the `dlv test`. For example, to debug the `./pkg/actors` tests: ```bash dlv test ./pkg/actors ``` DAPR_REGISTRY : should be set to `docker.io/<yourdockerhub_account>`. DAPR_TAG : should be set to whatever value you wish to use for a container image tag (`dev` is a common choice). ONLY_DAPR_IMAGE: should be set to `true` to use a single `dapr` image instead of individual images (like sentry, injector, daprd, etc.). On Linux/macOS: ```bash export DAPRREGISTRY=docker.io/<yourdockerhubaccount> export DAPR_TAG=dev ``` On Windows: ```cmd set DAPRREGISTRY=docker.io/<yourdockerhubaccount> set DAPR_TAG=dev ``` ```bash make build-linux make docker-build ``` To push the image to DockerHub, complete your `docker login` and run: ```bash make docker-push ``` Now we'll deploy Dapr with your changes. To create the dapr-system namespace: ```bash kubectl create namespace dapr-system ``` If you deployed Dapr to your cluster before, delete it now using: ```bash helm uninstall dapr -n dapr-system ``` To deploy your changes to your Kubernetes cluster: ```bash make docker-deploy-k8s ``` Once Dapr is deployed, list the Dapr pods: ```bash $ kubectl get pod -n dapr-system NAME READY STATUS RESTARTS AGE dapr-operator-86cddcfcb7-v2zjp 1/1 Running 0 4d3h dapr-placement-5d6465f8d5-pz2qt 1/1 Running 0 4d3h dapr-sidecar-injector-dc489d7bc-k2h4q 1/1 Running 0 4d3h ``` Refer to the on how to: Setting up a development environment