Wrap BuildArgs in our own type

This commit is contained in:
Priya Wadhwa 2018-05-11 10:23:13 -07:00
parent 33f4805f62
commit 4de14c34dd
No known key found for this signature in database
GPG Key ID: 0D0DAFD8F7AA73AE
21 changed files with 69 additions and 42 deletions

43
cmd/executor/cmd/args.go Normal file
View File

@ -0,0 +1,43 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd
import (
"github.com/sirupsen/logrus"
"strings"
)
// The buildArg type is used to pass in multiple --build-arg flags
type buildArg []string
// Now, for our new type, implement the two methods of
// the flag.Value interface...
// The first method is String() string
func (b *buildArg) String() string {
return strings.Join(*b, ",")
}
// The second method is Set(value string) error
func (b *buildArg) Set(value string) error {
logrus.Infof("appending to build args %s", value)
*b = append(*b, value)
return nil
}
func (b *buildArg) Type() string {
return "build-arg type"
}

View File

@ -23,7 +23,6 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/executor"
"github.com/genuinetools/amicontained/container"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/util"
@ -86,26 +85,6 @@ var RootCmd = &cobra.Command{
},
}
type buildArg []string
// Now, for our new type, implement the two methods of
// the flag.Value interface...
// The first method is String() string
func (b *buildArg) String() string {
return strings.Join(*b, ",")
}
// The second method is Set(value string) error
func (b *buildArg) Set(value string) error {
logrus.Infof("appending to build args %s", value)
*b = append(*b, value)
return nil
}
func (b *buildArg) Type() string {
return "Build ARG Type"
}
func checkContained() bool {
_, err := container.DetectRuntime()
return err == nil

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"path/filepath"
"strings"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"strings"
"github.com/docker/docker/builder/dockerfile/instructions"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/pkg/errors"

View File

@ -22,8 +22,8 @@ import (
"path/filepath"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"strings"
"github.com/docker/docker/builder/dockerfile/instructions"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/util"

View File

@ -18,7 +18,6 @@ package commands
import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/testutil"
docker "github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"testing"
@ -98,7 +97,7 @@ func Test_EnvExecute(t *testing.T) {
testutil.CheckErrorAndDeepEqual(t, false, err, expectedEnvs, cfg.Env)
}
func setUpBuildArgs() *docker.BuildArgs {
func setUpBuildArgs() *dockerfile.BuildArgs {
buildArgs := dockerfile.NewBuildArgs([]string{
"buildArg1=foo",
"buildArg2=foo2",

View File

@ -18,7 +18,7 @@ package commands
import (
"fmt"
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/util"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/util"

View File

@ -17,8 +17,8 @@ limitations under the License.
package commands
import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,8 +17,8 @@ limitations under the License.
package commands
import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,8 +17,8 @@ limitations under the License.
package commands
import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/docker/docker/pkg/signal"
"github.com/google/go-containerregistry/v1"

View File

@ -17,8 +17,8 @@ limitations under the License.
package commands
import (
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"os"
"strings"

View File

@ -17,7 +17,7 @@ limitations under the License.
package commands
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"os"
"path/filepath"

View File

@ -21,7 +21,11 @@ import (
"strings"
)
func NewBuildArgs(args []string) *d.BuildArgs {
type BuildArgs struct {
d.BuildArgs
}
func NewBuildArgs(args []string) *BuildArgs {
argsFromOptions := make(map[string]*string)
for _, a := range args {
s := strings.Split(a, "=")
@ -31,5 +35,7 @@ func NewBuildArgs(args []string) *d.BuildArgs {
argsFromOptions[s[0]] = &s[1]
}
}
return d.NewBuildArgs(argsFromOptions)
return &BuildArgs{
*d.NewBuildArgs(argsFromOptions),
}
}

View File

@ -17,7 +17,7 @@ limitations under the License.
package util
import (
"github.com/docker/docker/builder/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/docker/docker/builder/dockerfile/parser"
"github.com/docker/docker/builder/dockerfile/shell"