Skip to content

Support importing local project files #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ ci-build-images:
@./build/build-image.sh images/onnx-serve-gpu onnx-serve-gpu
@./build/build-image.sh images/operator operator
@./build/build-image.sh images/fluentd fluentd
@./build/build-image.sh images/python-packager python-packager
@./build/build-image.sh images/cluster-autoscaler cluster-autoscaler
@./build/build-image.sh images/nvidia nvidia
@./build/build-image.sh images/metrics-server metrics-server
Expand All @@ -165,7 +164,6 @@ ci-push-images:
@./build/push-image.sh onnx-serve-gpu
@./build/push-image.sh operator
@./build/push-image.sh fluentd
@./build/push-image.sh python-packager
@./build/push-image.sh cluster-autoscaler
@./build/push-image.sh nvidia
@./build/push-image.sh metrics-server
Expand Down
41 changes: 35 additions & 6 deletions cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ package cmd

import (
"fmt"
"io/ioutil"

"github.com/spf13/cobra"

"github.com/cortexlabs/cortex/pkg/lib/console"
"github.com/cortexlabs/cortex/pkg/lib/errors"
"github.com/cortexlabs/cortex/pkg/lib/files"
"github.com/cortexlabs/cortex/pkg/lib/json"
s "github.com/cortexlabs/cortex/pkg/lib/strings"
"github.com/cortexlabs/cortex/pkg/lib/zip"
"github.com/cortexlabs/cortex/pkg/operator/api/schema"
"github.com/cortexlabs/cortex/pkg/operator/api/userconfig"
)

var flagDeployForce bool
Expand All @@ -53,21 +56,47 @@ func deploy(force bool, ignoreCache bool) {
errors.Exit(err)
}

zipInput := &zip.Input{
params := map[string]string{
"force": s.Bool(force),
"ignoreCache": s.Bool(ignoreCache),
}

configBytes, err := ioutil.ReadFile("cortex.yaml")
if err != nil {
errors.Exit(errors.Wrap(err, "cortex.yaml", userconfig.ErrorReadConfig().Error()))
}

projectPaths, err := files.ListDirRecursive(root, false,
files.IgnoreCortexYAML,
files.IgnoreHiddenFiles,
files.IgnoreHiddenFolders,
files.IgnorePythonGeneratedFiles,
)
if err != nil {
errors.Exit(err)
}

projectZipBytes, err := zip.ToMem(&zip.Input{
FileLists: []zip.FileListInput{
{
Sources: allConfigPaths(root),
Sources: projectPaths,
RemovePrefix: root,
},
},
})

if err != nil {
errors.Exit(errors.Wrap(err, "failed to zip project folder"))
}

params := map[string]string{
"force": s.Bool(force),
"ignoreCache": s.Bool(ignoreCache),
uploadInput := &HTTPUploadInput{
Bytes: map[string][]byte{
"cortex.yaml": configBytes,
"project.zip": projectZipBytes,
},
}

response, err := HTTPUploadZip("/deploy", zipInput, "config.zip", params)
response, err := HTTPUpload("/deploy", uploadInput, params)
if err != nil {
errors.Exit(err)
}
Expand Down
51 changes: 0 additions & 51 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ func resourceByNameStr(resourceName string, resourcesRes *schema.GetResourcesRes
return "", err
}
switch resourceType := rs.GetResourceType(); resourceType {
case resource.PythonPackageType:
return describePythonPackage(resourceName, resourcesRes)
case resource.APIType:
return describeAPI(resourceName, resourcesRes, flagVerbose)
default:
Expand All @@ -185,8 +183,6 @@ func resourceByNameStr(resourceName string, resourcesRes *schema.GetResourcesRes

func resourcesByTypeStr(resourceType resource.Type, resourcesRes *schema.GetResourcesResponse) (string, error) {
switch resourceType {
case resource.PythonPackageType:
return pythonPackagesStr(resourcesRes.DataStatuses, resourcesRes.Context), nil
case resource.APIType:
return apisStr(resourcesRes.APIGroupStatuses), nil
default:
Expand All @@ -196,8 +192,6 @@ func resourcesByTypeStr(resourceType resource.Type, resourcesRes *schema.GetReso

func resourceByNameAndTypeStr(resourceName string, resourceType resource.Type, resourcesRes *schema.GetResourcesResponse, flagVerbose bool) (string, error) {
switch resourceType {
case resource.PythonPackageType:
return describePythonPackage(resourceName, resourcesRes)
case resource.APIType:
return describeAPI(resourceName, resourcesRes, flagVerbose)
default:
Expand All @@ -206,27 +200,11 @@ func resourceByNameAndTypeStr(resourceName string, resourceType resource.Type, r
}

func allResourcesStr(resourcesRes *schema.GetResourcesResponse) string {
ctx := resourcesRes.Context

out := ""
out += pythonPackagesStr(resourcesRes.DataStatuses, ctx)
out += apisStr(resourcesRes.APIGroupStatuses)
return out
}

func pythonPackagesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
if len(ctx.PythonPackages) == 0 {
return ""
}

resources := make([]context.Resource, 0, len(ctx.PythonPackages))
for _, pythonPackage := range ctx.PythonPackages {
resources = append(resources, pythonPackage)
}

return "\n" + dataResourceTable(resources, dataStatuses, resource.PythonPackageType) + "\n"
}

func apisStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
if len(apiGroupStatuses) == 0 {
return ""
Expand All @@ -235,15 +213,6 @@ func apisStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
return "\n" + apiResourceTable(apiGroupStatuses)
}

func describePythonPackage(name string, resourcesRes *schema.GetResourcesResponse) (string, error) {
pythonPackage := resourcesRes.Context.PythonPackages[name]
if pythonPackage == nil {
return "", userconfig.ErrorUndefinedResource(name, resource.PythonPackageType)
}
dataStatus := resourcesRes.DataStatuses[pythonPackage.GetID()]
return dataStatusSummary(dataStatus), nil
}

func describeAPI(name string, resourcesRes *schema.GetResourcesResponse, flagVerbose bool) (string, error) {
groupStatus := resourcesRes.APIGroupStatuses[name]
if groupStatus == nil {
Expand Down Expand Up @@ -553,10 +522,6 @@ func dataResourceTable(resources []context.Resource, dataStatuses map[string]*re
}

title := resourceType.UserFacing()
if resourceType == resource.PythonPackageType {
title = resourceType.UserFacingPlural()
}

t := table.Table{
Headers: []table.Header{
{Title: title, MaxWidth: 32},
Expand Down Expand Up @@ -615,14 +580,8 @@ func titleStr(title string) string {
}

func resourceStatusesStr(resourcesRes *schema.GetResourcesResponse) string {
ctx := resourcesRes.Context
var titles, values []string

if len(ctx.PythonPackages) != 0 {
titles = append(titles, resource.PythonPackageType.UserFacingPlural())
values = append(values, pythonPackageStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context))
}

if len(resourcesRes.APIGroupStatuses) != 0 {
titles = append(titles, resource.APIType.UserFacingPlural())
values = append(values, apiStatusesStr(resourcesRes.APIGroupStatuses))
Expand All @@ -643,16 +602,6 @@ func resourceStatusesStr(resourcesRes *schema.GetResourcesResponse) string {
return out
}

func pythonPackageStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.PythonPackages))
i := 0
for _, pythonPackage := range ctx.PythonPackages {
statuses[i] = dataStatuses[pythonPackage.GetID()]
i++
}
return StatusStr(statuses)
}

func apiStatusesStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
var statuses = make([]resource.Status, len(apiGroupStatuses))
i := 0
Expand Down
23 changes: 0 additions & 23 deletions cli/cmd/lib_config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"os"
"path/filepath"

"github.com/cortexlabs/cortex/pkg/consts"
"github.com/cortexlabs/cortex/pkg/lib/errors"
"github.com/cortexlabs/cortex/pkg/lib/files"
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
"github.com/cortexlabs/cortex/pkg/operator/api/userconfig"
)

Expand Down Expand Up @@ -68,27 +66,6 @@ func pythonPaths(dir string) []string {
return pyPaths
}

func allConfigPaths(root string) []string {
exportPaths := strset.New()
requirementsPath := filepath.Join(root, consts.RequirementsTxt)
if err := files.CheckFile(requirementsPath); err == nil {
exportPaths.Add(requirementsPath)
}

customPackagesRoot := filepath.Join(root, consts.PackageDir)
if err := files.CheckDir(customPackagesRoot); err == nil {
customPackagesPaths, err := files.ListDirRecursive(customPackagesRoot, false, files.IgnoreHiddenFiles, files.IgnoreHiddenFolders, files.IgnorePythonGeneratedFiles)
if err != nil {
errors.Exit(err)
}
exportPaths.Add(customPackagesPaths...)
}
exportPaths.Add(yamlPaths(root)...)
exportPaths.Add(pythonPaths(root)...)

return exportPaths.Slice()
}

func appNameFromConfig() (string, error) {
appRoot := mustAppRoot()
return userconfig.ReadAppName(filepath.Join(appRoot, "cortex.yaml"), "cortex.yaml")
Expand Down
2 changes: 0 additions & 2 deletions cortex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export CORTEX_IMAGE_FLUENTD="${CORTEX_IMAGE_FLUENTD:-cortexlabs/fluentd:$CORTEX_
export CORTEX_IMAGE_OPERATOR="${CORTEX_IMAGE_OPERATOR:-cortexlabs/operator:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_TF_SERVE="${CORTEX_IMAGE_TF_SERVE:-cortexlabs/tf-serve:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_TF_API="${CORTEX_IMAGE_TF_API:-cortexlabs/tf-api:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_PYTHON_PACKAGER="${CORTEX_IMAGE_PYTHON_PACKAGER:-cortexlabs/python-packager:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_TF_SERVE_GPU="${CORTEX_IMAGE_TF_SERVE_GPU:-cortexlabs/tf-serve-gpu:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_ONNX_SERVE="${CORTEX_IMAGE_ONNX_SERVE:-cortexlabs/onnx-serve:$CORTEX_VERSION_STABLE}"
export CORTEX_IMAGE_ONNX_SERVE_GPU="${CORTEX_IMAGE_ONNX_SERVE_GPU:-cortexlabs/onnx-serve-gpu:$CORTEX_VERSION_STABLE}"
Expand Down Expand Up @@ -231,7 +230,6 @@ function install_cortex() {
-e CORTEX_IMAGE_OPERATOR=$CORTEX_IMAGE_OPERATOR \
-e CORTEX_IMAGE_TF_SERVE=$CORTEX_IMAGE_TF_SERVE \
-e CORTEX_IMAGE_TF_API=$CORTEX_IMAGE_TF_API \
-e CORTEX_IMAGE_PYTHON_PACKAGER=$CORTEX_IMAGE_PYTHON_PACKAGER \
-e CORTEX_IMAGE_TF_SERVE_GPU=$CORTEX_IMAGE_TF_SERVE_GPU \
-e CORTEX_IMAGE_ONNX_SERVE=$CORTEX_IMAGE_ONNX_SERVE \
-e CORTEX_IMAGE_ONNX_SERVE_GPU=$CORTEX_IMAGE_ONNX_SERVE_GPU \
Expand Down
2 changes: 0 additions & 2 deletions dev/registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function create_registry() {
aws ecr create-repository --repository-name=cortexlabs/operator --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tf-serve --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tf-api --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/python-packager --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/tf-serve-gpu --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-serve --region=$REGISTRY_REGION || true
aws ecr create-repository --repository-name=cortexlabs/onnx-serve-gpu --region=$REGISTRY_REGION || true
Expand Down Expand Up @@ -129,7 +128,6 @@ elif [ "$cmd" = "update" ]; then
build_and_push $ROOT/images/tf-serve tf-serve latest
build_and_push $ROOT/images/tf-serve-gpu tf-serve-gpu latest
build_and_push $ROOT/images/onnx-serve-gpu onnx-serve-gpu latest
build_and_push $ROOT/images/python-packager python-packager latest
build_and_push $ROOT/images/cluster-autoscaler cluster-autoscaler latest
build_and_push $ROOT/images/nvidia nvidia latest
build_and_push $ROOT/images/metrics-server metrics-server latest
Expand Down
1 change: 0 additions & 1 deletion docs/cluster/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export CORTEX_IMAGE_TF_API="cortexlabs/tf-api:master"
export CORTEX_IMAGE_TF_SERVE_GPU="cortexlabs/tf-serve-gpu:master"
export CORTEX_IMAGE_ONNX_SERVE="cortexlabs/onnx-serve:master"
export CORTEX_IMAGE_ONNX_SERVE_GPU="cortexlabs/onnx-serve-gpu:master"
export CORTEX_IMAGE_PYTHON_PACKAGER="cortexlabs/python-packager:master"
export CORTEX_IMAGE_CLUSTER_AUTOSCALER="cortexlabs/cluster-autoscaler:master"
export CORTEX_IMAGE_NVIDIA="cortexlabs/nvidia:master"
export CORTEX_IMAGE_METRICS_SERVER="cortexlabs/metrics-server:master"
Expand Down
1 change: 0 additions & 1 deletion docs/cluster/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export CORTEX_IMAGE_OPERATOR="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlab
export CORTEX_IMAGE_TF_SERVE="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/tf-serve:latest"
export CORTEX_IMAGE_TF_SERVE_GPU="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/tf-serve-gpu:latest"
export CORTEX_IMAGE_TF_API="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/tf-api:latest"
export CORTEX_IMAGE_PYTHON_PACKAGER="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/python-packager:latest"
export CORTEX_IMAGE_CLUSTER_AUTOSCALER="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/cluster-autoscaler:latest"
export CORTEX_IMAGE_NVIDIA="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/nvidia:latest"
export CORTEX_IMAGE_METRICS_SERVER="XXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/cortexlabs/metrics-server:latest"
Expand Down
32 changes: 0 additions & 32 deletions docs/deployments/python-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,3 @@ Cortex looks for a `requirements.txt` file in the top level cortex directory (in
├── ...
└── requirements.txt
```

## Custom Packages

Cortex looks for your Python packages in the directory `./packages/<package name>`. The package must have a `setup.py` in the root of the package directory with the name set to your package name. Cortex will run `pip3 wheel -w wheelhouse ./packages/<package name>` to construct wheels for the Python Project.

```text
./iris/
├── cortex.yaml
├── ...
└── packages
└── acme-util
├── acme-util/
| ├── util_a.py
| └── util_b.py
└── setup.py
```

Sample `setup.py`

```python
from distutils.core import setup

setup(
name="acme-util",
version="0.0.1",
description="",
author="ACME C. M. Exists",
author_email="acme@acme.com",
packages=["acme-util"],
install_requires=["pyyaml==3.13"],
)
```
2 changes: 1 addition & 1 deletion examples/text-generator/cortex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
- kind: api
name: generator
model: s3://cortex-examples/gpt-2/774
request_handler: encoder.py
request_handler: handler.py
compute:
gpu: 1
13 changes: 0 additions & 13 deletions examples/text-generator/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,3 @@ def get_encoder():
)
bpe_merges = [tuple(merge_str.split()) for merge_str in bpe_data.split("\n")[1:-1]]
return Encoder(encoder=encoder, bpe_merges=bpe_merges)


encoder = get_encoder()


def pre_inference(sample, metadata):
context = encoder.encode(sample["text"])
return {"context": [context]}


def post_inference(prediction, metadata):
response = prediction["response"]["sample"]
return {encoder.decode(response)}
13 changes: 13 additions & 0 deletions examples/text-generator/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from encoder import get_encoder

encoder = get_encoder()


def pre_inference(sample, metadata):
context = encoder.encode(sample["text"])
return {"context": [context]}


def post_inference(prediction, metadata):
response = prediction["response"]["sample"]
return {encoder.decode(response)}
4 changes: 2 additions & 2 deletions images/onnx-serve-gpu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt-get update -qq && apt-get install -y -q \
&& apt-get clean -qq && rm -rf /var/lib/apt/lists/*


ENV PYTHONPATH="/src:${PYTHONPATH}"
ENV PYTHONPATH "${PYTHONPATH}:/src:/mnt/project"

COPY pkg/workloads/cortex/lib/requirements.txt /src/cortex/lib/requirements.txt
COPY pkg/workloads/cortex/onnx_serve/requirements.txt /src/cortex/onnx_serve/requirements.txt
Expand All @@ -39,4 +39,4 @@ COPY pkg/workloads/cortex/consts.py /src/cortex
COPY pkg/workloads/cortex/lib /src/cortex/lib
COPY pkg/workloads/cortex/onnx_serve /src/cortex/onnx_serve

ENTRYPOINT ["/usr/bin/python3", "/src/cortex/onnx_serve/api.py"]
ENTRYPOINT ["/src/cortex/onnx_serve/run.sh"]
4 changes: 2 additions & 2 deletions images/onnx-serve/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt-get update -qq && apt-get install -y -q \
&& apt-get clean -qq && rm -rf /var/lib/apt/lists/*


ENV PYTHONPATH="/src:${PYTHONPATH}"
ENV PYTHONPATH "${PYTHONPATH}:/src:/mnt/project"

COPY pkg/workloads/cortex/lib/requirements.txt /src/cortex/lib/requirements.txt
COPY pkg/workloads/cortex/onnx_serve/requirements.txt /src/cortex/onnx_serve/requirements.txt
Expand All @@ -39,4 +39,4 @@ COPY pkg/workloads/cortex/consts.py /src/cortex
COPY pkg/workloads/cortex/lib /src/cortex/lib
COPY pkg/workloads/cortex/onnx_serve /src/cortex/onnx_serve

ENTRYPOINT ["/usr/bin/python3", "/src/cortex/onnx_serve/api.py"]
ENTRYPOINT ["/src/cortex/onnx_serve/run.sh"]
Loading