Skip to content

Zip file limit #457

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 7 commits into from
Sep 13, 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
3 changes: 2 additions & 1 deletion cli/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ var deleteCmd = &cobra.Command{
if len(args) == 1 {
appName = args[0]
} else {
appName, err = appNameFromConfig()
config, err := readConfig()
if err != nil {
errors.Exit(err)
}
appName = config.App.Name
}

params := map[string]string{
Expand Down
54 changes: 32 additions & 22 deletions cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cortexlabs/cortex/pkg/operator/api/userconfig"
)

var MaxProjectSize = 1024 * 1024 * 50
var flagDeployForce bool

func init() {
Expand All @@ -51,7 +52,7 @@ var deployCmd = &cobra.Command{

func deploy(force bool, ignoreCache bool) {
root := mustAppRoot()
_, err := appNameFromConfig() // Check proper cortex.yaml
config, err := readConfig() // Check proper cortex.yaml
if err != nil {
errors.Exit(err)
}
Expand All @@ -66,34 +67,43 @@ func deploy(force bool, ignoreCache bool) {
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)
uploadBytes := map[string][]byte{
"cortex.yaml": configBytes,
}

projectZipBytes, err := zip.ToMem(&zip.Input{
FileLists: []zip.FileListInput{
{
Sources: projectPaths,
RemovePrefix: root,
if config.AreProjectFilesRequired() {
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: projectPaths,
RemovePrefix: root,
},
},
},
})
})

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

if len(projectZipBytes) > MaxProjectSize {
errors.Exit(errors.New("zipped project folder exceeds " + s.Int(MaxProjectSize) + " bytes"))
}

uploadBytes["project.zip"] = projectZipBytes
}

uploadInput := &HTTPUploadInput{
Bytes: map[string][]byte{
"cortex.yaml": configBytes,
"project.zip": projectZipBytes,
},
Bytes: uploadBytes,
}

response, err := HTTPUpload("/deploy", uploadInput, params)
Expand Down
12 changes: 8 additions & 4 deletions cli/cmd/lib_config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,26 @@ func pythonPaths(dir string) []string {
return pyPaths
}

func appNameFromConfig() (string, error) {
func readConfig() (*userconfig.Config, error) {
appRoot := mustAppRoot()
return userconfig.ReadAppName(filepath.Join(appRoot, "cortex.yaml"), "cortex.yaml")
config, err := userconfig.ReadConfigFile(filepath.Join(appRoot, "cortex.yaml"), "cortex.yaml")
if err != nil {
return nil, err
}
return config, nil
}

func AppNameFromFlagOrConfig() (string, error) {
if flagAppName != "" {
return flagAppName, nil
}

appName, err := appNameFromConfig()
config, err := readConfig()
if err != nil {
return "", err
}

return appName, nil
return config.App.Name, nil
}

func IsAppNameSpecified() bool {
Expand Down
13 changes: 13 additions & 0 deletions pkg/operator/api/userconfig/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ func (api *API) Validate(projectFileMap map[string][]byte) error {
return nil
}

func (api *API) AreProjectFilesRequired() bool {
return api.RequestHandler != nil
}

func (api *API) GetResourceType() resource.Type {
return resource.APIType
}
Expand All @@ -311,3 +315,12 @@ func (apis APIs) Names() []string {
}
return names
}

func (apis APIs) AreProjectFilesRequired() bool {
for _, api := range apis {
if api.AreProjectFilesRequired() {
return true
}
}
return false
}
26 changes: 18 additions & 8 deletions pkg/operator/api/userconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ var typeFieldValidation = &cr.StructFieldValidation{
}

func (config *Config) Validate(projectBytes []byte) error {
if err := config.App.Validate(); err != nil {
return err
}
err := config.App.Validate()

projectFileMap, err := zip.UnzipMemToMem(projectBytes)
if err != nil {
return err
}

projectFileMap := make(map[string][]byte)

if config.AreProjectFilesRequired() {
projectFileMap, err = zip.UnzipMemToMem(projectBytes)
if err != nil {
return err
}
}

if config.APIs != nil {
if err := config.APIs.Validate(projectFileMap); err != nil {
return err
Expand All @@ -55,6 +61,10 @@ func (config *Config) Validate(projectBytes []byte) error {
return nil
}

func (config *Config) AreProjectFilesRequired() bool {
return config.APIs.AreProjectFilesRequired()
}

func New(filePath string, configBytes []byte) (*Config, error) {
var err error

Expand Down Expand Up @@ -118,16 +128,16 @@ func New(filePath string, configBytes []byte) (*Config, error) {
return config, nil
}

func ReadAppName(filePath string, relativePath string) (string, error) {
func ReadConfigFile(filePath string, relativePath string) (*Config, error) {
configBytes, err := files.ReadFileBytes(filePath)
if err != nil {
return "", errors.Wrap(err, relativePath, ErrorReadConfig().Error())
return nil, errors.Wrap(err, relativePath, ErrorReadConfig().Error())
}

config, err := New(relativePath, configBytes)
if err != nil {
return "", err
return nil, err
}

return config.App.Name, nil
return config, nil
}
13 changes: 5 additions & 8 deletions pkg/operator/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ func New(
}
ctx.APIs = apis

for _, api := range ctx.APIs {
if api.RequestHandler != nil {
ctx.ProjectID = projectID
ctx.ProjectKey = filepath.Join(consts.ProjectsDir, ctx.ProjectID+".zip")
if err = config.AWS.UploadBytesToS3(projectBytes, ctx.ProjectKey); err != nil {
return nil, err
}
break
if userconf.AreProjectFilesRequired() {
ctx.ProjectID = projectID
ctx.ProjectKey = filepath.Join(consts.ProjectsDir, ctx.ProjectID+".zip")
if err = config.AWS.UploadBytesToS3(projectBytes, ctx.ProjectKey); err != nil {
return nil, err
}
}

Expand Down
14 changes: 0 additions & 14 deletions pkg/operator/endpoints/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func Deploy(w http.ResponseWriter, r *http.Request) {
}

projectBytes, err := files.ReadReqFile(r, "project.zip")
if err != nil {
RespondError(w, errors.WithStack(err))
return
}

userconf, err := userconfig.New("cortex.yaml", configBytes)
if err != nil {
Expand All @@ -65,22 +61,12 @@ func Deploy(w http.ResponseWriter, r *http.Request) {
return
}

if len(projectBytes) == 0 {
RespondError(w, ErrorFormFileMustBeProvided("project.zip"))
return
}

ctx, err := ocontext.New(userconf, projectBytes, ignoreCache)
if err != nil {
RespondError(w, err)
return
}

if err != nil {
RespondError(w, err)
return
}

err = workloads.PopulateWorkloadIDs(ctx)
if err != nil {
RespondError(w, err)
Expand Down