Skip to content

Commit

Permalink
feat: Implement storage initializer for Seldon and KF (#35)
Browse files Browse the repository at this point in the history
* chore: Update vendor

Signed-off-by: Ce Gao <[email protected]>

* feat(serving): Add storage initializer

Signed-off-by: Ce Gao <[email protected]>

* feat: Move files to upper directory

Signed-off-by: Ce Gao <[email protected]>

* fix: Remove panic

Signed-off-by: Ce Gao <[email protected]>

* feat: Add docs

Signed-off-by: Ce Gao <[email protected]>

* fix: Add link

Signed-off-by: Ce Gao <[email protected]>

* fix: Use AWS_SECRET_ACCESS_KEY AWS_ACCESS_KEY_ID

Seldon Core does not support renaming the environment variable name.

Signed-off-by: Ce Gao <[email protected]>

* chore: Update makefile

Signed-off-by: Ce Gao <[email protected]>

* feat: Update doc to record the modications for config

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored Jun 12, 2020
1 parent ec780e5 commit 8150ac1
Show file tree
Hide file tree
Showing 35 changed files with 520 additions and 6,642 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
.ipynb*/
.vscode/
third_party/
18 changes: 16 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
- id: ormb
main: ./cmd/ormb/main.go
binary: ormb
- id: ormb-storage-initializer
main: ./cmd/ormb-storage-initializer/main.go
binary: ormb-storage-initializer
archives:
- replacements:
darwin: Darwin
Expand All @@ -25,3 +28,14 @@ release:
github:
owner: caicloud
name: ormb
# dockers:
# - goos: linux
# goarch: amd64
# builds:
# - ormb
# dockerfile: build/ormb/Dockerfile
# # Templates of the Docker image names.
# image_templates:
# - "clvoss/clever-ormb:latest"
# - "clvoss/clever-ormb:{{ .Tag }}"
# - "clvoss/clever-ormb:v{{ .Major }}"
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
ROOT := github.com/caicloud/ormb

# Target binaries. You can build multiple binaries for a single project.
TARGETS := ormb
TARGETS := ormb ormb-storage-initializer

# Container image prefix and suffix added to targets.
# The final built images are:
# $[REGISTRY]/$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION]
# $[REGISTRY] is an item from $[REGISTRIES], $[TARGET] is an item from $[TARGETS].
IMAGE_PREFIX ?= $(strip template-)
IMAGE_PREFIX ?= $(strip clever-)
IMAGE_SUFFIX ?= $(strip )

# Container registries.
REGISTRY ?= cargo.dev.caicloud.xyz/release
REGISTRY ?= cleveross

# Container registry for base images.
BASE_REGISTRY ?= cargo.caicloud.xyz/library
Expand Down Expand Up @@ -129,18 +129,22 @@ build-linux:
$(CMD_DIR)/$${target}; \
done'

container: build-linux
container-buildlocal: build-local container-skipbuild

container: build-linux container-skipbuild

push: container
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker build -t $(REGISTRY)/$${image}:$(VERSION) \
--label $(DOCKER_LABELS) \
-f $(BUILD_DIR)/$${target}/Dockerfile .; \
docker push $(REGISTRY)/$${image}:$(VERSION); \
done

push: container
container-skipbuild:
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker push $(REGISTRY)/$${image}:$(VERSION); \
docker build -t $(REGISTRY)/$${image}:$(VERSION) \
--label $(DOCKER_LABELS) \
-f $(BUILD_DIR)/$${target}/Dockerfile .; \
done

.PHONY: clean
Expand Down
5 changes: 0 additions & 5 deletions build/admin/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions build/controller/Dockerfile

This file was deleted.

5 changes: 5 additions & 0 deletions build/ormb-storage-initializer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM debian:stretch

COPY bin/ormb-storage-initializer /usr/local/bin/ormb-storage-initializer

ENTRYPOINT ["ormb-storage-initializer"]
5 changes: 5 additions & 0 deletions build/ormb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM debian:stretch

COPY bin/ormb /usr/local/bin/ormb

CMD ["ormb"]
21 changes: 21 additions & 0 deletions cmd/ormb-storage-initializer/cmd/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

var (
usernameOpt, passwordOpt string
passwordFromStdinOpt, insecureOpt, plainHTTPOpt bool
)
28 changes: 28 additions & 0 deletions cmd/ormb-storage-initializer/cmd/prerun.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/caicloud/ormb/pkg/oci"
"github.com/caicloud/ormb/pkg/ormb"
)

func preRunE(cmd *cobra.Command, args []string) error {
rootPath, err := filepath.Abs(viper.GetString("rootPath"))
if err != nil {
return err
}
fmt.Printf("Using %s as the root path\n", rootPath)

ormbClient, err = ormb.NewOCIORMB(
oci.ClientOptRootPath(rootPath),
oci.ClientOptWriter(os.Stdout),
oci.ClientOptPlainHTTP(plainHTTPOpt),
)
return err
}
131 changes: 131 additions & 0 deletions cmd/ormb-storage-initializer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
Copyright © 2020 Caicloud Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/caicloud/ormb/pkg/consts"
"github.com/caicloud/ormb/pkg/oci"
"github.com/caicloud/ormb/pkg/ormb"
)

var ormbClient ormb.ORMB

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ormb-storage-initializer",
Short: "Download model from remote registry in Seldon Core and KFSerivng",
Long: ``,
PreRunE: preRunE,
RunE: func(cmd *cobra.Command, args []string) error {
modelURI := args[0]
dstDir := args[1]

// Get username and password from environment
// Here AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID are used
// because Seldon Core does not support renaming the environment variable name.
username := viper.GetString("AWS_ACCESS_KEY_ID")
pwd := viper.GetString("AWS_SECRET_ACCESS_KEY")
// Get the host from the URL.
strs := strings.Split(modelURI, "/")
if len(strs) == 0 {
return fmt.Errorf("Failed to get the host from %s", modelURI)
}
fmt.Printf("Logging to the remote registry %s\n", strs[0])
fmt.Printf("Username: %s\n", username)
if err := ormbClient.Login(strs[0], username, pwd, true); err != nil {
return err
}

// Recreate the ORMB client to let it know the registry and config.
rootPath, err := filepath.Abs(viper.GetString("rootPath"))
if err != nil {
return err
}
fmt.Printf("Using %s as the root path\n", rootPath)

ormbClient, err = ormb.NewOCIORMB(
oci.ClientOptRootPath(rootPath),
oci.ClientOptWriter(os.Stdout),
oci.ClientOptPlainHTTP(plainHTTPOpt),
)
if err != nil {
return err
}

// Pull the model from the remote registry.
if err := ormbClient.Pull(modelURI); err != nil {
return err
}
// Export it to the specified directory.
if err := ormbClient.Export(modelURI, dstDir); err != nil {
return err
}

// Move the files in model directory to the upper directory.
// Seldon core will run `--model_base_path=dstDir` directly.
originalDir, err := filepath.Abs(
filepath.Join(dstDir, consts.ORMBModelDirectory))
if err != nil {
return err
}
destinationDir, err := filepath.Abs(dstDir)
if err != nil {
return err
}
files, err := ioutil.ReadDir(originalDir)
if err != nil {
return err
}
for _, f := range files {
oldPath := filepath.Join(originalDir, f.Name())
newPath := filepath.Join(destinationDir, f.Name())
fmt.Printf("Moving %s to %s\n", oldPath, newPath)
if err := os.Rename(oldPath, newPath); err != nil {
return err
}
}
return nil
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

viper.AutomaticEnv()

logrus.SetLevel(logrus.DebugLevel)
}
22 changes: 22 additions & 0 deletions cmd/ormb-storage-initializer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright © 2020 Caicloud Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main

import "github.com/caicloud/ormb/cmd/ormb-storage-initializer/cmd"

func main() {
cmd.Execute()
}
Binary file added docs/images/harbor-projects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/harbor-registration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/harbor-tf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8150ac1

Please sign in to comment.