From 8ef7edfa4043a2bba954d876b442bac11994ab0b Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 18 Apr 2019 16:38:29 -0700 Subject: [PATCH 1/2] Remove bazel plugin & revert back to original For reference, initial PR that added this change was #1707 and #1662 --- integration/run_test.go | 4 - integration/testdata/plugin/local/bazel/BUILD | 9 - .../testdata/plugin/local/bazel/WORKSPACE | 30 --- .../plugin/local/bazel/k8s/k8s-pod.yaml | 8 - .../testdata/plugin/local/bazel/main.go | 13 - .../testdata/plugin/local/bazel/skaffold.yaml | 10 - .../builders => build}/bazel/dependencies.go | 0 .../bazel/dependencies_test.go | 0 pkg/skaffold/build/local/bazel.go | 153 +++++++++-- .../local/bazel_test.go} | 2 +- pkg/skaffold/build/local/local.go | 2 +- pkg/skaffold/build/plugin/core.go | 2 - pkg/skaffold/plugin/builders/bazel/bazel.go | 43 ---- pkg/skaffold/plugin/builders/bazel/builder.go | 122 --------- .../plugin/builders/bazel/builder_test.go | 103 -------- pkg/skaffold/plugin/builders/bazel/local.go | 240 ------------------ 16 files changed, 133 insertions(+), 608 deletions(-) delete mode 100644 integration/testdata/plugin/local/bazel/BUILD delete mode 100644 integration/testdata/plugin/local/bazel/WORKSPACE delete mode 100644 integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml delete mode 100644 integration/testdata/plugin/local/bazel/main.go delete mode 100644 integration/testdata/plugin/local/bazel/skaffold.yaml rename pkg/skaffold/{plugin/builders => build}/bazel/dependencies.go (100%) rename pkg/skaffold/{plugin/builders => build}/bazel/dependencies_test.go (100%) rename pkg/skaffold/{plugin/builders/bazel/local_test.go => build/local/bazel_test.go} (99%) delete mode 100644 pkg/skaffold/plugin/builders/bazel/bazel.go delete mode 100644 pkg/skaffold/plugin/builders/bazel/builder.go delete mode 100644 pkg/skaffold/plugin/builders/bazel/builder_test.go delete mode 100644 pkg/skaffold/plugin/builders/bazel/local.go diff --git a/integration/run_test.go b/integration/run_test.go index ae32e36d823..6fd969e99ad 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -104,10 +104,6 @@ func TestRun(t *testing.T) { dir: "testdata/plugin/gcb", deployments: []string{"leeroy-app", "leeroy-web"}, remoteOnly: true, - }, { - description: "bazel plugin in local exec environment", - dir: "testdata/plugin/local/bazel", - pods: []string{"bazel"}, }, { description: "docker plugin in local exec environment", dir: "testdata/plugin/local/docker", diff --git a/integration/testdata/plugin/local/bazel/BUILD b/integration/testdata/plugin/local/bazel/BUILD deleted file mode 100644 index ba00afe13d3..00000000000 --- a/integration/testdata/plugin/local/bazel/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -load("@io_bazel_rules_docker//go:image.bzl", "go_image") - -go_image( - name = "skaffold_example", - srcs = ["main.go"], - goos = "linux", - goarch = "amd64", - static = "on", -) diff --git a/integration/testdata/plugin/local/bazel/WORKSPACE b/integration/testdata/plugin/local/bazel/WORKSPACE deleted file mode 100644 index 6f90ba50199..00000000000 --- a/integration/testdata/plugin/local/bazel/WORKSPACE +++ /dev/null @@ -1,30 +0,0 @@ -workspace(name = "skaffold") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "io_bazel_rules_docker", - strip_prefix = "rules_docker-0.7.0", - urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.7.0.tar.gz"], - sha256 = "aed1c249d4ec8f703edddf35cbe9dfaca0b5f5ea6e4cd9e83e99f3b0d1136c3d", -) - -http_archive( - name = "io_bazel_rules_go", - urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.16.5/rules_go-0.16.5.tar.gz"], - sha256 = "7be7dc01f1e0afdba6c8eb2b43d2fa01c743be1b9273ab1eaf6c233df078d705", -) - -load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") - -go_rules_dependencies() -go_register_toolchains( - go_version = "1.10.1", -) - -load( - "@io_bazel_rules_docker//go:image.bzl", - _go_image_repos = "repositories", -) - -_go_image_repos() \ No newline at end of file diff --git a/integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml b/integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml deleted file mode 100644 index 2ecd153fb4f..00000000000 --- a/integration/testdata/plugin/local/bazel/k8s/k8s-pod.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: bazel -spec: - containers: - - name: bazel - image: gcr.io/k8s-skaffold/skaffold-bazel diff --git a/integration/testdata/plugin/local/bazel/main.go b/integration/testdata/plugin/local/bazel/main.go deleted file mode 100644 index 8f98567919a..00000000000 --- a/integration/testdata/plugin/local/bazel/main.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import ( - "fmt" - "time" -) - -func main() { - for { - fmt.Println("Hello bazel!!!!") - time.Sleep(time.Second * 1) - } -} diff --git a/integration/testdata/plugin/local/bazel/skaffold.yaml b/integration/testdata/plugin/local/bazel/skaffold.yaml deleted file mode 100644 index 4619dfd41f2..00000000000 --- a/integration/testdata/plugin/local/bazel/skaffold.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: skaffold/v1beta9 -kind: Config -build: - artifacts: - - image: gcr.io/k8s-skaffold/skaffold-bazel - context: . - plugin: - name: bazel - properties: - target: //:skaffold_example.tar diff --git a/pkg/skaffold/plugin/builders/bazel/dependencies.go b/pkg/skaffold/build/bazel/dependencies.go similarity index 100% rename from pkg/skaffold/plugin/builders/bazel/dependencies.go rename to pkg/skaffold/build/bazel/dependencies.go diff --git a/pkg/skaffold/plugin/builders/bazel/dependencies_test.go b/pkg/skaffold/build/bazel/dependencies_test.go similarity index 100% rename from pkg/skaffold/plugin/builders/bazel/dependencies_test.go rename to pkg/skaffold/build/bazel/dependencies_test.go diff --git a/pkg/skaffold/build/local/bazel.go b/pkg/skaffold/build/local/bazel.go index 7b1954df393..3d5f6d8a7e2 100644 --- a/pkg/skaffold/build/local/bazel.go +++ b/pkg/skaffold/build/local/bazel.go @@ -18,31 +18,140 @@ package local import ( "context" + "fmt" "io" + "net/http" + "os" + "os/exec" + "path/filepath" + "strings" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/bazel" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/go-containerregistry/pkg/v1/tarball" + "github.com/pkg/errors" ) -func (b *Builder) buildBazel(ctx context.Context, out io.Writer, a *latest.Artifact, tag string) (string, error) { - builder := bazel.NewBuilder() - builder.LocalBuild = b.cfg - builder.LocalDocker = b.localDocker - builder.KubeContext = b.kubeContext - builder.PushImages = b.pushImages - builder.PluginMode = false - - builder.Init(&runcontext.RunContext{ - Opts: &config.SkaffoldOptions{ - SkipTests: b.skipTests, - }, - Cfg: &latest.Pipeline{ - Build: latest.BuildConfig{ - ExecutionEnvironment: &latest.ExecutionEnvironment{}, - }, - }, - }) - return builder.BuildArtifact(ctx, out, a, tag) +func (b *Builder) buildBazel(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) { + args := []string{"build"} + a := artifact.ArtifactType.BazelArtifact + workspace := artifact.Workspace + args = append(args, a.BuildArgs...) + args = append(args, a.BuildTarget) + + // FIXME: is it possible to apply b.skipTests? + cmd := exec.CommandContext(ctx, "bazel", args...) + cmd.Dir = workspace + cmd.Stdout = out + cmd.Stderr = out + if err := util.RunCmd(cmd); err != nil { + return "", errors.Wrap(err, "running command") + } + + bazelBin, err := bazelBin(ctx, workspace, a) + if err != nil { + return "", errors.Wrap(err, "getting path of bazel-bin") + } + + tarPath := filepath.Join(bazelBin, buildTarPath(a.BuildTarget)) + + if b.pushImages { + return pushImage(tarPath, tag, b.insecureRegistries) + } + + return b.loadImage(ctx, out, tarPath, a, tag) +} + +// pushImage pushes the tarball image created by bazel +func pushImage(tarPath, tag string, insecureRegistries map[string]bool) (string, error) { + t, err := name.NewTag(tag, name.WeakValidation) + if err != nil { + return "", errors.Wrapf(err, "parsing tag %q", tag) + } + + auth, err := authn.DefaultKeychain.Resolve(t.Registry) + if err != nil { + return "", errors.Wrapf(err, "getting creds for %q", t) + } + + i, err := tarball.ImageFromPath(tarPath, nil) + if err != nil { + return "", errors.Wrapf(err, "reading image %q", tarPath) + } + + if err := remote.Write(t, i, auth, http.DefaultTransport); err != nil { + return "", errors.Wrapf(err, "writing image %q", t) + } + + return docker.RemoteDigest(tag, insecureRegistries) +} + +func (b *Builder) loadImage(ctx context.Context, out io.Writer, tarPath string, a *latest.BazelArtifact, tag string) (string, error) { + imageTar, err := os.Open(tarPath) + if err != nil { + return "", errors.Wrap(err, "opening image tarball") + } + defer imageTar.Close() + + bazelTag := buildImageTag(a.BuildTarget) + imageID, err := b.localDocker.Load(ctx, out, imageTar, bazelTag) + if err != nil { + return "", errors.Wrap(err, "loading image into docker daemon") + } + + if err := b.localDocker.Tag(ctx, imageID, tag); err != nil { + return "", errors.Wrap(err, "tagging the image") + } + + b.builtImages = append(b.builtImages, imageID) + return imageID, nil +} + +func bazelBin(ctx context.Context, workspace string, a *latest.BazelArtifact) (string, error) { + args := []string{"info", "bazel-bin"} + args = append(args, a.BuildArgs...) + + cmd := exec.CommandContext(ctx, "bazel", args...) + cmd.Dir = workspace + + buf, err := util.RunCmdOut(cmd) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(buf)), nil +} + +func trimTarget(buildTarget string) string { + //TODO(r2d4): strip off leading //:, bad + trimmedTarget := strings.TrimPrefix(buildTarget, "//") + // Useful if root target "//:target" + trimmedTarget = strings.TrimPrefix(trimmedTarget, ":") + + return trimmedTarget +} + +func buildTarPath(buildTarget string) string { + tarPath := trimTarget(buildTarget) + tarPath = strings.Replace(tarPath, ":", string(os.PathSeparator), 1) + + return tarPath +} + +func buildImageTag(buildTarget string) string { + imageTag := trimTarget(buildTarget) + imageTag = strings.TrimPrefix(imageTag, ":") + + //TODO(r2d4): strip off trailing .tar, even worse + imageTag = strings.TrimSuffix(imageTag, ".tar") + + if strings.Contains(imageTag, ":") { + return fmt.Sprintf("bazel/%s", imageTag) + } + + return fmt.Sprintf("bazel:%s", imageTag) } diff --git a/pkg/skaffold/plugin/builders/bazel/local_test.go b/pkg/skaffold/build/local/bazel_test.go similarity index 99% rename from pkg/skaffold/plugin/builders/bazel/local_test.go rename to pkg/skaffold/build/local/bazel_test.go index 85f097154da..1e06ba6cc60 100644 --- a/pkg/skaffold/plugin/builders/bazel/local_test.go +++ b/pkg/skaffold/build/local/bazel_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package bazel +package local import ( "context" diff --git a/pkg/skaffold/build/local/local.go b/pkg/skaffold/build/local/local.go index 36e42082413..85208f27646 100644 --- a/pkg/skaffold/build/local/local.go +++ b/pkg/skaffold/build/local/local.go @@ -23,11 +23,11 @@ import ( "strings" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/bazel" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/jib" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/bazel" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" "github.com/pkg/errors" diff --git a/pkg/skaffold/build/plugin/core.go b/pkg/skaffold/build/plugin/core.go index 3d00b38978b..4931c840aa6 100644 --- a/pkg/skaffold/build/plugin/core.go +++ b/pkg/skaffold/build/plugin/core.go @@ -23,7 +23,6 @@ import ( "github.com/hashicorp/go-hclog" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/bazel" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/docker" ) @@ -33,7 +32,6 @@ const DefaultPluginLogLevel = hclog.Info // SkaffoldCorePluginExecutionMap maps the core plugin name to the execution function var SkaffoldCorePluginExecutionMap = map[string]func() error{ "docker": docker.Execute(DefaultPluginLogLevel), - "bazel": bazel.Execute(DefaultPluginLogLevel), } // GetCorePluginFromEnv returns the core plugin name if env variables for plugins are set properly diff --git a/pkg/skaffold/plugin/builders/bazel/bazel.go b/pkg/skaffold/plugin/builders/bazel/bazel.go deleted file mode 100644 index 7d4ab5e72a7..00000000000 --- a/pkg/skaffold/plugin/builders/bazel/bazel.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 bazel - -import ( - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/shared" - "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-plugin" -) - -// Execute an image build with docker -func Execute(pluginLogLevel hclog.Level) func() error { - return func() error { - // pluginMap is the map of plugins we can dispense. - var pluginMap = map[string]plugin.Plugin{ - "bazel": &shared.BuilderPlugin{Impl: NewBuilder()}, - } - - plugin.Serve(&plugin.ServeConfig{ - Logger: hclog.New(&hclog.LoggerOptions{ - Level: pluginLogLevel, - }), - HandshakeConfig: shared.Handshake, - Plugins: pluginMap, - }) - - return nil - } -} diff --git a/pkg/skaffold/plugin/builders/bazel/builder.go b/pkg/skaffold/plugin/builders/bazel/builder.go deleted file mode 100644 index 27f195774b3..00000000000 --- a/pkg/skaffold/plugin/builders/bazel/builder.go +++ /dev/null @@ -1,122 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 bazel - -import ( - "context" - "io" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - yaml "gopkg.in/yaml.v2" -) - -// Builder builds artifacts with Bazel. -type Builder struct { - opts *config.SkaffoldOptions - env *latest.ExecutionEnvironment - *latest.LocalBuild - LocalDocker docker.LocalDaemon - LocalCluster bool - PushImages bool - PluginMode bool - KubeContext string - builtImages []string - insecureRegistries map[string]bool -} - -// NewBuilder creates a new Builder that builds artifacts with Bazel. -func NewBuilder() *Builder { - return &Builder{ - PluginMode: true, - } -} - -// Init stores skaffold options and the execution environment -func (b *Builder) Init(runCtx *runcontext.RunContext) error { - if b.PluginMode { - if err := event.SetupRPCClient(runCtx.Opts); err != nil { - logrus.Warn("error establishing gRPC connection to skaffold process; events will not be handled correctly") - logrus.Warn(err.Error()) - return err - } - } - b.opts = runCtx.Opts - b.env = runCtx.Cfg.Build.ExecutionEnvironment - b.insecureRegistries = runCtx.InsecureRegistries - return nil -} - -// Labels are labels specific to Bazel. -func (b *Builder) Labels() map[string]string { - return map[string]string{ - constants.Labels.Builder: "bazel", - } -} - -// DependenciesForArtifact returns the dependencies for this bazel artifact -func (b *Builder) DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error) { - if err := setArtifact(artifact); err != nil { - return nil, err - } - if artifact.BazelArtifact == nil { - return nil, errors.New("bazel artifact is nil") - } - paths, err := GetDependencies(ctx, artifact.Workspace, artifact.BazelArtifact) - if err != nil { - return nil, errors.Wrap(err, "getting bazel dependencies") - } - return util.AbsolutePaths(artifact.Workspace, paths), nil -} - -// Build is responsible for building artifacts in their respective execution environments -// The builder plugin is also responsible for setting any necessary defaults -func (b *Builder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - switch b.env.Name { - case constants.Local: - return b.local(ctx, out, tags, artifacts) - default: - return nil, errors.Errorf("%s is not a supported environment for builder bazel", b.env.Name) - } -} - -func setArtifact(artifact *latest.Artifact) error { - if artifact.ArtifactType.BazelArtifact != nil { - return nil - } - var a *latest.BazelArtifact - if err := yaml.UnmarshalStrict(artifact.BuilderPlugin.Contents, &a); err != nil { - return errors.Wrap(err, "unmarshalling bazel artifact") - } - if a == nil { - return errors.New("artifact is nil") - } - if a.BuildTarget == "" { - return errors.Errorf("%s must have an associated build target", artifact.ImageName) - } - artifact.ArtifactType.BazelArtifact = a - return nil -} diff --git a/pkg/skaffold/plugin/builders/bazel/builder_test.go b/pkg/skaffold/plugin/builders/bazel/builder_test.go deleted file mode 100644 index 896577376e5..00000000000 --- a/pkg/skaffold/plugin/builders/bazel/builder_test.go +++ /dev/null @@ -1,103 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 bazel - -import ( - "testing" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/testutil" -) - -func TestSetArtifact(t *testing.T) { - tests := []struct { - name string - initial *latest.Artifact - expected *latest.Artifact - shouldErr bool - }{ - { - name: "set target correctly", - initial: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte("target: myTarget"), - }, - }, - expected: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte("target: myTarget"), - }, - ArtifactType: latest.ArtifactType{ - BazelArtifact: &latest.BazelArtifact{ - BuildTarget: "myTarget", - }, - }, - }, - }, - { - name: "set target and build args correctly", - initial: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte(`target: myTarget -args: - - arg1=arg1 - - arg2=arg2`)}, - }, - expected: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte(`target: myTarget -args: - - arg1=arg1 - - arg2=arg2`)}, - ArtifactType: latest.ArtifactType{ - BazelArtifact: &latest.BazelArtifact{ - BuildTarget: "myTarget", - BuildArgs: []string{ - "arg1=arg1", - "arg2=arg2", - }, - }, - }, - }, - }, - { - name: "no target", - initial: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte(`args: - - arg=arg`)}, - }, - shouldErr: true, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err := setArtifact(test.initial) - if test.shouldErr { - testutil.CheckError(t, test.shouldErr, err) - return - } - testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, test.expected, test.initial) - }) - } -} diff --git a/pkg/skaffold/plugin/builders/bazel/local.go b/pkg/skaffold/plugin/builders/bazel/local.go deleted file mode 100644 index debe7daa923..00000000000 --- a/pkg/skaffold/plugin/builders/bazel/local.go +++ /dev/null @@ -1,240 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 bazel - -import ( - "context" - "fmt" - "io" - "net/http" - "os" - "os/exec" - "path/filepath" - "strings" - - configutil "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/google/go-containerregistry/pkg/authn" - "github.com/google/go-containerregistry/pkg/name" - "github.com/google/go-containerregistry/pkg/v1/remote" - "github.com/google/go-containerregistry/pkg/v1/tarball" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -// local sets any necessary defaults and then builds artifacts with bazel locally -func (b *Builder) local(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - localCluster, err := configutil.GetLocalCluster() - if err != nil { - return nil, errors.Wrap(err, "getting localCluster") - } - b.LocalCluster = localCluster - kubeContext, err := kubectx.CurrentContext() - if err != nil { - return nil, errors.Wrap(err, "getting current cluster context") - } - b.KubeContext = kubeContext - localDocker, err := docker.NewAPIClient(b.opts.Prune(), b.insecureRegistries) - if err != nil { - return nil, errors.Wrap(err, "getting docker client") - } - b.LocalDocker = localDocker - var l *latest.LocalBuild - if err := util.CloneThroughJSON(b.env.Properties, &l); err != nil { - return nil, errors.Wrap(err, "converting execution env to localBuild struct") - } - if l == nil { - l = &latest.LocalBuild{} - } - b.LocalBuild = l - var pushImages bool - if b.LocalBuild.Push == nil { - pushImages = !localCluster - logrus.Debugf("push value not present, defaulting to %t because localCluster is %t", pushImages, localCluster) - } else { - pushImages = *b.LocalBuild.Push - } - b.PushImages = pushImages - for _, a := range artifacts { - if err := setArtifact(a); err != nil { - return nil, errors.Wrapf(err, "setting artifact %s", a.ImageName) - } - } - return b.buildArtifacts(ctx, out, tags, artifacts) -} - -func (b *Builder) Prune(ctx context.Context, out io.Writer) error { - // TODO(nkubala): implement - return nil -} - -func (b *Builder) buildArtifacts(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - if b.LocalCluster { - color.Default.Fprintf(out, "Found [%s] context, using local docker daemon.\n", b.KubeContext) - } - return build.InSequence(ctx, out, tags, artifacts, b.runBuild) -} - -func (b *Builder) runBuild(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) { - digestOrImageID, err := b.BuildArtifact(ctx, out, artifact, tag) - if err != nil { - return "", errors.Wrap(err, "build artifact") - } - if b.PushImages { - digest := digestOrImageID - return tag + "@" + digest, nil - } - - // k8s doesn't recognize the imageID or any combination of the image name - // suffixed with the imageID, as a valid image name. - // So, the solution we chose is to create a tag, just for Skaffold, from - // the imageID, and use that in the manifests. - imageID := digestOrImageID - uniqueTag := artifact.ImageName + ":" + strings.TrimPrefix(imageID, "sha256:") - if err := b.LocalDocker.Tag(ctx, imageID, uniqueTag); err != nil { - return "", err - } - - return uniqueTag, nil -} - -// BuildArtifact builds the bazel artifact -func (b *Builder) BuildArtifact(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) { - args := []string{"build"} - a := artifact.ArtifactType.BazelArtifact - workspace := artifact.Workspace - args = append(args, a.BuildArgs...) - args = append(args, a.BuildTarget) - - // FIXME: is it possible to apply b.skipTests? - cmd := exec.CommandContext(ctx, "bazel", args...) - cmd.Dir = workspace - cmd.Stdout = out - cmd.Stderr = out - if err := util.RunCmd(cmd); err != nil { - return "", errors.Wrap(err, "running command") - } - - bazelBin, err := bazelBin(ctx, workspace, a) - if err != nil { - return "", errors.Wrap(err, "getting path of bazel-bin") - } - - tarPath := filepath.Join(bazelBin, buildTarPath(a.BuildTarget)) - - if b.PushImages { - return PushImage(tarPath, tag, b.insecureRegistries) - } - - return b.loadImage(ctx, out, tarPath, a, tag) -} - -// PushImage pushes the tarball image created by bazel -func PushImage(tarPath, tag string, insecureRegistries map[string]bool) (string, error) { - t, err := name.NewTag(tag, name.WeakValidation) - if err != nil { - return "", errors.Wrapf(err, "parsing tag %q", tag) - } - - auth, err := authn.DefaultKeychain.Resolve(t.Registry) - if err != nil { - return "", errors.Wrapf(err, "getting creds for %q", t) - } - - i, err := tarball.ImageFromPath(tarPath, nil) - if err != nil { - return "", errors.Wrapf(err, "reading image %q", tarPath) - } - - if err := remote.Write(t, i, auth, http.DefaultTransport); err != nil { - return "", errors.Wrapf(err, "writing image %q", t) - } - - return docker.RemoteDigest(tag, insecureRegistries) -} - -func (b *Builder) loadImage(ctx context.Context, out io.Writer, tarPath string, a *latest.BazelArtifact, tag string) (string, error) { - imageTar, err := os.Open(tarPath) - if err != nil { - return "", errors.Wrap(err, "opening image tarball") - } - defer imageTar.Close() - - bazelTag := buildImageTag(a.BuildTarget) - imageID, err := b.LocalDocker.Load(ctx, out, imageTar, bazelTag) - if err != nil { - return "", errors.Wrap(err, "loading image into docker daemon") - } - - if err := b.LocalDocker.Tag(ctx, imageID, tag); err != nil { - return "", errors.Wrap(err, "tagging the image") - } - - b.builtImages = append(b.builtImages, imageID) - return imageID, nil -} - -func bazelBin(ctx context.Context, workspace string, a *latest.BazelArtifact) (string, error) { - args := []string{"info", "bazel-bin"} - args = append(args, a.BuildArgs...) - - cmd := exec.CommandContext(ctx, "bazel", args...) - cmd.Dir = workspace - - buf, err := util.RunCmdOut(cmd) - if err != nil { - return "", err - } - - return strings.TrimSpace(string(buf)), nil -} - -func trimTarget(buildTarget string) string { - //TODO(r2d4): strip off leading //:, bad - trimmedTarget := strings.TrimPrefix(buildTarget, "//") - // Useful if root target "//:target" - trimmedTarget = strings.TrimPrefix(trimmedTarget, ":") - - return trimmedTarget -} - -func buildTarPath(buildTarget string) string { - tarPath := trimTarget(buildTarget) - tarPath = strings.Replace(tarPath, ":", string(os.PathSeparator), 1) - - return tarPath -} - -func buildImageTag(buildTarget string) string { - imageTag := trimTarget(buildTarget) - imageTag = strings.TrimPrefix(imageTag, ":") - - //TODO(r2d4): strip off trailing .tar, even worse - imageTag = strings.TrimSuffix(imageTag, ".tar") - - if strings.Contains(imageTag, ":") { - return fmt.Sprintf("bazel/%s", imageTag) - } - - return fmt.Sprintf("bazel:%s", imageTag) -} From c605b639233c166e7dc6df738b9bd3fe6d3113a8 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 18 Apr 2019 17:41:41 -0700 Subject: [PATCH 2/2] Remove docker plugin and revert to original code structure This changes removes the plugin code entirely, and moves docker back to `pkg/build/local`. It moves the `gcb` code back to `pkg/build/gcb`. For reference, the original PRs making this change were primarily #1717 and also #1577. --- cmd/skaffold/app/skaffold.go | 8 - integration/run_test.go | 9 - .../testdata/plugin/gcb/leeroy-app/Dockerfile | 9 - .../testdata/plugin/gcb/leeroy-app/app.go | 17 -- .../gcb/leeroy-app/kubernetes/deployment.yaml | 35 --- .../testdata/plugin/gcb/leeroy-web/Dockerfile | 7 - .../gcb/leeroy-web/kubernetes/deployment.yaml | 37 ---- .../testdata/plugin/gcb/leeroy-web/web.go | 26 --- integration/testdata/plugin/gcb/skaffold.yaml | 21 -- .../plugin/local/docker/leeroy-app/Dockerfile | 7 - .../plugin/local/docker/leeroy-app/app.go | 17 -- .../leeroy-app/kubernetes/deployment.yaml | 35 --- .../plugin/local/docker/leeroy-web/Dockerfile | 7 - .../leeroy-web/kubernetes/deployment.yaml | 37 ---- .../plugin/local/docker/leeroy-web/web.go | 26 --- .../plugin/local/docker/skaffold.yaml | 19 -- .../environments => build}/gcb/cloud_build.go | 0 .../environments => build}/gcb/desc.go | 0 .../environments => build}/gcb/desc_test.go | 0 .../environments => build}/gcb/docker.go | 0 .../environments => build}/gcb/docker_test.go | 0 .../{plugin/environments => build}/gcb/jib.go | 0 .../environments => build}/gcb/jib_test.go | 0 .../environments => build}/gcb/types.go | 0 pkg/skaffold/build/local/docker.go | 101 +++++++-- pkg/skaffold/build/plugin/core.go | 53 ----- pkg/skaffold/build/plugin/plugin.go | 180 ---------------- pkg/skaffold/build/plugin/plugin_test.go | 111 ---------- .../plugin/builders/docker/builder.go | 165 -------------- .../plugin/builders/docker/builder_test.go | 76 ------- pkg/skaffold/plugin/builders/docker/docker.go | 43 ---- pkg/skaffold/plugin/builders/docker/local.go | 203 ------------------ pkg/skaffold/plugin/shared/build.go | 27 --- pkg/skaffold/plugin/shared/client.go | 89 -------- pkg/skaffold/plugin/shared/server.go | 107 --------- pkg/skaffold/plugin/shared/shared.go | 35 --- pkg/skaffold/runner/runner.go | 7 +- 37 files changed, 81 insertions(+), 1433 deletions(-) delete mode 100644 integration/testdata/plugin/gcb/leeroy-app/Dockerfile delete mode 100644 integration/testdata/plugin/gcb/leeroy-app/app.go delete mode 100644 integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml delete mode 100644 integration/testdata/plugin/gcb/leeroy-web/Dockerfile delete mode 100644 integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml delete mode 100644 integration/testdata/plugin/gcb/leeroy-web/web.go delete mode 100644 integration/testdata/plugin/gcb/skaffold.yaml delete mode 100644 integration/testdata/plugin/local/docker/leeroy-app/Dockerfile delete mode 100644 integration/testdata/plugin/local/docker/leeroy-app/app.go delete mode 100644 integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml delete mode 100644 integration/testdata/plugin/local/docker/leeroy-web/Dockerfile delete mode 100644 integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml delete mode 100644 integration/testdata/plugin/local/docker/leeroy-web/web.go delete mode 100644 integration/testdata/plugin/local/docker/skaffold.yaml rename pkg/skaffold/{plugin/environments => build}/gcb/cloud_build.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/desc.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/desc_test.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/docker.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/docker_test.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/jib.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/jib_test.go (100%) rename pkg/skaffold/{plugin/environments => build}/gcb/types.go (100%) delete mode 100644 pkg/skaffold/build/plugin/core.go delete mode 100644 pkg/skaffold/build/plugin/plugin.go delete mode 100644 pkg/skaffold/build/plugin/plugin_test.go delete mode 100644 pkg/skaffold/plugin/builders/docker/builder.go delete mode 100644 pkg/skaffold/plugin/builders/docker/builder_test.go delete mode 100644 pkg/skaffold/plugin/builders/docker/docker.go delete mode 100644 pkg/skaffold/plugin/builders/docker/local.go delete mode 100644 pkg/skaffold/plugin/shared/build.go delete mode 100644 pkg/skaffold/plugin/shared/client.go delete mode 100644 pkg/skaffold/plugin/shared/server.go delete mode 100644 pkg/skaffold/plugin/shared/shared.go diff --git a/cmd/skaffold/app/skaffold.go b/cmd/skaffold/app/skaffold.go index 76bd51a7d81..a99515df669 100644 --- a/cmd/skaffold/app/skaffold.go +++ b/cmd/skaffold/app/skaffold.go @@ -20,17 +20,9 @@ import ( "io" "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/plugin" ) func Run(out, stderr io.Writer) error { - corePlugin, err := plugin.GetCorePluginFromEnv() - if err != nil { - return err - } - if corePlugin != "" { - return plugin.Execute(corePlugin) - } c := cmd.NewSkaffoldCommand(out, stderr) return c.Execute() } diff --git a/integration/run_test.go b/integration/run_test.go index 21d01bd9093..eb1cd5432d9 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -98,15 +98,6 @@ func TestRun(t *testing.T) { // dir: "examples/helm-deployment", // deployments: []string{"skaffold-helm"}, // remoteOnly: true, - }, { - description: "docker plugin in gcb exec environment", - dir: "testdata/plugin/gcb", - deployments: []string{"leeroy-app", "leeroy-web"}, - remoteOnly: true, - }, { - description: "docker plugin in local exec environment", - dir: "testdata/plugin/local/docker", - deployments: []string{"leeroy-app", "leeroy-web"}, }, { description: "jib in googlecloudbuild", dir: "testdata/jib", diff --git a/integration/testdata/plugin/gcb/leeroy-app/Dockerfile b/integration/testdata/plugin/gcb/leeroy-app/Dockerfile deleted file mode 100644 index 1c02a3644d9..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-app/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM golang:1.10.1-alpine3.7 as builder -COPY app.go . -RUN go build -o /app . - -FROM alpine:3.7 as targetStage -CMD ["./app"] -COPY --from=builder /app . - -FROM busybox as unusedStage diff --git a/integration/testdata/plugin/gcb/leeroy-app/app.go b/integration/testdata/plugin/gcb/leeroy-app/app.go deleted file mode 100644 index 40f9c08afac..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-app/app.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" -) - -func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "leeroooooy app!!\n") -} - -func main() { - log.Print("leeroy app server ready") - http.HandleFunc("/", handler) - http.ListenAndServe(":50051", nil) -} diff --git a/integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml b/integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml deleted file mode 100644 index 56ef7152fef..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-app/kubernetes/deployment.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: leeroy-app - labels: - app: leeroy-app -spec: - clusterIP: None - ports: - - port: 50051 - name: leeroy-app - selector: - app: leeroy-app ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: leeroy-app - labels: - app: leeroy-app -spec: - replicas: 1 - selector: - matchLabels: - app: leeroy-app - template: - metadata: - labels: - app: leeroy-app - spec: - containers: - - name: leeroy-app - image: gcr.io/k8s-skaffold/leeroy-app - ports: - - containerPort: 50051 diff --git a/integration/testdata/plugin/gcb/leeroy-web/Dockerfile b/integration/testdata/plugin/gcb/leeroy-web/Dockerfile deleted file mode 100644 index fba8dd8007b..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-web/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:1.10.1-alpine3.7 as builder -COPY web.go . -RUN go build -o /web . - -FROM alpine:3.7 -CMD ["./web"] -COPY --from=builder /web . diff --git a/integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml b/integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml deleted file mode 100644 index fd8ad0bc032..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-web/kubernetes/deployment.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: leeroy-web - labels: - app: leeroy-web -spec: - type: NodePort - ports: - - port: 8080 - targetPort: 8080 - protocol: TCP - name: leeroy-web - selector: - app: leeroy-web ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: leeroy-web - labels: - app: leeroy-web -spec: - replicas: 1 - selector: - matchLabels: - app: leeroy-web - template: - metadata: - labels: - app: leeroy-web - spec: - containers: - - name: leeroy-web - image: gcr.io/k8s-skaffold/leeroy-web - ports: - - containerPort: 8080 diff --git a/integration/testdata/plugin/gcb/leeroy-web/web.go b/integration/testdata/plugin/gcb/leeroy-web/web.go deleted file mode 100644 index 419fd62e067..00000000000 --- a/integration/testdata/plugin/gcb/leeroy-web/web.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "io" - "net/http" - - "log" -) - -func handler(w http.ResponseWriter, r *http.Request) { - resp, err := http.Get("http://leeroy-app:50051") - if err != nil { - panic(err) - } - defer resp.Body.Close() - if _, err := io.Copy(w, resp.Body); err != nil { - panic(err) - } - -} - -func main() { - log.Print("leeroy web server ready") - http.HandleFunc("/", handler) - http.ListenAndServe(":8080", nil) -} diff --git a/integration/testdata/plugin/gcb/skaffold.yaml b/integration/testdata/plugin/gcb/skaffold.yaml deleted file mode 100644 index ac791ac3d51..00000000000 --- a/integration/testdata/plugin/gcb/skaffold.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: skaffold/v1beta9 -kind: Config -build: - artifacts: - - image: gcr.io/k8s-skaffold/leeroy-web - context: ./leeroy-web/ - plugin: - name: docker - - image: gcr.io/k8s-skaffold/leeroy-app - context: ./leeroy-app/ - plugin: - name: docker - properties: - target: targetStage - executionEnvironment: - name: googleCloudBuild -deploy: - kubectl: - manifests: - - ./leeroy-web/kubernetes/* - - ./leeroy-app/kubernetes/* diff --git a/integration/testdata/plugin/local/docker/leeroy-app/Dockerfile b/integration/testdata/plugin/local/docker/leeroy-app/Dockerfile deleted file mode 100644 index 6c10e125d7a..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-app/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:1.10.1-alpine3.7 as builder -COPY app.go . -RUN go build -o /app . - -FROM alpine:3.7 -CMD ["./app"] -COPY --from=builder /app . diff --git a/integration/testdata/plugin/local/docker/leeroy-app/app.go b/integration/testdata/plugin/local/docker/leeroy-app/app.go deleted file mode 100644 index 40f9c08afac..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-app/app.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" -) - -func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "leeroooooy app!!\n") -} - -func main() { - log.Print("leeroy app server ready") - http.HandleFunc("/", handler) - http.ListenAndServe(":50051", nil) -} diff --git a/integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml b/integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml deleted file mode 100644 index 56ef7152fef..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-app/kubernetes/deployment.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: leeroy-app - labels: - app: leeroy-app -spec: - clusterIP: None - ports: - - port: 50051 - name: leeroy-app - selector: - app: leeroy-app ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: leeroy-app - labels: - app: leeroy-app -spec: - replicas: 1 - selector: - matchLabels: - app: leeroy-app - template: - metadata: - labels: - app: leeroy-app - spec: - containers: - - name: leeroy-app - image: gcr.io/k8s-skaffold/leeroy-app - ports: - - containerPort: 50051 diff --git a/integration/testdata/plugin/local/docker/leeroy-web/Dockerfile b/integration/testdata/plugin/local/docker/leeroy-web/Dockerfile deleted file mode 100644 index fba8dd8007b..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-web/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM golang:1.10.1-alpine3.7 as builder -COPY web.go . -RUN go build -o /web . - -FROM alpine:3.7 -CMD ["./web"] -COPY --from=builder /web . diff --git a/integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml b/integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml deleted file mode 100644 index fd8ad0bc032..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-web/kubernetes/deployment.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: leeroy-web - labels: - app: leeroy-web -spec: - type: NodePort - ports: - - port: 8080 - targetPort: 8080 - protocol: TCP - name: leeroy-web - selector: - app: leeroy-web ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: leeroy-web - labels: - app: leeroy-web -spec: - replicas: 1 - selector: - matchLabels: - app: leeroy-web - template: - metadata: - labels: - app: leeroy-web - spec: - containers: - - name: leeroy-web - image: gcr.io/k8s-skaffold/leeroy-web - ports: - - containerPort: 8080 diff --git a/integration/testdata/plugin/local/docker/leeroy-web/web.go b/integration/testdata/plugin/local/docker/leeroy-web/web.go deleted file mode 100644 index 419fd62e067..00000000000 --- a/integration/testdata/plugin/local/docker/leeroy-web/web.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "io" - "net/http" - - "log" -) - -func handler(w http.ResponseWriter, r *http.Request) { - resp, err := http.Get("http://leeroy-app:50051") - if err != nil { - panic(err) - } - defer resp.Body.Close() - if _, err := io.Copy(w, resp.Body); err != nil { - panic(err) - } - -} - -func main() { - log.Print("leeroy web server ready") - http.HandleFunc("/", handler) - http.ListenAndServe(":8080", nil) -} diff --git a/integration/testdata/plugin/local/docker/skaffold.yaml b/integration/testdata/plugin/local/docker/skaffold.yaml deleted file mode 100644 index fd636f64bd2..00000000000 --- a/integration/testdata/plugin/local/docker/skaffold.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: skaffold/v1beta9 -kind: Config -build: - artifacts: - - image: gcr.io/k8s-skaffold/leeroy-web - context: ./leeroy-web/ - plugin: - name: docker - - image: gcr.io/k8s-skaffold/leeroy-app - context: ./leeroy-app/ - plugin: - name: docker - executionEnvironment: - name: local -deploy: - kubectl: - manifests: - - ./leeroy-web/kubernetes/* - - ./leeroy-app/kubernetes/* diff --git a/pkg/skaffold/plugin/environments/gcb/cloud_build.go b/pkg/skaffold/build/gcb/cloud_build.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/cloud_build.go rename to pkg/skaffold/build/gcb/cloud_build.go diff --git a/pkg/skaffold/plugin/environments/gcb/desc.go b/pkg/skaffold/build/gcb/desc.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/desc.go rename to pkg/skaffold/build/gcb/desc.go diff --git a/pkg/skaffold/plugin/environments/gcb/desc_test.go b/pkg/skaffold/build/gcb/desc_test.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/desc_test.go rename to pkg/skaffold/build/gcb/desc_test.go diff --git a/pkg/skaffold/plugin/environments/gcb/docker.go b/pkg/skaffold/build/gcb/docker.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/docker.go rename to pkg/skaffold/build/gcb/docker.go diff --git a/pkg/skaffold/plugin/environments/gcb/docker_test.go b/pkg/skaffold/build/gcb/docker_test.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/docker_test.go rename to pkg/skaffold/build/gcb/docker_test.go diff --git a/pkg/skaffold/plugin/environments/gcb/jib.go b/pkg/skaffold/build/gcb/jib.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/jib.go rename to pkg/skaffold/build/gcb/jib.go diff --git a/pkg/skaffold/plugin/environments/gcb/jib_test.go b/pkg/skaffold/build/gcb/jib_test.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/jib_test.go rename to pkg/skaffold/build/gcb/jib_test.go diff --git a/pkg/skaffold/plugin/environments/gcb/types.go b/pkg/skaffold/build/gcb/types.go similarity index 100% rename from pkg/skaffold/plugin/environments/gcb/types.go rename to pkg/skaffold/build/gcb/types.go diff --git a/pkg/skaffold/build/local/docker.go b/pkg/skaffold/build/local/docker.go index 505d8df6ca7..d1a098f143b 100644 --- a/pkg/skaffold/build/local/docker.go +++ b/pkg/skaffold/build/local/docker.go @@ -19,30 +19,89 @@ package local import ( "context" "io" + "os" + "os/exec" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/docker" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" + "github.com/pkg/errors" ) func (b *Builder) buildDocker(ctx context.Context, out io.Writer, a *latest.Artifact, tag string) (string, error) { - builder := docker.NewBuilder() - builder.LocalBuild = b.cfg - builder.LocalDocker = b.localDocker - builder.KubeContext = b.kubeContext - builder.PushImages = b.pushImages - builder.PluginMode = false - - builder.Init(&runcontext.RunContext{ - Opts: &config.SkaffoldOptions{ - SkipTests: b.skipTests, - }, - Cfg: &latest.Pipeline{ - Build: latest.BuildConfig{ - ExecutionEnvironment: &latest.ExecutionEnvironment{}, - }, - }, - }) - return builder.BuildArtifact(ctx, out, a, tag) + if err := b.pullCacheFromImages(ctx, out, a.ArtifactType.DockerArtifact); err != nil { + return "", errors.Wrap(err, "pulling cache-from images") + } + + var ( + imageID string + err error + ) + + if b.cfg.UseDockerCLI || b.cfg.UseBuildkit { + imageID, err = b.dockerCLIBuild(ctx, out, a.Workspace, a.ArtifactType.DockerArtifact, tag) + } else { + imageID, err = b.localDocker.Build(ctx, out, a.Workspace, a.ArtifactType.DockerArtifact, tag) + } + + if err != nil { + return "", err + } + + if b.pushImages { + return b.localDocker.Push(ctx, out, tag) + } + + return imageID, nil +} + +func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, workspace string, a *latest.DockerArtifact, tag string) (string, error) { + dockerfilePath, err := docker.NormalizeDockerfilePath(workspace, a.DockerfilePath) + if err != nil { + return "", errors.Wrap(err, "normalizing dockerfile path") + } + + args := []string{"build", workspace, "--file", dockerfilePath, "-t", tag} + args = append(args, docker.GetBuildArgs(a)...) + + if b.prune { + args = append(args, "--force-rm") + } + + cmd := exec.CommandContext(ctx, "docker", args...) + if b.cfg.UseBuildkit { + cmd.Env = append(os.Environ(), "DOCKER_BUILDKIT=1") + } + cmd.Stdout = out + cmd.Stderr = out + + if err := util.RunCmd(cmd); err != nil { + return "", errors.Wrap(err, "running build") + } + + return b.localDocker.ImageID(ctx, tag) +} + +func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *latest.DockerArtifact) error { + if len(a.CacheFrom) == 0 { + return nil + } + + for _, image := range a.CacheFrom { + imageID, err := b.localDocker.ImageID(ctx, image) + if err != nil { + return errors.Wrapf(err, "getting imageID for %s", image) + } + if imageID != "" { + // already pulled + continue + } + + if err := b.localDocker.Pull(ctx, out, image); err != nil { + warnings.Printf("Cache-From image couldn't be pulled: %s\n", image) + } + } + + return nil } diff --git a/pkg/skaffold/build/plugin/core.go b/pkg/skaffold/build/plugin/core.go deleted file mode 100644 index 4931c840aa6..00000000000 --- a/pkg/skaffold/build/plugin/core.go +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 plugin - -import ( - "fmt" - "os" - - "github.com/hashicorp/go-hclog" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/builders/docker" -) - -//TODO(this should be rather wired through an env var from the skaffold process) -const DefaultPluginLogLevel = hclog.Info - -// SkaffoldCorePluginExecutionMap maps the core plugin name to the execution function -var SkaffoldCorePluginExecutionMap = map[string]func() error{ - "docker": docker.Execute(DefaultPluginLogLevel), -} - -// GetCorePluginFromEnv returns the core plugin name if env variables for plugins are set properly -// and the plugin passed in is a core plugin -func GetCorePluginFromEnv() (string, error) { - if os.Getenv(constants.SkaffoldPluginKey) != constants.SkaffoldPluginValue { - return "", nil - } - plugin := os.Getenv(constants.SkaffoldPluginName) - if _, ok := SkaffoldCorePluginExecutionMap[plugin]; ok { - return plugin, nil - } - return "", fmt.Errorf("no core plugin found with name %s", plugin) -} - -// Execute executes a plugin - does not validate -func Execute(plugin string) error { - return SkaffoldCorePluginExecutionMap[plugin]() -} diff --git a/pkg/skaffold/build/plugin/plugin.go b/pkg/skaffold/build/plugin/plugin.go deleted file mode 100644 index 1d064d328c5..00000000000 --- a/pkg/skaffold/build/plugin/plugin.go +++ /dev/null @@ -1,180 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 plugin - -import ( - "context" - "fmt" - "io" - "os" - "os/exec" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/shared" - runctx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - plugin "github.com/hashicorp/go-plugin" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -var ( - // For testing - randomID = util.RandomFourCharacterID -) - -// NewPluginBuilder initializes and returns all required plugin builders -func NewPluginBuilder(runCtx *runctx.RunContext) (shared.PluginBuilder, error) { - // We're a host. Start by launching the plugin process. - logrus.SetOutput(os.Stdout) - - builders := map[string]shared.PluginBuilder{} - - for _, a := range runCtx.Cfg.Build.Artifacts { - p := a.BuilderPlugin.Name - if _, ok := builders[p]; ok { - continue - } - cmd := exec.Command(p) - if _, ok := SkaffoldCorePluginExecutionMap[p]; ok { - executable, err := os.Executable() - if err != nil { - return nil, errors.Wrap(err, "getting executable path") - } - cmd = exec.Command(executable) - cmd.Env = append(os.Environ(), []string{fmt.Sprintf("%s=%s", constants.SkaffoldPluginKey, constants.SkaffoldPluginValue), - fmt.Sprintf("%s=%s", constants.SkaffoldPluginName, p)}...) - } - - client := plugin.NewClient(&plugin.ClientConfig{ - Stderr: os.Stderr, - SyncStderr: os.Stderr, - SyncStdout: os.Stdout, - Managed: true, - HandshakeConfig: shared.Handshake, - Plugins: shared.PluginMap, - Cmd: cmd, - }) - - logrus.Debugf("Starting plugin with command: %+v", cmd) - - // Connect via RPC - rpcClient, err := client.Client() - if err != nil { - return nil, errors.Wrap(err, "connecting via rpc") - } - logrus.Debugf("plugin started.") - // Request the plugin - raw, err := rpcClient.Dispense(p) - if err != nil { - return nil, errors.Wrap(err, "requesting rpc plugin") - } - pluginBuilder := raw.(shared.PluginBuilder) - builders[p] = pluginBuilder - } - - b := &Builder{ - Builders: builders, - } - - logrus.Debugf("Calling Init() for all plugins.") - if err := b.Init(runCtx); err != nil { - plugin.CleanupClients() - return nil, err - } - return b, nil -} - -type Builder struct { - Builders map[string]shared.PluginBuilder -} - -func (b *Builder) Init(runCtx *runctx.RunContext) error { - for _, builder := range b.Builders { - if err := builder.Init(runCtx); err != nil { - return err - } - } - return nil -} - -// Labels are labels applied to deployed resources. -func (b *Builder) Labels() map[string]string { - labels := map[string]string{} - for _, builder := range b.Builders { - for k, v := range builder.Labels() { - if val, ok := labels[k]; ok { - random := fmt.Sprintf("%s-%s", k, randomID()) - logrus.Warnf("%s=%s label exists, saving %s=%s as %s=%s to avoid overlap", k, val, k, v, random, v) - labels[random] = v - continue - } - labels[k] = v - } - } - return labels -} - -func (b *Builder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - var builtArtifacts []build.Artifact - // Group artifacts by plugin name - m := retrieveArtifactsByPlugin(artifacts) - // Group artifacts by builder - for name, builder := range b.Builders { - bArts, err := builder.Build(ctx, out, tags, m[name]) - if err != nil { - return nil, errors.Wrapf(err, "building artifacts with builder %s", name) - } - builtArtifacts = append(builtArtifacts, bArts...) - } - return builtArtifacts, nil -} - -func (b *Builder) DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error) { - // Group artifacts by builder - for name, builder := range b.Builders { - if name != artifact.BuilderPlugin.Name { - continue - } - return builder.DependenciesForArtifact(ctx, artifact) - } - return nil, errors.New("couldn't find plugin builder to get dependencies for artifact") -} - -func (b *Builder) Prune(ctx context.Context, out io.Writer) error { - for name, builder := range b.Builders { - if err := builder.Prune(ctx, out); err != nil { - return errors.Wrapf(err, "pruning images for builder %s", name) - } - } - return nil -} - -func retrieveArtifactsByPlugin(artifacts []*latest.Artifact) map[string][]*latest.Artifact { - m := map[string][]*latest.Artifact{} - for _, a := range artifacts { - if _, ok := m[a.BuilderPlugin.Name]; ok { - m[a.BuilderPlugin.Name] = append(m[a.BuilderPlugin.Name], a) - continue - } - m[a.BuilderPlugin.Name] = []*latest.Artifact{a} - } - return m -} diff --git a/pkg/skaffold/build/plugin/plugin_test.go b/pkg/skaffold/build/plugin/plugin_test.go deleted file mode 100644 index 8438c49452a..00000000000 --- a/pkg/skaffold/build/plugin/plugin_test.go +++ /dev/null @@ -1,111 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 plugin - -import ( - "context" - "io" - "testing" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/shared" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/testutil" -) - -type mockBuilder struct { - labels map[string]string - artifacts []build.Artifact -} - -func (b *mockBuilder) Build(_ context.Context, _ io.Writer, _ tag.ImageTags, _ []*latest.Artifact) ([]build.Artifact, error) { - return b.artifacts, nil -} - -func (b *mockBuilder) Labels() map[string]string { - return b.labels -} - -func (b *mockBuilder) Init(_ *runcontext.RunContext) error { return nil } - -func (b *mockBuilder) DependenciesForArtifact(_ context.Context, _ *latest.Artifact) ([]string, error) { - return nil, nil -} - -func (b *mockBuilder) Prune(_ context.Context, _ io.Writer) error { - return nil -} - -func TestPluginBuilderLabels(t *testing.T) { - tests := []struct { - name string - builder shared.PluginBuilder - expected map[string]string - }{ - { - name: "check labels", - builder: &Builder{ - Builders: map[string]shared.PluginBuilder{ - "mock-one": &mockBuilder{ - labels: map[string]string{"key-one": "value-one"}, - }, - "mock-two": &mockBuilder{ - labels: map[string]string{"key-two": "value-two"}, - }, - }, - }, - expected: map[string]string{ - "key-one": "value-one", - "key-two": "value-two", - }, - }, - { - name: "check overlapping labels", - builder: &Builder{ - Builders: map[string]shared.PluginBuilder{ - "mock-one": &mockBuilder{ - labels: map[string]string{"key-one": "value"}, - }, - "mock-two": &mockBuilder{ - labels: map[string]string{"key-one": "value"}, - }, - }, - }, - expected: map[string]string{ - "key-one": "value", - "key-one-rand": "value", - }, - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - original := randomID - mockRandomID := func() string { - return "rand" - } - randomID = mockRandomID - defer func() { - randomID = original - }() - - actual := test.builder.Labels() - testutil.CheckErrorAndDeepEqual(t, false, nil, test.expected, actual) - }) - } -} diff --git a/pkg/skaffold/plugin/builders/docker/builder.go b/pkg/skaffold/plugin/builders/docker/builder.go deleted file mode 100644 index 5a6bf12c222..00000000000 --- a/pkg/skaffold/plugin/builders/docker/builder.go +++ /dev/null @@ -1,165 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 docker - -import ( - "context" - "io" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/environments/gcb" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/defaults" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "gopkg.in/yaml.v2" -) - -// Builder builds artifacts with Docker. -type Builder struct { - opts *config.SkaffoldOptions - env *latest.ExecutionEnvironment - - gcbEnv *gcb.Builder - - *latest.LocalBuild - LocalDocker docker.LocalDaemon - LocalCluster bool - PushImages bool - - // TODO: remove once old docker build functionality is removed (priyawadhwa@) - PluginMode bool - KubeContext string - builtImages []string - insecureRegistries map[string]bool -} - -// NewBuilder creates a new Builder that builds artifacts with Docker. -func NewBuilder() *Builder { - return &Builder{ - PluginMode: true, - } -} - -// Init stores skaffold options and the execution environment -func (b *Builder) Init(runCtx *runcontext.RunContext) error { - b.opts = runCtx.Opts - b.env = runCtx.Cfg.Build.ExecutionEnvironment - b.insecureRegistries = runCtx.InsecureRegistries - - if b.PluginMode { - if err := event.SetupRPCClient(runCtx.Opts); err != nil { - logrus.Warn("error establishing gRPC connection to skaffold process; events will not be handled correctly") - logrus.Warn(err.Error()) - return err - } - switch b.env.Name { - case constants.GoogleCloudBuild: - gcbEnv, err := gcb.NewBuilderFromPluginConfig(runCtx) - if err != nil { - return errors.Wrap(err, "initializing GCB builder") - } - b.gcbEnv = gcbEnv - case constants.Local: - //pass - default: - return errors.Errorf("%s is not a supported environment for builder docker", b.env.Name) - } - } - - logrus.Debugf("initialized plugin with %+v", runCtx) - return nil -} - -// Labels are labels specific to Docker. -func (b *Builder) Labels() map[string]string { - return map[string]string{ - constants.Labels.Builder: "docker", - } -} - -// DependenciesForArtifact returns the dependencies for this docker artifact -func (b *Builder) DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error) { - if err := setArtifact(artifact); err != nil { - return nil, err - } - paths, err := docker.GetDependencies(ctx, artifact.Workspace, artifact.DockerArtifact.DockerfilePath, artifact.DockerArtifact.BuildArgs, b.insecureRegistries) - if err != nil { - return nil, errors.Wrapf(err, "getting dependencies for %s", artifact.ImageName) - } - return util.AbsolutePaths(artifact.Workspace, paths), nil -} - -// Build is responsible for building artifacts in their respective execution environments -// The builder plugin is also responsible for setting any necessary defaults -func (b *Builder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - switch b.env.Name { - case constants.GoogleCloudBuild: - return b.googleCloudBuild(ctx, out, tags, artifacts) - case constants.Local: - return b.local(ctx, out, tags, artifacts) - default: - return nil, errors.Errorf("%s is not a supported environment for builder docker", b.env.Name) - } -} - -func (b *Builder) Prune(ctx context.Context, out io.Writer) error { - switch b.env.Name { - case constants.GoogleCloudBuild: - return nil // noop - case constants.Local: - return b.prune(ctx, out) - default: - return errors.Errorf("%s is not a supported environment for builder docker", b.env.Name) - } - // return b.builder.Prune(ctx, out) -} - -// googleCloudBuild sets any necessary defaults and then builds artifacts with docker in GCB -func (b *Builder) googleCloudBuild(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - - for _, a := range artifacts { - if err := setArtifact(a); err != nil { - return nil, err - } - } - - return b.gcbEnv.Build(ctx, out, tags, artifacts) -} - -func setArtifact(artifact *latest.Artifact) error { - if artifact.ArtifactType.DockerArtifact != nil { - return nil - } - var a *latest.DockerArtifact - if err := yaml.UnmarshalStrict(artifact.BuilderPlugin.Contents, &a); err != nil { - return errors.Wrap(err, "unmarshalling docker artifact") - } - if a == nil { - a = &latest.DockerArtifact{} - } - defaults.SetDefaultDockerArtifact(a) - artifact.ArtifactType.DockerArtifact = a - return nil -} diff --git a/pkg/skaffold/plugin/builders/docker/builder_test.go b/pkg/skaffold/plugin/builders/docker/builder_test.go deleted file mode 100644 index 3cd44056885..00000000000 --- a/pkg/skaffold/plugin/builders/docker/builder_test.go +++ /dev/null @@ -1,76 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 docker - -import ( - "testing" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/testutil" -) - -func TestSetArtifact(t *testing.T) { - tests := []struct { - name string - initial *latest.Artifact - expected *latest.Artifact - }{ - { - name: "no contents passed in", - initial: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{}, - }, - expected: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{}, - ArtifactType: latest.ArtifactType{ - DockerArtifact: &latest.DockerArtifact{ - DockerfilePath: "Dockerfile", - }, - }, - }, - }, - { - name: "set dockerfile path", - initial: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte("dockerfile: path/to/Dockerfile"), - }, - }, - expected: &latest.Artifact{ - ImageName: "image", - BuilderPlugin: &latest.BuilderPlugin{ - Contents: []byte("dockerfile: path/to/Dockerfile"), - }, - ArtifactType: latest.ArtifactType{ - DockerArtifact: &latest.DockerArtifact{ - DockerfilePath: "path/to/Dockerfile", - }, - }, - }, - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err := setArtifact(test.initial) - testutil.CheckErrorAndDeepEqual(t, false, err, test.expected, test.initial) - }) - } -} diff --git a/pkg/skaffold/plugin/builders/docker/docker.go b/pkg/skaffold/plugin/builders/docker/docker.go deleted file mode 100644 index d0dd5e0c486..00000000000 --- a/pkg/skaffold/plugin/builders/docker/docker.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 docker - -import ( - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/shared" - "github.com/hashicorp/go-hclog" - "github.com/hashicorp/go-plugin" -) - -// Execute an image build with docker -func Execute(pluginLogLevel hclog.Level) func() error { - return func() error { - // pluginMap is the map of plugins we can dispense. - var pluginMap = map[string]plugin.Plugin{ - "docker": &shared.BuilderPlugin{Impl: NewBuilder()}, - } - - plugin.Serve(&plugin.ServeConfig{ - Logger: hclog.New(&hclog.LoggerOptions{ - Level: pluginLogLevel, - }), - HandshakeConfig: shared.Handshake, - Plugins: pluginMap, - }) - - return nil - } -} diff --git a/pkg/skaffold/plugin/builders/docker/local.go b/pkg/skaffold/plugin/builders/docker/local.go deleted file mode 100644 index 4e22a3a4779..00000000000 --- a/pkg/skaffold/plugin/builders/docker/local.go +++ /dev/null @@ -1,203 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 docker - -import ( - "context" - "io" - "os" - "os/exec" - "strings" - - configutil "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker" - kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/warnings" - - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -func (b *Builder) local(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - var l *latest.LocalBuild - if err := util.CloneThroughJSON(b.env.Properties, &l); err != nil { - return nil, errors.Wrap(err, "converting execution env to localBuild struct") - } - if l == nil { - l = &latest.LocalBuild{} - } - b.LocalBuild = l - kubeContext, err := kubectx.CurrentContext() - if err != nil { - return nil, errors.Wrap(err, "getting current cluster context") - } - b.KubeContext = kubeContext - localDocker, err := docker.NewAPIClient(b.opts.Prune(), b.insecureRegistries) - if err != nil { - return nil, errors.Wrap(err, "getting docker client") - } - b.LocalDocker = localDocker - localCluster, err := configutil.GetLocalCluster() - if err != nil { - return nil, errors.Wrap(err, "getting localCluster") - } - b.LocalCluster = localCluster - var pushImages bool - if b.LocalBuild.Push == nil { - pushImages = !localCluster - logrus.Debugf("push value not present, defaulting to %t because localCluster is %t", pushImages, localCluster) - } else { - pushImages = *b.LocalBuild.Push - } - b.PushImages = pushImages - for _, a := range artifacts { - if err := setArtifact(a); err != nil { - return nil, err - } - } - return b.buildArtifacts(ctx, out, tags, artifacts) -} - -func (b *Builder) prune(ctx context.Context, out io.Writer) error { - return docker.Prune(ctx, out, b.builtImages, b.LocalDocker) -} - -func (b *Builder) buildArtifacts(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - if b.LocalCluster { - color.Default.Fprintf(out, "Found [%s] context, using local docker daemon.\n", b.KubeContext) - } - return build.InSequence(ctx, out, tags, artifacts, b.runBuild) -} - -func (b *Builder) runBuild(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) { - digestOrImageID, err := b.BuildArtifact(ctx, out, artifact, tag) - if err != nil { - return "", errors.Wrap(err, "build artifact") - } - if b.PushImages { - imageID, err := b.getImageIDForTag(ctx, tag) - if err != nil { - logrus.Warnf("unable to inspect image: built images may not be cleaned up correctly by skaffold") - } - b.builtImages = append(b.builtImages, imageID) - digest := digestOrImageID - return tag + "@" + digest, nil - } - - // k8s doesn't recognize the imageID or any combination of the image name - // suffixed with the imageID, as a valid image name. - // So, the solution we chose is to create a tag, just for Skaffold, from - // the imageID, and use that in the manifests. - imageID := digestOrImageID - b.builtImages = append(b.builtImages, imageID) - uniqueTag := artifact.ImageName + ":" + strings.TrimPrefix(imageID, "sha256:") - if err := b.LocalDocker.Tag(ctx, imageID, uniqueTag); err != nil { - return "", err - } - - return uniqueTag, nil -} - -// BuildArtifact builds the docker artifact -func (b *Builder) BuildArtifact(ctx context.Context, out io.Writer, a *latest.Artifact, tag string) (string, error) { - if err := b.pullCacheFromImages(ctx, out, a.ArtifactType.DockerArtifact); err != nil { - return "", errors.Wrap(err, "pulling cache-from images") - } - - var ( - imageID string - err error - ) - - if b.LocalBuild.UseDockerCLI || b.LocalBuild.UseBuildkit { - imageID, err = b.dockerCLIBuild(ctx, out, a.Workspace, a.ArtifactType.DockerArtifact, tag) - } else { - imageID, err = b.LocalDocker.Build(ctx, out, a.Workspace, a.ArtifactType.DockerArtifact, tag) - } - - if err != nil { - return "", err - } - - if b.PushImages { - return b.LocalDocker.Push(ctx, out, tag) - } - - return imageID, nil -} - -func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, workspace string, a *latest.DockerArtifact, tag string) (string, error) { - dockerfilePath, err := docker.NormalizeDockerfilePath(workspace, a.DockerfilePath) - if err != nil { - return "", errors.Wrap(err, "normalizing dockerfile path") - } - - args := []string{"build", workspace, "--file", dockerfilePath, "-t", tag} - args = append(args, docker.GetBuildArgs(a)...) - if b.opts.Prune() { - args = append(args, "--force-rm") - } - - cmd := exec.CommandContext(ctx, "docker", args...) - if b.LocalBuild.UseBuildkit { - cmd.Env = append(os.Environ(), "DOCKER_BUILDKIT=1") - } - cmd.Stdout = out - cmd.Stderr = out - - if err := util.RunCmd(cmd); err != nil { - return "", errors.Wrap(err, "running build") - } - - return b.LocalDocker.ImageID(ctx, tag) -} - -func (b *Builder) pullCacheFromImages(ctx context.Context, out io.Writer, a *latest.DockerArtifact) error { - if len(a.CacheFrom) == 0 { - return nil - } - - for _, image := range a.CacheFrom { - imageID, err := b.LocalDocker.ImageID(ctx, image) - if err != nil { - return errors.Wrapf(err, "getting imageID for %s", image) - } - if imageID != "" { - // already pulled - continue - } - - if err := b.LocalDocker.Pull(ctx, out, image); err != nil { - warnings.Printf("Cache-From image couldn't be pulled: %s\n", image) - } - } - - return nil -} - -func (b *Builder) getImageIDForTag(ctx context.Context, tag string) (string, error) { - insp, _, err := b.LocalDocker.ImageInspectWithRaw(ctx, tag) - if err != nil { - return "", errors.Wrap(err, "inspecting image") - } - return insp.ID, nil -} diff --git a/pkg/skaffold/plugin/shared/build.go b/pkg/skaffold/plugin/shared/build.go deleted file mode 100644 index 725f064ecc9..00000000000 --- a/pkg/skaffold/plugin/shared/build.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 shared - -import ( - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" -) - -type PluginBuilder interface { - Init(runCtx *runcontext.RunContext) error - build.Builder -} diff --git a/pkg/skaffold/plugin/shared/client.go b/pkg/skaffold/plugin/shared/client.go deleted file mode 100644 index c34208e931f..00000000000 --- a/pkg/skaffold/plugin/shared/client.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 shared - -import ( - "context" - "io" - "net/rpc" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" -) - -// BuilderRPC is an implementation of an rpc client -type BuilderRPC struct { - client *rpc.Client -} - -func (b *BuilderRPC) Init(runCtx *runcontext.RunContext) error { - // We don't expect a response, so we can just use interface{} - var resp interface{} - return b.client.Call("Plugin.Init", runCtx, &resp) -} - -func (b *BuilderRPC) DependenciesForArtifact(ctx context.Context, artifact *latest.Artifact) ([]string, error) { - var resp []string - if err := convertPropertiesToBytes([]*latest.Artifact{artifact}); err != nil { - return nil, errors.Wrapf(err, "converting properties to bytes") - } - args := DependencyArgs{artifact} - err := b.client.Call("Plugin.DependenciesForArtifact", args, &resp) - if err != nil { - return nil, err - } - return resp, nil -} - -func (b *BuilderRPC) Labels() map[string]string { - var resp map[string]string - err := b.client.Call("Plugin.Labels", new(interface{}), &resp) - if err != nil { - // Can't return error, so log it instead - logrus.Errorf("Unable to get labels from server: %v", err) - } - return resp -} - -func (b *BuilderRPC) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, artifacts []*latest.Artifact) ([]build.Artifact, error) { - var resp []build.Artifact - if err := convertPropertiesToBytes(artifacts); err != nil { - return nil, errors.Wrapf(err, "converting properties to bytes") - } - args := BuildArgs{ - ImageTags: tags, - Artifacts: artifacts, - } - err := b.client.Call("Plugin.Build", args, &resp) - if err != nil { - return nil, err - } - return resp, nil -} - -func (b *BuilderRPC) Prune(ctx context.Context, out io.Writer) error { - var resp interface{} - if err := b.client.Call("Plugin.Prune", new(interface{}), &resp); err != nil { - return err - } - return nil -} diff --git a/pkg/skaffold/plugin/shared/server.go b/pkg/skaffold/plugin/shared/server.go deleted file mode 100644 index 9057ef3b792..00000000000 --- a/pkg/skaffold/plugin/shared/server.go +++ /dev/null @@ -1,107 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 shared - -import ( - "context" - "net/rpc" - "os" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" - runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - plugin "github.com/hashicorp/go-plugin" - "github.com/pkg/errors" - yaml "gopkg.in/yaml.v2" -) - -func convertPropertiesToBytes(artifacts []*latest.Artifact) error { - for _, a := range artifacts { - if a.BuilderPlugin.Properties == nil { - continue - } - data, err := yaml.Marshal(a.BuilderPlugin.Properties) - if err != nil { - return err - } - a.BuilderPlugin.Contents = data - a.BuilderPlugin.Properties = nil - } - return nil -} - -// BuilderRPCServer is the RPC server that BuilderRPC talks to, conforming to -// the requirements of net/rpc -type BuilderRPCServer struct { - Impl PluginBuilder -} - -func (s *BuilderRPCServer) Init(runCtx *runcontext.RunContext, resp *interface{}) error { - return s.Impl.Init(runCtx) -} - -func (s *BuilderRPCServer) Labels(_ interface{}, resp *map[string]string) error { - *resp = s.Impl.Labels() - return nil -} - -func (s *BuilderRPCServer) Build(b BuildArgs, resp *[]build.Artifact) error { - artifacts, err := s.Impl.Build(context.Background(), os.Stdout, b.ImageTags, b.Artifacts) - if err != nil { - return errors.Wrap(err, "building artifacts") - } - *resp = artifacts - return nil -} - -func (s *BuilderRPCServer) Prune(args interface{}, resp *interface{}) error { - return s.Impl.Prune(context.Background(), os.Stdout) -} - -func (s *BuilderRPCServer) DependenciesForArtifact(d DependencyArgs, resp *[]string) error { - dependencies, err := s.Impl.DependenciesForArtifact(context.Background(), d.Artifact) - if err != nil { - return errors.Wrapf(err, "getting dependencies for %s", d.Artifact.ImageName) - } - *resp = dependencies - return nil -} - -// DependencyArgs are args passed via rpc to the build plugin on DependencyForArtifact() -type DependencyArgs struct { - *latest.Artifact -} - -// BuildArgs are the args passed via rpc to the builder plugin on Build() -type BuildArgs struct { - tag.ImageTags - Artifacts []*latest.Artifact -} - -// BuilderPlugin is the implementation of the hashicorp plugin.Plugin interface -type BuilderPlugin struct { - Impl PluginBuilder -} - -func (p *BuilderPlugin) Server(*plugin.MuxBroker) (interface{}, error) { - return &BuilderRPCServer{Impl: p.Impl}, nil -} - -func (BuilderPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) { - return &BuilderRPC{client: c}, nil -} diff --git a/pkg/skaffold/plugin/shared/shared.go b/pkg/skaffold/plugin/shared/shared.go deleted file mode 100644 index 39b0313408a..00000000000 --- a/pkg/skaffold/plugin/shared/shared.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Copyright 2019 The Skaffold 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 shared - -import ( - plugin "github.com/hashicorp/go-plugin" -) - -// Handshake is a common handshake that is shared by plugin and host. -var Handshake = plugin.HandshakeConfig{ - ProtocolVersion: 1, - - MagicCookieKey: "SKAFFOLD_BUILDER_PLUGIN", - MagicCookieValue: "hello", -} - -// PluginMap is a map of all accepted plugins -var PluginMap = map[string]plugin.Plugin{ - "docker": &BuilderPlugin{}, - "bazel": &BuilderPlugin{}, -} diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index 15cbe6e7be8..e1faec2dd29 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -27,16 +27,15 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cache" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/gcb" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/local" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/plugin" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/config" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/plugin/environments/gcb" runcontext "github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/context" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" @@ -129,10 +128,6 @@ func NewForConfig(opts *config.SkaffoldOptions, cfg *latest.SkaffoldConfig) (*Sk func getBuilder(runCtx *runcontext.RunContext) (build.Builder, error) { switch { - case runCtx.Plugin: - logrus.Debugln("Using builder plugins") - return plugin.NewPluginBuilder(runCtx) - case len(runCtx.Opts.PreBuiltImages) > 0: logrus.Debugln("Using pre-built images") return build.NewPreBuiltImagesBuilder(runCtx), nil