2019-02-21 16:30:13 +00:00
# Contributing
2019-02-11 18:38:43 +00:00
## Before You Start
You must install and run the ArgoCD using a local Kubernetes (e.g. Docker for Desktop or Minikube) first. This will help you understand the application, but also get your local environment set-up.
Then, to get a good grounding in Go, try out [the tutorial ](https://tour.golang.org/ ).
2019-02-21 16:30:13 +00:00
## Pre-requisites
2019-02-11 18:38:43 +00:00
Install:
2018-07-27 23:51:44 +00:00
* [docker ](https://docs.docker.com/install/#supported-platforms )
* [golang ](https://golang.org/ )
* [dep ](https://github.com/golang/dep )
* [protobuf ](https://developers.google.com/protocol-buffers/ )
* [ksonnet ](https://github.com/ksonnet/ksonnet#install )
* [helm ](https://github.com/helm/helm/releases )
2018-08-15 21:54:56 +00:00
* [kustomize ](https://github.com/kubernetes-sigs/kustomize/releases )
2018-07-27 23:51:44 +00:00
* [go-swagger ](https://github.com/go-swagger/go-swagger/blob/master/docs/install.md )
* [jq ](https://stedolan.github.io/jq/ )
* [kubectl ](https://kubernetes.io/docs/tasks/tools/install-kubectl/ ).
2019-02-11 18:38:43 +00:00
* [minikube ](https://kubernetes.io/docs/setup/minikube/ ) or Docker for Desktop
2018-03-12 21:41:46 +00:00
2019-03-18 05:25:20 +00:00
Note about Kustomize:
Since Argo CD supports Kustomize v1.0 and v2.0, you will need to install both versions in order for the unit tests to run. The kustomize1 unit test expects to find a kustomize1 binary in the path. You can use this (link)[https://github.com/argoproj/argo-cd/blob/master/Dockerfile#L66-L69] to find the Kustomize1 currently used by Argo CD and modify the curl command to download the correct OS.
2018-02-18 21:16:24 +00:00
```
2019-02-11 18:38:43 +00:00
brew tap go-swagger/go-swagger
brew install go dep protobuf kubectl ksonnet/tap/ks kubernetes-helm jq go-swagger
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
Set up environment variables (e.g. is `~/.bashrc` ):
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
```
Install go dependencies:
```
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/go-swagger/go-swagger/cmd/swagger
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
2019-03-09 00:22:04 +00:00
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
2019-02-11 18:38:43 +00:00
go get -u github.com/mattn/goreman
2019-03-31 05:14:35 +00:00
go get -u gotest.tools/gotestsum
2018-02-18 21:16:24 +00:00
```
## Building
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
go get -u github.com/argoproj/argo-cd
dep ensure
make
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
The make command can take a while, and we recommend building the specific component you are working on
* `make codegen` - Builds protobuf and swagger files
2018-06-25 20:49:38 +00:00
* `make cli` - Make the argocd CLI tool
* `make server` - Make the API/repo/controller server
* `make argocd-util` - Make the administrator's utility, used for certain tasks such as import/export
2018-03-12 21:41:46 +00:00
2019-02-11 18:38:43 +00:00
## Running Tests
2018-07-30 23:13:54 +00:00
2019-02-11 18:38:43 +00:00
To run unit tests:
2018-07-30 23:13:54 +00:00
```
2019-02-11 18:38:43 +00:00
make test
2018-07-30 23:13:54 +00:00
```
2019-02-11 18:38:43 +00:00
To run e2e tests:
```
make test-e2e
```
2018-03-12 21:41:46 +00:00
2019-02-11 18:38:43 +00:00
## Running Locally
2018-03-12 21:41:46 +00:00
2019-02-11 18:38:43 +00:00
It is much easier to run and debug if you run ArgoCD on your local machine than in the Kubernetes cluster.
2019-04-03 22:11:48 +00:00
You should scale the deployments to zero:
2019-02-11 18:38:43 +00:00
```
kubectl -n argocd scale deployment.extensions/argocd-application-controller --replicas 0
2019-02-20 22:19:07 +00:00
kubectl -n argocd scale deployment.extensions/argocd-dex-server --replicas 0
2019-02-11 18:38:43 +00:00
kubectl -n argocd scale deployment.extensions/argocd-repo-server --replicas 0
kubectl -n argocd scale deployment.extensions/argocd-server --replicas 0
2019-02-20 22:19:07 +00:00
kubectl -n argocd scale deployment.extensions/argocd-redis --replicas 0
2019-02-11 18:38:43 +00:00
```
Then checkout and build the UI next to your code
```
cd ~/go/src/github.com/argoproj
git clone git@github.com:argoproj/argo-cd-ui.git
```
2019-02-20 22:19:07 +00:00
Follow the UI's [README ](https://github.com/argoproj/argo-cd-ui/blob/master/README.md ) to build it.
Note: you'll need to use the https://localhost:6443 cluster now.
2019-02-11 18:38:43 +00:00
Then start the services:
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
cd ~/go/src/github.com/argoproj/argo-cd
2019-04-03 22:11:48 +00:00
make start
2018-03-12 21:41:46 +00:00
```
2019-02-11 18:38:43 +00:00
You can now execute `argocd` command against your locally running ArgoCD by appending `--server localhost:8080 --plaintext --insecure` , e.g.:
2018-03-12 21:41:46 +00:00
```
2019-02-20 22:19:07 +00:00
argocd app set guestbook --path guestbook --repo https://github.com/argoproj/argocd-example-apps.git --dest-server https://localhost:6443 --dest-namespace default --server localhost:8080 --plaintext --insecure
2019-02-11 18:38:43 +00:00
```
You can open the UI: http://localhost:8080
2019-02-20 22:19:07 +00:00
Note: you'll need to use the https://kubernetes.default.svc cluster now.
## Running Local Containers
You may need to run containers locally, so here's how:
Create login to Docker Hub, then login.
```
docker login
```
Add your username as the environment variable, e.g. to your `~/.bash_profile` :
```
export IMAGE_NAMESPACE=alexcollinsintuit
```
If you have not built the UI image (see [the UI README ](https://github.com/argoproj/argo-cd-ui/blob/master/README.md )), then do the following:
```
docker pull argoproj/argocd-ui:latest
docker tag argoproj/argocd-ui:latest $IMAGE_NAMESPACE/argocd-ui:latest
docker push $IMAGE_NAMESPACE/argocd-ui:latest
```
Build the images:
```
DOCKER_PUSH=true make image
```
Update the manifests:
```
make manifests
```
Install the manifests:
```
kubectl -n argocd apply --force -f manifests/install.yaml
```
Scale your deployments up:
```
kubectl -n argocd scale deployment.extensions/argocd-application-controller --replicas 1
kubectl -n argocd scale deployment.extensions/argocd-dex-server --replicas 1
kubectl -n argocd scale deployment.extensions/argocd-repo-server --replicas 1
kubectl -n argocd scale deployment.extensions/argocd-server --replicas 1
kubectl -n argocd scale deployment.extensions/argocd-redis --replicas 1
```
Now you can set-up the port-forwarding (see [README ](README.md )) and open the UI or CLI.
2019-02-11 18:38:43 +00:00
## Pre-commit Checks
Before you commit, make sure you've formatted and linted your code, or your PR will fail CI:
2018-02-18 21:16:24 +00:00
```
2019-02-11 18:38:43 +00:00
STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$")
2018-06-25 20:49:38 +00:00
2019-02-11 18:38:43 +00:00
gofmt -w $STAGED_GO_FILES
make codgen
make precommit ;# lint and test
```