-
Notifications
You must be signed in to change notification settings - Fork 1.8k
commands/{build,cmdutil},pkg/generator: remove build.sh #561
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
Changes from all commits
cf4b48e
038cfcf
f045683
37acb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "log" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil" | ||
|
|
@@ -144,14 +145,20 @@ func buildFunc(cmd *cobra.Command, args []string) { | |
| cmdError.ExitWithError(cmdError.ExitBadArgs, fmt.Errorf("build command needs exactly 1 argument")) | ||
| } | ||
|
|
||
| cmdutil.MustInProjectRoot() | ||
| goBuildEnv := append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0") | ||
| wd, err := os.Getwd() | ||
| if err != nil { | ||
| cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("could not identify current working directory: %v", err)) | ||
| } | ||
|
|
||
| // Don't need to buld go code if Ansible Operator | ||
| if mainExists() { | ||
| bcmd := exec.Command(build) | ||
| bcmd.Env = append(os.Environ(), fmt.Sprintf("TEST_LOCATION=%v", testLocationBuild)) | ||
| bcmd.Env = append(bcmd.Env, fmt.Sprintf("ENABLE_TESTS=%v", enableTests)) | ||
| o, err := bcmd.CombinedOutput() | ||
| buildCmd := exec.Command("go", "build", "-o", filepath.Join(wd, "tmp/_output/bin", filepath.Base(wd)), filepath.Join(cmdutil.GetCurrPkg(), "cmd", filepath.Base(wd))) | ||
| buildCmd.Env = goBuildEnv | ||
| o, err := buildCmd.CombinedOutput() | ||
| if err != nil { | ||
| cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to build: (%v)", string(o))) | ||
| log.Fatalf("failed to build operator binary: %v (%v)", err, string(o)) | ||
| } | ||
| fmt.Fprintln(os.Stdout, string(o)) | ||
| } | ||
|
|
@@ -173,6 +180,18 @@ func buildFunc(cmd *cobra.Command, args []string) { | |
| fmt.Fprintln(os.Stdout, string(o)) | ||
|
|
||
| if enableTests { | ||
| buildTestCmd := exec.Command("go", "test", "-c", "-o", filepath.Join(wd, "tmp/_output/bin", filepath.Base(wd)+"-test"), testLocationBuild+"/...") | ||
| buildTestCmd.Env = goBuildEnv | ||
| o, err := buildTestCmd.CombinedOutput() | ||
| if err != nil { | ||
| log.Fatalf("failed to build test binary: %v (%v)", err, string(o)) | ||
| } | ||
| fmt.Fprintln(os.Stdout, string(o)) | ||
| // if a user is using an older sdk repo as their library, make sure they have required build files | ||
| _, err = os.Stat("tmp/build/test-framework/Dockerfile") | ||
| if err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a logging to indicate that you are missing the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. offline discussion: generator already prints out the file it is going to generate. so we don't need to add extra a logging statement. |
||
| generator.RenderTestingContainerFiles(filepath.Join(wd, "tmp/build"), filepath.Base(wd)) | ||
| } | ||
| testDbcmd := exec.Command("docker", "build", ".", "-f", "tmp/build/test-framework/Dockerfile", "-t", image, "--build-arg", "NAMESPACEDMAN="+namespacedManBuild, "--build-arg", "BASEIMAGE="+baseImageName) | ||
| o, err = testDbcmd.CombinedOutput() | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command breaks support for Ansible Operator because
config/config.yamldoesn't exist in our project. Why doesn't this function look for the Dockerfile instead? It would verify we are in the project root and be agnostic to the type of operator.