You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
6
6
7
7
## Prerequisites
8
8
9
-
1. Go (>=1.14)
10
-
2. Docker
11
-
3. eksctl
12
-
4. kubectl
13
-
5. aws-cli
9
+
### System packages
14
10
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
Create a config directory in the repo's root directory:
113
+
Install development tools by running:
91
114
92
115
```bash
93
-
mkdir dev/config
116
+
make tools
94
117
```
95
118
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.
97
120
98
-
```bash
99
-
export CORTEX_VERSION="master"
121
+
Run the linter:
100
122
101
-
export REGISTRY_REGION="us-west-2"
123
+
```bash
124
+
make lint
102
125
```
103
126
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:
105
128
106
129
```bash
107
-
make registry-create
130
+
make format
131
+
132
+
git diff # there should be no diff
108
133
```
109
134
110
-
Take note of the registry URL, this will be needed shortly.
135
+
### Cluster configuration
111
136
112
-
Create the S3 buckets:
137
+
Create a config directory in the repo's root directory:
113
138
114
139
```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
117
141
```
118
142
119
-
### Cluster
143
+
Create `dev/config/env.sh` with your AWS credentials:
120
144
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`):
122
153
123
154
```bash
155
+
# dev/config/build.sh
156
+
124
157
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:
125
163
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:
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:
162
208
163
209
```bash
164
210
export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs" # set the default image for APIs
165
211
export CORTEX_TELEMETRY_SENTRY_DSN="https://[email protected]/1848098" # redirect analytics to our dev environment
166
212
export CORTEX_TELEMETRY_SEGMENT_WRITE_KEY="0WvoJyCey9z1W2EW7rYTPJUMRYat46dl" # redirect error reporting to our dev environment
167
213
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
172
215
```
173
216
174
217
Refresh your bash profile:
@@ -177,61 +220,49 @@ Refresh your bash profile:
177
220
. ~/.bash_profile # or: `. ~/.bashrc`
178
221
```
179
222
180
-
Build and push all Cortex images:
181
-
182
-
```bash
183
-
make registry-all
184
-
```
185
-
186
223
Build the Cortex CLI:
187
224
188
225
```bash
189
226
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"
191
228
```
192
229
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:
198
231
199
232
```bash
200
-
make cluster-up
233
+
make registry-all
201
234
```
202
235
203
-
Tear down the Cortex cluster:
236
+
## Dev workflow
204
237
205
-
```bash
206
-
make cluster-down
207
-
```
238
+
Here is the typical full dev workflow which covers most cases:
208
239
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)
If you want to switch back to the in-cluster operator:
214
248
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
216
251
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:
218
253
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)
222
258
223
-
If you want to switch back to the in-cluster operator:
259
+
### Dev workflow optimizations
224
260
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.
227
262
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.
229
264
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`.
0 commit comments