Wrap BuildArgs in our own type
This commit is contained in:
		
							parent
							
								
									33f4805f62
								
							
						
					
					
						commit
						4de14c34dd
					
				|  | @ -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" | ||||||
|  | } | ||||||
|  | @ -23,7 +23,6 @@ import ( | ||||||
| 
 | 
 | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/executor" | 	"github.com/GoogleContainerTools/kaniko/pkg/executor" | ||||||
| 	"github.com/genuinetools/amicontained/container" | 	"github.com/genuinetools/amicontained/container" | ||||||
| 	"strings" |  | ||||||
| 
 | 
 | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/constants" | 	"github.com/GoogleContainerTools/kaniko/pkg/constants" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"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 { | func checkContained() bool { | ||||||
| 	_, err := container.DetectRuntime() | 	_, err := container.DetectRuntime() | ||||||
| 	return err == nil | 	return err == nil | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | 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/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | 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/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/pkg/errors" | 	"github.com/pkg/errors" | ||||||
|  |  | ||||||
|  | @ -22,8 +22,8 @@ import ( | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
|  | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
|  |  | ||||||
|  | @ -18,7 +18,6 @@ package commands | ||||||
| import ( | import ( | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/testutil" | 	"github.com/GoogleContainerTools/kaniko/testutil" | ||||||
| 	docker "github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"testing" | 	"testing" | ||||||
|  | @ -98,7 +97,7 @@ func Test_EnvExecute(t *testing.T) { | ||||||
| 	testutil.CheckErrorAndDeepEqual(t, false, err, expectedEnvs, cfg.Env) | 	testutil.CheckErrorAndDeepEqual(t, false, err, expectedEnvs, cfg.Env) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func setUpBuildArgs() *docker.BuildArgs { | func setUpBuildArgs() *dockerfile.BuildArgs { | ||||||
| 	buildArgs := dockerfile.NewBuildArgs([]string{ | 	buildArgs := dockerfile.NewBuildArgs([]string{ | ||||||
| 		"buildArg1=foo", | 		"buildArg1=foo", | ||||||
| 		"buildArg2=foo2", | 		"buildArg2=foo2", | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | 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/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/docker/docker/pkg/signal" | 	"github.com/docker/docker/pkg/signal" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
|  |  | ||||||
|  | @ -17,8 +17,8 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"github.com/GoogleContainerTools/kaniko/pkg/util" | 	"github.com/GoogleContainerTools/kaniko/pkg/util" | ||||||
| 	"github.com/docker/docker/builder/dockerfile" |  | ||||||
| 	"github.com/docker/docker/builder/dockerfile/instructions" | 	"github.com/docker/docker/builder/dockerfile/instructions" | ||||||
| 	"github.com/google/go-containerregistry/v1" | 	"github.com/google/go-containerregistry/v1" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package commands | package commands | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"github.com/docker/docker/builder/dockerfile" | 	"github.com/GoogleContainerTools/kaniko/pkg/dockerfile" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -21,7 +21,11 @@ import ( | ||||||
| 	"strings" | 	"strings" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func NewBuildArgs(args []string) *d.BuildArgs { | type BuildArgs struct { | ||||||
|  | 	d.BuildArgs | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func NewBuildArgs(args []string) *BuildArgs { | ||||||
| 	argsFromOptions := make(map[string]*string) | 	argsFromOptions := make(map[string]*string) | ||||||
| 	for _, a := range args { | 	for _, a := range args { | ||||||
| 		s := strings.Split(a, "=") | 		s := strings.Split(a, "=") | ||||||
|  | @ -31,5 +35,7 @@ func NewBuildArgs(args []string) *d.BuildArgs { | ||||||
| 			argsFromOptions[s[0]] = &s[1] | 			argsFromOptions[s[0]] = &s[1] | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return d.NewBuildArgs(argsFromOptions) | 	return &BuildArgs{ | ||||||
|  | 		*d.NewBuildArgs(argsFromOptions), | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ limitations under the License. | ||||||
| package util | package util | ||||||
| 
 | 
 | ||||||
| import ( | 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/instructions" | ||||||
| 	"github.com/docker/docker/builder/dockerfile/parser" | 	"github.com/docker/docker/builder/dockerfile/parser" | ||||||
| 	"github.com/docker/docker/builder/dockerfile/shell" | 	"github.com/docker/docker/builder/dockerfile/shell" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue