-
Notifications
You must be signed in to change notification settings - Fork 607
Cortex Patch #1651
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
Cortex Patch #1651
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0d03ebf
Progress
vishalbollu 273ffa4
progress
vishalbollu 4509533
Merge branch 'master' into patch
vishalbollu ee8edd8
Patch progress
vishalbollu cfa0d32
Self review
vishalbollu 66597ea
Merge branch 'master' into patch
vishalbollu 1f1391e
Respond to PR comments
vishalbollu 6c8777f
Merge branch 'patch' of github.com:cortexlabs/cortex into patch
vishalbollu 2b04644
Cast arrays of maps to str map
vishalbollu db4d913
Update casting to be JSON marshallable
vishalbollu 2a92695
Update client.py
vishalbollu 0e17ef3
Merge branch 'master' into patch
vishalbollu 4cac46f
Update client.py
vishalbollu 25ad1ef
Adding patch documentation to CLI and python client
vishalbollu 3b38fba
Merge branch 'master' into patch
deliahu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2020 Cortex Labs, Inc. | ||
|
||
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 cluster | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"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/operator/schema" | ||
) | ||
|
||
func Patch(operatorConfig OperatorConfig, configPath string, force bool) ([]schema.DeployResult, error) { | ||
params := map[string]string{ | ||
"force": s.Bool(force), | ||
"configFileName": filepath.Base(configPath), | ||
} | ||
|
||
configBytes, err := files.ReadFileBytes(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := HTTPPostJSON(operatorConfig, "/patch", configBytes, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var deployResults []schema.DeployResult | ||
if err := json.Unmarshal(response, &deployResults); err != nil { | ||
return nil, errors.Wrap(err, "/patch", string(response)) | ||
} | ||
|
||
return deployResults, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2020 Cortex Labs, Inc. | ||
|
||
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" | ||
"strings" | ||
|
||
"github.com/cortexlabs/cortex/cli/cluster" | ||
"github.com/cortexlabs/cortex/cli/local" | ||
"github.com/cortexlabs/cortex/cli/types/flags" | ||
"github.com/cortexlabs/cortex/pkg/lib/exit" | ||
libjson "github.com/cortexlabs/cortex/pkg/lib/json" | ||
"github.com/cortexlabs/cortex/pkg/lib/print" | ||
"github.com/cortexlabs/cortex/pkg/lib/telemetry" | ||
"github.com/cortexlabs/cortex/pkg/operator/schema" | ||
"github.com/cortexlabs/cortex/pkg/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
_flagPatchEnv string | ||
_flagPatchForce bool | ||
) | ||
|
||
func patchInit() { | ||
_patchCmd.Flags().SortFlags = false | ||
_patchCmd.Flags().StringVarP(&_flagPatchEnv, "env", "e", getDefaultEnv(_generalCommandType), "environment to use") | ||
_patchCmd.Flags().BoolVarP(&_flagPatchForce, "force", "f", false, "override the in-progress api update") | ||
_patchCmd.Flags().VarP(&_flagOutput, "output", "o", fmt.Sprintf("output format: one of %s", strings.Join(flags.UserOutputTypeStrings(), "|"))) | ||
} | ||
|
||
var _patchCmd = &cobra.Command{ | ||
Use: "patch [CONFIG_FILE]", | ||
Short: "update API configuration for a deployed API", | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
env, err := ReadOrConfigureEnv(_flagPatchEnv) | ||
if err != nil { | ||
telemetry.Event("cli.patch") | ||
exit.Error(err) | ||
} | ||
telemetry.Event("cli.patch", map[string]interface{}{"provider": env.Provider.String(), "env_name": env.Name}) | ||
|
||
err = printEnvIfNotSpecified(_flagPatchEnv, cmd) | ||
if err != nil { | ||
exit.Error(err) | ||
} | ||
|
||
configPath := getConfigPath(args) | ||
|
||
var deployResults []schema.DeployResult | ||
if env.Provider == types.AWSProviderType { | ||
deployResults, err = cluster.Patch(MustGetOperatorConfig(env.Name), configPath, _flagPatchForce) | ||
if err != nil { | ||
exit.Error(err) | ||
} | ||
} else { | ||
deployResults, err = local.Patch(env, configPath) | ||
if err != nil { | ||
exit.Error(err) | ||
} | ||
} | ||
|
||
switch _flagOutput { | ||
case flags.JSONOutputType: | ||
bytes, err := libjson.Marshal(deployResults) | ||
if err != nil { | ||
exit.Error(err) | ||
} | ||
fmt.Println(string(bytes)) | ||
case flags.PrettyOutputType: | ||
message := deployMessage(deployResults, env.Name) | ||
if didAnyResultsError(deployResults) { | ||
print.StderrBoldFirstBlock(message) | ||
} else { | ||
print.BoldFirstBlock(message) | ||
} | ||
} | ||
|
||
if didAnyResultsError(deployResults) { | ||
exit.Error(nil) | ||
} | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright 2020 Cortex Labs, Inc. | ||
|
||
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 local | ||
|
||
import ( | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/cortexlabs/cortex/cli/types/cliconfig" | ||
"github.com/cortexlabs/cortex/pkg/lib/files" | ||
"github.com/cortexlabs/cortex/pkg/operator/schema" | ||
"github.com/cortexlabs/cortex/pkg/types" | ||
"github.com/cortexlabs/cortex/pkg/types/spec" | ||
"github.com/cortexlabs/cortex/pkg/types/userconfig" | ||
) | ||
|
||
func Patch(env cliconfig.Environment, configPath string) ([]schema.DeployResult, error) { | ||
configFileName := filepath.Base(configPath) | ||
|
||
configBytes, err := files.ReadFileBytes(configPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiConfigs, err := spec.ExtractAPIConfigs(configBytes, types.LocalProviderType, configFileName, nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
deployResults := []schema.DeployResult{} | ||
for i := range apiConfigs { | ||
apiConfig := &apiConfigs[i] | ||
apiResponse, err := GetAPI(apiConfig.Name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
localProjectDir := apiResponse[0].Spec.LocalProjectDir | ||
|
||
projectFileList, err := findProjectFiles(localProjectDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
projectFiles, err := newProjectFiles(projectFileList, localProjectDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
deployResult, err := deploy(env, []userconfig.API{*apiConfig}, projectFiles, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
deployResults = append(deployResults, deployResult...) | ||
} | ||
|
||
return deployResults, nil | ||
} | ||
|
||
func findProjectFiles(projectRoot string) ([]string, error) { | ||
ignoreFns := []files.IgnoreFn{ | ||
files.IgnoreCortexDebug, | ||
files.IgnoreHiddenFiles, | ||
files.IgnoreHiddenFolders, | ||
files.IgnorePythonGeneratedFiles, | ||
} | ||
|
||
cortexIgnorePath := path.Join(projectRoot, ".cortexignore") | ||
if files.IsFile(cortexIgnorePath) { | ||
cortexIgnore, err := files.GitIgnoreFn(cortexIgnorePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ignoreFns = append(ignoreFns, cortexIgnore) | ||
} | ||
|
||
projectPaths, err := files.ListDirRecursive(projectRoot, false, ignoreFns...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Include .env file containing environment variables | ||
dotEnvPath := path.Join(projectRoot, ".env") | ||
if files.IsFile(dotEnvPath) { | ||
projectPaths = append(projectPaths, dotEnvPath) | ||
} | ||
|
||
return projectPaths, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.