Skip to content

Commit ec800d1

Browse files
authored
Update development.md
1 parent 746be85 commit ec800d1

File tree

1 file changed

+117
-86
lines changed

1 file changed

+117
-86
lines changed

docs/contributing/development.md

Lines changed: 117 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,48 @@
22

33
## Remote development
44

5-
We recommend that you run your development environment on a cloud instance, e.g. an AWS EC2 instance or GCP VM (due to frequent docker registry pushing). There are a variety of ways to develop on a remote VM, feel free to reach out on [gitter](https://gitter.im/cortexlabs/cortex) and we can point you in the right direction based on your operating system and editor preferences.
5+
We recommend that you run your development environment on a cloud instance due to frequent docker registry pushing, e.g. an AWS EC2 instance or GCP VM. We've had a good experience using [Mutagen](https://mutagen.io/documentation/introduction) to synchronize local / remote file systems. Feel free to reach out to us on [gitter](https://gitter.im/cortexlabs/cortex) if you have any questions about this.
66

77
## Prerequisites
88

9-
1. Go (>=1.14)
10-
2. Docker
11-
3. eksctl
12-
4. kubectl
13-
5. aws-cli
9+
### System packages
1410

15-
Also, please use the VS Code [yaml extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) and enable auto-formatting for YAML files.
11+
To install the necessary system packages on Ubuntu, you can run these commands:
12+
13+
```bash
14+
sudo apt-get update
15+
sudo apt install -y apt-transport-https ca-certificates software-properties-common gnupg-agent curl zip python3 python3-pip python3-dev build-essential jq tree
16+
sudo python3 -m pip install --upgrade pip setuptools boto3
17+
```
1618

1719
### Go
1820

1921
To install Go on linux, run:
2022

2123
```bash
24+
mkdir -p ~/bin && \
2225
wget https://dl.google.com/go/go1.14.7.linux-amd64.tar.gz && \
2326
sudo tar -xvf go1.14.7.linux-amd64.tar.gz && \
2427
sudo mv go /usr/local && \
25-
rm go1.14.7.linux-amd64.tar.gz
28+
rm go1.14.7.linux-amd64.tar.gz && \
29+
echo 'export PATH="/usr/local/go/bin:$HOME/go/bin:$PATH"' >> $HOME/.bashrc
2630
```
2731

32+
And then log out and back in.
33+
2834
### Docker
2935

3036
To install Docker on Ubuntu, run:
3137

3238
```bash
33-
sudo apt install docker.io && \
34-
sudo systemctl start docker && \
35-
sudo systemctl enable docker && \
36-
sudo groupadd docker && \
37-
sudo gpasswd -a $USER docker
39+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
40+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
41+
sudo apt update && \
42+
sudo apt install -y docker-ce docker-ce-cli containerd.io && \
43+
sudo usermod -aG docker $USER
3844
```
3945

40-
### eksctl
41-
42-
To install eksctl run:
43-
44-
```bash
45-
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp && \
46-
sudo mv /tmp/eksctl /usr/local/bin
47-
```
46+
And then log out and back in.
4847

4948
### kubectl
5049

@@ -56,18 +55,42 @@ chmod +x ./kubectl && \
5655
sudo mv ./kubectl /usr/local/bin/kubectl
5756
```
5857

58+
### eksctl
59+
60+
To install eksctl run:
61+
62+
```bash
63+
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp && \
64+
sudo mv /tmp/eksctl /usr/local/bin
65+
```
66+
5967
### aws-cli (v1)
6068

6169
Follow [these instructions](https://github.com/aws/aws-cli#installation) to install aws-cli (v1).
6270

6371
E.g. to install it globally, run:
6472

6573
```bash
66-
sudo python -m pip install awscli
74+
sudo python3 -m pip install awscli
6775

6876
aws configure
6977
```
7078

79+
### gcloud (v1)
80+
81+
Follow [these instructions](https://cloud.google.com/sdk/docs/install#deb) to install gcloud.
82+
83+
For example:
84+
85+
```bash
86+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
87+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
88+
sudo apt-get update && \
89+
sudo apt-get install -y google-cloud-sdk
90+
91+
gcloud init
92+
```
93+
7194
## Cortex dev environment
7295

7396
### Clone the repo
@@ -85,61 +108,84 @@ Run the tests:
85108
make test
86109
```
87110

88-
### Image Registry
111+
### Dev tools
89112

90-
Create a config directory in the repo's root directory:
113+
Install development tools by running:
91114

92115
```bash
93-
mkdir dev/config
116+
make tools
94117
```
95118

96-
Next, create `dev/config/build.sh`. Add the following content to it (you may use a different region for `REGISTRY_REGION`):
119+
After the dependencies are installed, there may be a diff in `go.mod` and `go.sum`, which you can revert.
97120

98-
```bash
99-
export CORTEX_VERSION="master"
121+
Run the linter:
100122

101-
export REGISTRY_REGION="us-west-2"
123+
```bash
124+
make lint
102125
```
103126

104-
Create the AWS Elastic Container Registry:
127+
We use `gofmt` for formatting Go files, `black` for Python files (line length = 100), and the VS Code [yaml extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) for YAML files. It is recommended to enable these in your code editor, but you can also run the Go and Python formatters from the terminal:
105128

106129
```bash
107-
make registry-create
130+
make format
131+
132+
git diff # there should be no diff
108133
```
109134

110-
Take note of the registry URL, this will be needed shortly.
135+
### Cluster configuration
111136

112-
Create the S3 buckets:
137+
Create a config directory in the repo's root directory:
113138

114139
```bash
115-
aws s3 mb s3://cortex-cluster-<your_name>
116-
aws s3 mb s3://cortex-cli-<your_name> # if you'll be uploading your compiled CLI
140+
mkdir dev/config
117141
```
118142

119-
### Cluster
143+
Create `dev/config/env.sh` with your AWS credentials:
120144

121-
Update `dev/config/build.sh`. Paste the following config, and update `CLI_BUCKET_NAME`, `CLI_BUCKET_REGION`, `REGISTRY_URL` (the), and `REGISTRY_REGION` accordingly:
145+
```bash
146+
# dev/config/env.sh
147+
148+
export AWS_ACCESS_KEY_ID=***
149+
export AWS_SECRET_ACCESS_KEY=***
150+
```
151+
152+
Next, create `dev/config/build.sh`. Add the following content to it (you may use a different region for `REGISTRY_REGION`):
122153

123154
```bash
155+
# dev/config/build.sh
156+
124157
export CORTEX_VERSION="master"
158+
export REGISTRY_REGION="us-west-2"
159+
# export NUM_BUILD_PROCS=2 # optional; can be >2 if you have enough memory
160+
```
161+
162+
Create the ECR registries:
125163

164+
```bash
165+
make registry-create
166+
```
167+
168+
Update `dev/config/build.sh` to include `REGISTRY_URL`, which was printed in the previous command:
169+
170+
```bash
171+
# dev/config/build.sh
172+
173+
export CORTEX_VERSION="master"
126174
export REGISTRY_REGION="us-west-2"
127175
export REGISTRY_URL="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com"
128-
129-
# optional, only used for dev/build_cli.sh
130-
export CLI_BUCKET_NAME="cortex-cli-<your_name>"
131-
export CLI_BUCKET_REGION="us-west-2"
176+
# export NUM_BUILD_PROCS=2 # optional; can be >2 if you have enough memory
132177
```
133178

134-
Create `dev/config/cluster.yaml`. Paste the following config, and update `cortex_bucket`, `cortex_region`, and all registry URLs accordingly:
179+
Create `dev/config/cluster.yaml`. Paste the following config, and update `cortex_region` and all registry URLs accordingly:
135180

136181
```yaml
182+
# dev/config/cluster.yaml
183+
184+
cluster_name: cortex
185+
region: us-west-2
137186
instance_type: m5.large
138-
min_instances: 2
187+
min_instances: 1
139188
max_instances: 5
140-
bucket: cortex-cluster-<your_name>
141-
region: us-west-2
142-
cluster_name: cortex
143189

144190
image_operator: XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/operator:latest
145191
image_manager: XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/manager:latest
@@ -158,17 +204,14 @@ image_istio_pilot: XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/istio-pil
158204
159205
### Building
160206
161-
Add this to your bash profile (e.g. `~/.bash_profile`, `~/.profile` or `~/.bashrc`):
207+
Add this to your bash profile (e.g. `~/.bash_profile`, `~/.profile` or `~/.bashrc`), replacing the image registry URL accordingly:
162208

163209
```bash
164210
export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs" # set the default image for APIs
165211
export CORTEX_TELEMETRY_SENTRY_DSN="https://[email protected]/1848098" # redirect analytics to our dev environment
166212
export CORTEX_TELEMETRY_SEGMENT_WRITE_KEY="0WvoJyCey9z1W2EW7rYTPJUMRYat46dl" # redirect error reporting to our dev environment
167213
168-
export AWS_ACCESS_KEY_ID=""
169-
export AWS_SECRET_ACCESS_KEY=""
170-
171-
alias cortex-dev='<path/to/cortex>/bin/cortex' # replace <path/to/cortex> with the path to the cortex repo that you cloned
214+
alias cortex='$HOME/bin/cortex' # your path may be different depending on where you cloned the repo
172215
```
173216

174217
Refresh your bash profile:
@@ -177,61 +220,49 @@ Refresh your bash profile:
177220
. ~/.bash_profile # or: `. ~/.bashrc`
178221
```
179222

180-
Build and push all Cortex images:
181-
182-
```bash
183-
make registry-all
184-
```
185-
186223
Build the Cortex CLI:
187224

188225
```bash
189226
make cli # the binary will be placed in <path/to/cortex>/bin/cortex
190-
cortex-dev version # should show "master"
227+
cortex version # should show "master"
191228
```
192229

193-
If you wish to parallelize the build process, the `parallel` GNU utility needs to be installed. Once installed, set the `NUM_BUILD_PROCS` environment variable to the desired number of parallel jobs. For ease of use, export `NUM_BUILD_PROCS` in `dev/config/build.sh`.
194-
195-
### Cortex cluster
196-
197-
Start Cortex:
230+
Build and push all Cortex images:
198231

199232
```bash
200-
make cluster-up
233+
make registry-all
201234
```
202235

203-
Tear down the Cortex cluster:
236+
## Dev workflow
204237

205-
```bash
206-
make cluster-down
207-
```
238+
Here is the typical full dev workflow which covers most cases:
208239

209-
### Deploy an example
240+
1. `make cluster-up` (creates a cluster using `dev/config/cluster.yaml`)
241+
2. `make devstart` (deletes the in-cluster operator, builds the CLI, and starts the operator locally; file changes will trigger the CLI and operator to re-build)
242+
3. Make your changes
243+
4. `make registry-dev` (only necessary if API images or the manager are modified)
244+
5. Test your changes e.g. via `cortex deploy` (and repeat steps 3 and 4 as necessary)
245+
6. `make cluster-down` (deletes your cluster)
210246

211-
```bash
212-
cortex deploy examples/pytorch/iris-classifier --env aws
213-
```
247+
If you want to switch back to the in-cluster operator:
214248

215-
## Off-cluster operator
249+
1. `<ctrl+c>` to stop your off-cluster operator
250+
2. `make cluster-configure` to install the operator in your cluster
216251

217-
If you're making changes in the operator and want faster iterations, you can run an off-cluster operator.
252+
If you only want to test Cortex's local environment, here is the common workflow:
218253

219-
1. `make tools` to install the necessary dependencies to run the operator
220-
2. `make operator-stop` to stop the in-cluster operator
221-
3. `make devstart` to run the off-cluster operator (which rebuilds the CLI and restarts the Operator when files change)
254+
1. `make cli-watch` (builds the CLI and re-builds it when files are changed)
255+
2. Make your changes
256+
3. `make registry-dev` (only necessary if API images or the manager are modified)
257+
4. Test your changes e.g. via `cortex deploy` (and repeat steps 2 and 3 as necessary)
222258

223-
If you want to switch back to the in-cluster operator:
259+
### Dev workflow optimizations
224260

225-
1. `<ctrl+c>` to stop your off-cluster operator
226-
2. `make cluster-configure` to install the operator in your cluster
261+
If you are only modifying the CLI, `make cli-watch` will build the CLI and re-build it when files are changed. When doing this, you can leave the operator running in the cluster instead of running it locally.
227262

228-
## Dev workflow
263+
If you are only modifying the operator, `make operator-local` will build and start the operator locally, and build/restart it when files are changed.
229264

230-
1. `make cluster-up`
231-
2. `make devstart`
232-
3. Make changes
233-
4. `make registry-dev`
234-
5. Test your changes with projects in `examples` or your own
265+
If you are modifying code in the API images (i.e. any of the Python serving code), `make registry-dev` may build more images than you need during testing. For example, if you are only testing using the `python-predictor-cpu` image, you can comment out the other images listed in `user_facing_images` and `dev_images` in `build/images.sh` before running `make registry-dev`.
235266

236267
See `Makefile` for additional dev commands.
237268

0 commit comments

Comments
 (0)