未验证 提交 447f511b 编写于 作者: Y Young Bu Park 提交者: GitHub

Revise dapr development doc (#587)

Revised Dapr development doc
Removed duplicated docs
上级 f6cc3d7b
## Development
* [Development Guide](./development.md)
* [Setup Dapr Development environment](./setup-dapr-development-env.md) : Provide Dapr runtime development setup guide
* [Developing Dapr](./developing-dapr.md) : Provide how to develop Dapr runtime from cloning branch
# Development Guide
This document helps you get started developing Dapr. If you find any problem while following this guide, please create a Pull Request to update this document.
## Prerequisites
### Linux and MacOS
1. The Go language environment [(instructions)](https://golang.org/doc/install#tarball).
* Make sure that your GOPATH and PATH are configured correctly
```bash
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
```
2. [Delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) for Debugging
### Windows
1. The Go language environment [(instructions)](https://golang.org/doc/install#windows).
Make sure that your GOPATH and PATH are configured correctly - You may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.
```
GOPATH=c:\go
PATH=%GOPATH%\bin;...
```
2. [Delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) for Debugging
3. [Git for Windows](https://gitforwindows.org)
* Install [Git with chocolatey](https://chocolatey.org/packages/git) and ensure that Git bin directory is in PATH environment variable
```bash
choco install git -y --package-parameters="/GitAndUnixToolsOnPath /WindowsTerminal /NoShellIntegration"
```
4. [MinGW](http://www.mingw.org/)
Install [MinGW with chocolatey](https://chocolatey.org/packages/mingw) and ensure that MinGW bin directory is in PATH environment variable
```bash
choco install mingw
```
## Developing Dapr
## Clone the repo
......@@ -44,7 +8,7 @@ mkdir -p github.com/dapr/dapr
git clone https://github.com/dapr/dapr.git github.com/dapr/dapr
```
## Build the Dapr binary
## Build the Dapr
You can build dapr binaries via `make` tool and find the binaries in `./dist/{os}_{arch}/release/`.
......@@ -63,7 +27,7 @@ make build
make build GOOS=linux GOARCH=amd64
```
## Run tests
## Run unit-test
```bash
make test
......@@ -78,14 +42,14 @@ This section introduces how to start debugging with Delve CLI. Please see [Delve
### Start with debugger
```bash
$ cd $GOPATH/src/github.com/dapr/dapr/daprd
$ cd $GOPATH/src/github.com/dapr/dapr/cmd/daprd
$ dlv debug .
Type 'help' for list of commands.
(dlv) break main.main
(dlv) continue
```
### Attach Debugger to running binary
### Attach Debugger to running process
This is useful to debug dapr when the process is running.
......@@ -98,6 +62,11 @@ $ make DEBUG=1 build
2. Create component yaml file under `./dist/{os}_{arch}/debug/components` e.g. statstore component yaml
3. Run dapr runtime
```bash
$ /dist/{os}_{arch}/debug/daprd
```
4. Find the process id and attach the debugger
```bash
......@@ -108,11 +77,90 @@ $ dlv attach [pid]
```bash
# Specify the package that you want to test
# e.g. debuggin ./pkg/actors
# e.g. debugging ./pkg/actors
$ dlv test ./pkg/actors
```
### Developing Dapr and Deploying to a Cluster
Please see the following for steps on how to make a simple change to Dapr and then on how deploy them to a cluster:
- [Local cluster using Minikube](./setup_minikube.md)
- [Non-local cluster using AKS](./setup_aks.md)
## Developing on Kubernetes environment
### Setting environment variable
* **DAPR_REGISTRY** : should be set to docker.io/<your_docker_hub_account>.
* **DAPR_TAG** : should be set to whatever value you wish to use for a container image tag.
**Linux/macOS**
```
export DAPR_REGISTRY=docker.io/<your_docker_hub_account>
export DAPR_TAG=dev
```
**Windows**
```
set DAPR_REGISTRY=docker.io/<your_docker_hub_account>
set DAPR_TAG=dev
```
### Building the Container Image
Run the appropriate command below to build the container image.
**Linux/macOS**
```
make docker-build
```
**Windows**
```
mingw32-make.exe docker-build
```
## Push the Container Image
To push the image to DockerHub, run:
**Linux/macOS**
```
make docker-push
```
**Windows**
```
mingw32-make.exe docker-push
```
## Deploy Dapr With Your Changes
Now we'll deploy Dapr with your changes.
If you deployed Dapr to your cluster before, delete it now using:
```
helm del --purge dapr
```
and run the following to deploy your change to your Kubernetes cluster:
**Linux/macOS**
```
make docker-deploy-k8s
```
**Windows**
```
mingw32-make.exe docker-deploy-k8s
```
## Verifying your changes
Once Dapr is deployed, print the Dapr pods:
```
kubectl.exe 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
```
## Developing Dapr and Deploying to a Cluster
This guide will walk through the steps to make a small change to Dapr, then deploy the change to your cluster.
This guide assumes you have a local or AKS cluster set up. If you haven't done this, follow the appropriate link:
- [Local Minikube cluster](./setup_minikube.md)
- [AKS cluster](/setup_aks.md)
1. If you haven't already cloned the code, clone https://github.com/dapr/dapr.
2. Open the following file and add a log statement of your choice in main(). We'll look for this log statement after we deploy our changes to confirm everything worked.
```
[location you cloned to]/dapr/dapr/cmd/operator/main.go
```
Save the file.
3. Go up two levels to
```
[location you cloned to]/dapr/dapr
```
and build. We're going to build for a Linux container.
For Linux or macOS:
```
make build GOOS=linux GOARCH=amd64
```
For Windows:
```
mingw32-make.exe build GOOS=linux GOARCH=amd64
```
For all environments, you should see the built binaries in ./dist/linux_amd64/release.
4. We're going to now build a container with our changes and push it to Docker Hub. If you haven't created a Docker Hub account yet, create one now at https://hub.docker.com.
After creating the account, log into Docker Hub:
```
docker login
```
5. Now set the following environment varariables, which will be used by make:
- `DAPR_REGISTRY` should be set to docker.io/[your Docker Hub account name].
- `DAPR_TAG` should be set to whatever value you wish to use for a container image tag.
Linux/macOS:
```
export DAPR_REGISTRY=docker.io/[your Docker Hub account name]
export DAPR_TAG=dev1
```
Windows:
```
set DAPR_REGISTRY=docker.io/[your Docker Hub account name]
set DAPR_TAG=dev1
```
## Building the Container Image
From
```
[location you cloned to]/daprscore/dapr
```
Run the appropriate command below to build the container image.
For Linux/macOS, you'll have to configure docker to run without sudo for this to work, because of the environment variables. See the following on how to configure this: https://docs.docker.com/install/linux/linux-postinstall/
Linux/macOS:
```
make docker-build
```
Windows:
```
mingw32-make.exe docker-build
```
For example, if our environment variables are set like so:
- `DAPR_REGISTRY=docker.io/user123`
- `DAPR_TAG=dev`
The command above will create an image with repo `user123/dapr` (note `dapr` is added) and tag `dev`.
You should see the new image if you run:
```
docker images
```
## Push the Container Image
To push the image to DockerHub, run:
Linux/macOS:
```
make docker-push
```
Windows:
```
mingw32-make.exe docker-push
```
## Deploy Dapr With Your Changes
Now we'll deploy Dapr with your changes.
If you deployed Dapr to your cluster before, delete it now using:
```
helm del --purge dapr
```
Then go to
```
<repo root>/dapr/dapr/charts/dapr-operator
```
and run the following to deploy:
Linux/macOS:
```
make docker-deploy-k8s
```
Windows:
```
mingw32-make.exe docker-deploy-k8s
```
## Verifying your changes
Once Dapr is deployed, print the Dapr pods:
```
kubectl.exe get po -n dapr-system
```
Find the one with a name starting with dapr-operator (e.g. dapr-operator-123-456), and run
```
kubectl logs [your dapr-operator pod name]
```
you should see the print statement you added.
\ No newline at end of file
# Setup Dapr development environment
This document helps you get started developing Dapr. If you find any problem while following this guide, please create a Pull Request to update this document.
## Docker environment
1. Install [Docker](https://docs.docker.com/install/)
> For Linux, you'll have to configure docker to run without sudo for this to work, because of the environment variables. See the following on how to configure [this](https://docs.docker.com/install/linux/linux-postinstall/).
2. Create your [Docker Hub account](https://hub.docker.com)
## Golang dev environment
### Linux and MacOS
1. The Go language environment [(instructions)](https://golang.org/doc/install#tarball).
* Make sure that your GOPATH and PATH are configured correctly
```bash
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
```
2. [Delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) for Debugging
### Windows
1. The Go language environment [(instructions)](https://golang.org/doc/install#windows).
Make sure that your GOPATH and PATH are configured correctly - You may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.
```
GOPATH=c:\go
PATH=%GOPATH%\bin;...
```
2. [Delve](https://github.com/go-delve/delve/tree/master/Documentation/installation) for Debugging
3. [Git for Windows](https://gitforwindows.org)
* Install [Git with chocolatey](https://chocolatey.org/packages/git) and ensure that Git bin directory is in PATH environment variable
```bash
choco install git -y --package-parameters="/GitAndUnixToolsOnPath /WindowsTerminal /NoShellIntegration"
```
4. [MinGW](http://www.mingw.org/)
Install [MinGW with chocolatey](https://chocolatey.org/packages/mingw) and ensure that MinGW bin directory is in PATH environment variable
```bash
choco install mingw
```
## Setup Kubernetes development environment
For development environment, you must install helm client and tiller.
1. [Setup Minikube for Local environment](https://github.com/dapr/docs/blob/master/getting-started/cluster/setup-minikube.md)
2. [Setup Azure Kubernetes Service](https://github.com/dapr/docs/blob/master/getting-started/cluster/setup-aks.md)
# Set Up an Azure Kubernetes Service Cluster
## Prerequisites
- Install Docker
- Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- If on Windows,
- Virtualization needs to be enabled in BIOS
- Hyper-V needs to be (enabled)[https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v]
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)
## Deploy an Azure Kubernetes Service Cluster
To set up an AKS cluster, please follow these instructions:
https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough
In addition, make sure the cluster is RBAC enabled.
When finished run the following:
```
az aks get-credentials -n <cluster-name> -g <resource-group>
```
It should be pointing at your AKS cluster:
```
kubectl cluster-info
```
## Install Helm and Deploy Tiller
1. Install Helm if you haven't already.
Linux/macOS:
```
sudo snap install helm --classic
```
Windows:
See this: https://helm.sh/docs/using_helm/#from-chocolatey-or-scoop-windows
Create the tiller service account
```
kubectl apply -f https://raw.githubusercontent.com/Azure/helm-charts/master/docs/prerequisities/helm-rbac-config.yaml
```
2. Run the following to install tiller into the cluster
```
helm init --service-account tiller --history-max 200
```
3. To confirm the step above worked, you should see a pod with a name starting with "tiller-deploy", for example "tiller-deploy-7695cecfb7-dln4h"
```
kubectl get pods -n kube-system
```
If you do *not* see one, try running these two commands:
```
kubectl create serviceaccount -n kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
```
Then repeat step 2.
4. If you still don't see a tiller pod, you may have to debug your environment. Try running the following, and look for errors under "Events" at the bottom of the output:
```
kubectl describe deployment tiller-deploy --namespace kube-system
```
Your cluster is now ready! Please see [Modify Dapr and Deploy to the Cluster](./edit_and_deploy.md) to deploy a change to the cluster.
\ No newline at end of file
# Set Up a Minikube Cluster
## Prerequisites
Install
- Install Docker
- Install [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- If on Windows,
- Virtualization needs to be enabled in BIOS
- Hyper-V needs to be (enabled)[https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v]
## Start the Minikube Cluster
1. To start the cluster, type the following:
Linux/macOS:
```
minikube start --vm-driver=kvm2 --cpus=4 --memory=4096 --kubernetes-version=1.14.6 --extra-config=apiserver.authorization-mode=RBAC
```
Windows:
```
minikube start --vm-driver=hyperv --cpus=4 --memory=4096 --kubernetes-version=1.14.6 --extra-config=apiserver.authorization-mode=RBAC
```
*Note: if you stop the cluster, you must start it again with the args above. A common mistake is to start it again with a shortened line:*
```
[wrong] minikube start
```
2. In some environments, the args above may not configure RBAC correctly. The following steps will set it correctly if that happens.
Create clusterrole.yaml somewhere locally with these contents.:
```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: cluster-admin
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- nonResourceURLs:
- '*'
verbs:
- '*'
```
3. Now run the command below to apply it
```
kubectl create -f clusterrole.yaml
```
You may get `AlreadyExists`. That is ok.
## Install Helm and Deploy Tiller
1. [Install Helm](https://helm.sh/docs/using_helm/#installing-the-helm-client) if you haven't already:
2. Create the tiller service account
```
kubectl apply -f https://raw.githubusercontent.com/Azure/helm-charts/master/docs/prerequisities/helm-rbac-config.yaml
```
3. Run the following to install tiller into the cluster
```
helm init --service-account tiller --history-max 200
```
4. To confirm the step above worked, you should see a pod with a name starting with "tiller-deploy", for example "tiller-deploy-7695cecfb7-dln4h"
```
kubectl get pods -n kube-system
```
If you do *not* see one, try running these two commands:
```
kubectl create serviceaccount -n kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
```
Then repeat step 3.
5. If you still don't see a tiller pod, you may have to debug your environment. Try running the following, and look for errors under "Events" at the bottom of the output:
```
kubectl describe deployment tiller-deploy --namespace kube-system
```
Your Minikube cluster is now ready! Please see [Modify Daprs and Deploy to the Cluster](./edit_and_deploy.md) to deploy a local change to the cluster.
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册