From 93e7eae744ca6f87d707c2fdf8c8d4f28429ae17 Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Mon, 27 Jul 2020 09:39:42 -0700 Subject: [PATCH] cmd/operator-sdk: remove `build` subcommand --- changelog/fragments/remove-build.yaml | 12 ++ cmd/operator-sdk/build/cmd.go | 130 ------------------ cmd/operator-sdk/cli/cli.go | 2 - go.mod | 1 - go.sum | 2 - hack/tests/e2e-ansible-molecule.sh | 4 +- website/content/en/docs/cli/operator-sdk.md | 1 - .../content/en/docs/cli/operator-sdk_build.md | 46 ------- 8 files changed, 14 insertions(+), 184 deletions(-) create mode 100644 changelog/fragments/remove-build.yaml delete mode 100644 cmd/operator-sdk/build/cmd.go delete mode 100644 website/content/en/docs/cli/operator-sdk_build.md diff --git a/changelog/fragments/remove-build.yaml b/changelog/fragments/remove-build.yaml new file mode 100644 index 00000000000..4df94121cea --- /dev/null +++ b/changelog/fragments/remove-build.yaml @@ -0,0 +1,12 @@ +entries: + - description: Removed the `build` subcommand. + kind: removal + breaking: true + migration: + header: Remove `operator-sdk build` references from project + body: > + `operator-sdk build` was removed in favor of `make docker-build`. Any image build args passed + to the removed command can be directly added to the `docker-build` Makefile rule. + Any Go build args passed to the removed command can be directly added to the project's Dockerfile. + The image builder can be substituted for `docker` in the `docker-build` Makefile rule, assuming + flags are the same. diff --git a/cmd/operator-sdk/build/cmd.go b/cmd/operator-sdk/build/cmd.go deleted file mode 100644 index 8bb3dbb216d..00000000000 --- a/cmd/operator-sdk/build/cmd.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018 The Operator-SDK 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 build - -import ( - "fmt" - "os/exec" - "path/filepath" - - "github.com/operator-framework/operator-sdk/internal/util/projutil" - - "github.com/google/shlex" - log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" -) - -var ( - imageBuildArgs string - imageBuilder string - - // todo: remove when the legacy layout is no longer supported - // Deprecated - goBuildArgs string -) - -func NewCmd() *cobra.Command { - buildCmd := &cobra.Command{ - Use: "build ", - Short: "Compiles code and builds artifacts", - Long: `The operator-sdk build command compiles the Operator code into an executable binary -and generates the Dockerfile manifest. - -'< image >' is the container image to be built, e.g. "quay.io/example/operator:v0.0.1". -This image will be automatically set in the deployment manifests. - -After build completes, the image would be built locally in docker. Then it needs to -be pushed to remote registry. -For example: - - $ operator-sdk build quay.io/example/operator:v0.0.1 - $ docker push quay.io/example/operator:v0.0.1 -`, - RunE: buildFunc, - } - buildCmd.Flags().StringVar(&imageBuildArgs, "image-build-args", "", - "Extra image build arguments as one string such as \"--build-arg https_proxy=$https_proxy\"") - buildCmd.Flags().StringVar(&imageBuilder, "image-builder", "docker", - "Tool to build OCI images. One of: [docker, podman, buildah]") - - // todo: remove when the legacy layout is no longer supported - if !projutil.HasProjectFile() { - buildCmd.Flags().StringVar(&goBuildArgs, "go-build-args", "", - "Extra Go build arguments as one string such as \"-ldflags -X=main.xyz=abc\"") - } - return buildCmd -} - -func createBuildCommand(imageBuilder, context, dockerFile, image string, imageBuildArgs ...string) (*exec.Cmd, error) { - var args []string - switch imageBuilder { - case "docker", "podman": - args = append(args, "build", "-f", dockerFile, "-t", image) - case "buildah": - args = append(args, "bud", "--format=docker", "-f", dockerFile, "-t", image) - default: - return nil, fmt.Errorf("%s is not supported image builder", imageBuilder) - } - - for _, bargs := range imageBuildArgs { - if bargs != "" { - splitArgs, err := shlex.Split(bargs) - if err != nil { - return nil, fmt.Errorf("image-build-args is not parseable: %v", err) - } - args = append(args, splitArgs...) - } - } - - args = append(args, context) - - return exec.Command(imageBuilder, args...), nil -} - -func buildFunc(cmd *cobra.Command, args []string) error { - if len(args) != 1 { - return fmt.Errorf("command %s requires exactly one argument", cmd.CommandPath()) - } - - image := args[0] - - if projutil.HasProjectFile() { - if err := doImageBuild("Dockerfile", image); err != nil { - log.Fatalf("Failed to build image %s: %v", image, err) - } - return nil - } - - // todo: remove when the legacy layout is no longer supported - // note that the above if will no longer be required as well. - if err := doImageBuild(filepath.Join("build", "Dockerfile"), image); err != nil { - log.Fatalf("Failed to build image %s: %v", image, err) - } - return nil -} - -// doImageBuild will execute the build command for the given Dockerfile path and image -func doImageBuild(dockerFilePath, image string) error { - log.Infof("Building OCI image %s", image) - buildCmd, err := createBuildCommand(imageBuilder, ".", dockerFilePath, image, imageBuildArgs) - if err != nil { - return err - } - if err := projutil.ExecCmd(buildCmd); err != nil { - return err - } - log.Info("Operator build complete.") - return nil -} diff --git a/cmd/operator-sdk/cli/cli.go b/cmd/operator-sdk/cli/cli.go index 24d5fd31e6c..ca851e348a5 100644 --- a/cmd/operator-sdk/cli/cli.go +++ b/cmd/operator-sdk/cli/cli.go @@ -15,7 +15,6 @@ package cli import ( - "github.com/operator-framework/operator-sdk/cmd/operator-sdk/build" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/bundle" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/cleanup" "github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion" @@ -37,7 +36,6 @@ import ( ) var commands = []*cobra.Command{ - build.NewCmd(), bundle.NewCmd(), cleanup.NewCmd(), completion.NewCmd(), diff --git a/go.mod b/go.mod index b773f2952d2..0ce08cfc23b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/fatih/structtag v1.1.0 github.com/go-logr/logr v0.1.0 github.com/go-logr/zapr v0.1.1 - github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 github.com/kr/text v0.1.0 github.com/markbates/inflect v1.0.4 diff --git a/go.sum b/go.sum index 3f38a5f18a6..d9f01fc34cf 100644 --- a/go.sum +++ b/go.sum @@ -372,8 +372,6 @@ github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/hack/tests/e2e-ansible-molecule.sh b/hack/tests/e2e-ansible-molecule.sh index 78109ff8b6b..72434ddd3e1 100755 --- a/hack/tests/e2e-ansible-molecule.sh +++ b/hack/tests/e2e-ansible-molecule.sh @@ -58,12 +58,12 @@ KUSTOMIZE_PATH=${KUSTOMIZE} TEST_OPERATOR_NAMESPACE=default molecule test -s kin popd popd -KUSTOMIZE_PATH=${KUSTOMIZE} +KUSTOMIZE_PATH=${KUSTOMIZE} header_text "Test Ansible Molecule scenarios" pushd "${ROOTDIR}/test/ansible" DEST_IMAGE="quay.io/example/ansible-test-operator:v0.0.1" sed -i".bak" -E -e 's/(FROM quay.io\/operator-framework\/ansible-operator)(:.*)?/\1:dev/g' build/Dockerfile; rm -f build/Dockerfile.bak -operator-sdk build "$DEST_IMAGE" --image-build-args="--no-cache" +docker build -f build/Dockerfile -t "$DEST_IMAGE" --no-cache . load_image_if_kind "$DEST_IMAGE" OPERATOR_PULL_POLICY=Never OPERATOR_IMAGE=${DEST_IMAGE} TEST_CLUSTER_PORT=24443 TEST_OPERATOR_NAMESPACE=osdk-test molecule test --all diff --git a/website/content/en/docs/cli/operator-sdk.md b/website/content/en/docs/cli/operator-sdk.md index 493ffabcafd..92217d388d0 100644 --- a/website/content/en/docs/cli/operator-sdk.md +++ b/website/content/en/docs/cli/operator-sdk.md @@ -66,7 +66,6 @@ operator-sdk [flags] ### SEE ALSO -* [operator-sdk build](../operator-sdk_build) - Compiles code and builds artifacts * [operator-sdk bundle](../operator-sdk_bundle) - Manage operator bundle metadata * [operator-sdk cleanup](../operator-sdk_cleanup) - Clean up an Operator deployed with the 'run' subcommand * [operator-sdk completion](../operator-sdk_completion) - Generators for shell completions diff --git a/website/content/en/docs/cli/operator-sdk_build.md b/website/content/en/docs/cli/operator-sdk_build.md deleted file mode 100644 index 79c43ff4c25..00000000000 --- a/website/content/en/docs/cli/operator-sdk_build.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: "operator-sdk build" ---- -## operator-sdk build - -Compiles code and builds artifacts - -### Synopsis - -The operator-sdk build command compiles the Operator code into an executable binary -and generates the Dockerfile manifest. - -'< image >' is the container image to be built, e.g. "quay.io/example/operator:v0.0.1". -This image will be automatically set in the deployment manifests. - -After build completes, the image would be built locally in docker. Then it needs to -be pushed to remote registry. -For example: - - $ operator-sdk build quay.io/example/operator:v0.0.1 - $ docker push quay.io/example/operator:v0.0.1 - - -``` -operator-sdk build [flags] -``` - -### Options - -``` - --go-build-args string Extra Go build arguments as one string such as "-ldflags -X=main.xyz=abc" - -h, --help help for build - --image-build-args string Extra image build arguments as one string such as "--build-arg https_proxy=$https_proxy" - --image-builder string Tool to build OCI images. One of: [docker, podman, buildah] (default "docker") -``` - -### Options inherited from parent commands - -``` - --verbose Enable verbose logging -``` - -### SEE ALSO - -* [operator-sdk](../operator-sdk) - Development kit for building Kubernetes extensions and tools. -