Skip to content

Commit dbc60a3

Browse files
authored
System package docs (#250)
1 parent 383abd9 commit dbc60a3

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

docs/apis/python-packages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python Packages
22

3-
Cortex allows you to install additional Python packages to be used in any workload.
3+
Cortex allows you to install additional Python packages to be used in any workload. If your Python packages require system packages to be installed, see [system packages](system-packages.md) for more details.
44

55
## PyPI Packages
66

docs/apis/system-packages.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# System Packages
2+
3+
Cortex uses Docker images to run workloads. These Docker images can be replaced with custom images based on Cortex images and augmented with your system packages and libraries. Your custom images need to be pushed to a container registry (e.g. Docker Hub, ECR, GCR) that can be accessed by your cluster.
4+
5+
See `Image paths` section in [cortex config](../cluster/config.md) for all images that can be customized.
6+
7+
The example below demonstrates how to create a custom Docker image and configure Cortex to use it.
8+
9+
## Create Custom Image
10+
11+
Create a Dockerfile to build your custom image:
12+
13+
```
14+
mkdir my-api && cd my-api && touch Dockerfile
15+
```
16+
17+
Specify the base image you want to override followed by your customizations. The sample Dockerfile below inherits from Cortex's ONNX Serving image and installs the `tree` system package.
18+
19+
```
20+
# Dockerfile
21+
22+
FROM cortexlabs/onnx-serve
23+
24+
RUN apt-get update \
25+
&& apt-get install -y tree \
26+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
27+
```
28+
29+
## Build and Push to a Container Registry
30+
31+
Create a repository to store your image:
32+
33+
```
34+
# We create a repository in AWS ECR
35+
36+
export AWS_ACCESS_KEY_ID="***"
37+
export AWS_SECRET_ACCESS_KEY="***"
38+
39+
eval $(aws ecr get-login --no-include-email --region us-west-2)
40+
41+
aws ecr create-repository --repository-name=org/my-api --region=us-west-2
42+
# take note of repository url
43+
```
44+
45+
Build the image based on your Dockerfile and push to its repository in AWS ECR:
46+
47+
```
48+
docker build . -t org/my-api:latest -t <repository_url>:latest
49+
50+
docker push <repository_url>:latest
51+
```
52+
53+
## Configure Cortex
54+
55+
Set the environment variable of the image to your `my-api` image repository url:
56+
57+
```
58+
export CORTEX_IMAGE_ONNX_SERVE="<repository_url>:latest"
59+
60+
./cortex.sh update
61+
```
62+
63+
## Use System Package in Workloads
64+
65+
Cortex will use your image to launch ONNX serving workloads. You will have access to any customizations you made:
66+
67+
```
68+
# request_handler.py
69+
70+
import subprocess
71+
72+
def pre_inference(sample, metadata):
73+
subprocess.run(["tree"])
74+
...
75+
```

docs/summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [Request Handlers](apis/request-handlers.md)
1414
* [Compute](apis/compute.md)
1515
* [Python Packages](apis/python-packages.md)
16+
* [System Packages](apis/system-packages.md)
1617
* [CLI Commands](cluster/cli.md)
1718
* [Resource Statuses](apis/statuses.md)
1819

0 commit comments

Comments
 (0)