Skip to content

Commit

Permalink
Merge pull request #2037 from priyawadhwa/refactor
Browse files Browse the repository at this point in the history
Refactor kaniko builder to cluster builder
  • Loading branch information
priyawadhwa authored Apr 30, 2019
2 parents 1780a80 + 0dac1ae commit 11f8a1b
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"context"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, tags tag.ImageTags,
}

func (b *Builder) buildArtifactWithKaniko(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
digest, err := b.run(ctx, out, artifact, tag)
digest, err := b.runKanikoBuild(ctx, out, artifact, tag)
if err != nil {
return "", errors.Wrapf(err, "kaniko build for [%s]", artifact.ImageName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"context"
Expand All @@ -23,7 +23,7 @@ import (
"sort"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cache"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/kaniko/sources"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cluster/sources"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
Expand All @@ -33,7 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (b *Builder) run(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
func (b *Builder) runKanikoBuild(ctx context.Context, out io.Writer, artifact *latest.Artifact, tag string) (string, error) {
// Prepare context
s := sources.Retrieve(b.ClusterDetails, artifact.KanikoArtifact)
dependencies, err := b.DependenciesForArtifact(ctx, artifact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"io"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"io"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package kaniko
package cluster

import (
"context"
"fmt"
"io"
"time"

Expand All @@ -29,15 +30,15 @@ import (
"github.com/pkg/errors"
)

// Builder builds docker artifacts on Kubernetes, using Kaniko.
// Builder builds docker artifacts on Kubernetes.
type Builder struct {
*latest.ClusterDetails

timeout time.Duration
insecureRegistries map[string]bool
}

// NewBuilder creates a new Builder that builds artifacts with Kaniko.
// NewBuilder creates a new Builder that builds artifacts on cluster.
func NewBuilder(runCtx *runcontext.RunContext) (*Builder, error) {
timeout, err := time.ParseDuration(runCtx.Cfg.Build.Cluster.Timeout)
if err != nil {
Expand All @@ -50,18 +51,29 @@ func NewBuilder(runCtx *runcontext.RunContext) (*Builder, error) {
}, nil
}

// Labels are labels specific to Kaniko builder.
// Labels are labels specific to cluster builder.
func (b *Builder) Labels() map[string]string {
return map[string]string{
constants.Labels.Builder: "kaniko",
constants.Labels.Builder: "cluster",
}
}

// DependenciesForArtifact returns the Dockerfile dependencies for this kaniko artifact
// DependenciesForArtifact returns the Dockerfile dependencies for this artifact
func (b *Builder) DependenciesForArtifact(ctx context.Context, a *latest.Artifact) ([]string, error) {
paths, err := docker.GetDependencies(ctx, a.Workspace, a.KanikoArtifact.DockerfilePath, a.KanikoArtifact.BuildArgs, b.insecureRegistries)
var (
paths []string
err error
)
switch {
case a.KanikoArtifact != nil:
paths, err = docker.GetDependencies(ctx, a.Workspace, a.KanikoArtifact.DockerfilePath, a.KanikoArtifact.BuildArgs, b.insecureRegistries)

default:
return nil, fmt.Errorf("undefined artifact type: %+v", a.ArtifactType)
}

if err != nil {
return nil, errors.Wrapf(err, "getting dependencies for %s", a.ImageName)
return nil, err
}
return util.AbsolutePaths(a.Workspace, paths), nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cache"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cluster"
"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/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
Expand Down Expand Up @@ -140,8 +140,8 @@ func getBuilder(runCtx *runcontext.RunContext) (build.Builder, error) {
return gcb.NewBuilder(runCtx), nil

case runCtx.Cfg.Build.Cluster != nil:
logrus.Debugln("Using builder: kaniko")
return kaniko.NewBuilder(runCtx)
logrus.Debugln("Using builder: cluster")
return cluster.NewBuilder(runCtx)

default:
return nil, fmt.Errorf("unknown builder for config %+v", runCtx.Cfg.Build)
Expand Down

0 comments on commit 11f8a1b

Please sign in to comment.