add skip-build flag to bypass generating build config
@@ -48,6 +48,7 @@ import (
const NoDockerfile = "None (image not built from these sources)"
var outfile string
+var skipBuild bool
func NewCmdInit(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
@@ -64,6 +65,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
func AddInitFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&outfile, "file", "f", "", "File to write generated skaffold config")
+ cmd.Flags().BoolVar(&skipBuild, "skip-build", false, "Skip generating build artifacts in skaffold config")
}
func doInit(out io.Writer) error {
@@ -107,6 +109,10 @@ func doInit(out io.Writer) error {
logrus.Infof("invalid k8s yaml %s: %s", file, err.Error())
}
}
+
+ var pairs []dockerfilePair
+ // conditionally generate build artifacts
+ if !skipBuild {
if len(dockerfiles) == 0 {
return errors.New("one or more valid Dockerfiles must be present to run skaffold; please provide at least one Dockerfile and try again")
}
@@ -115,10 +121,11 @@ func doInit(out io.Writer) error {
return errors.New("one or more valid kubernetes manifests is required to run skaffold")
}
- pairs, err := resolveDockerfileImages(dockerfiles, images)
+ pairs, err = resolveDockerfileImages(dockerfiles, images)
if err != nil {
return errors.Wrap(err, "resolving dockerfile/image pairs")
}
+ }
cfg, err := generateSkaffoldConfig(k8sConfigs, pairs)
if err != nil {
@@ -185,6 +192,7 @@ func generateSkaffoldConfig(k8sConfigs []string, dockerfilePairs []dockerfilePai
return nil, errors.Wrap(err, "generating default config")
}
+ if len(dockerfilePairs) > 0 {
var artifacts []*v1alpha2.Artifact
for _, pair := range dockerfilePairs {
artifacts = append(artifacts, &v1alpha2.Artifact{
@@ -193,6 +201,10 @@ func generateSkaffoldConfig(k8sConfigs []string, dockerfilePairs []dockerfilePai
})
}
config.Build.Artifacts = artifacts
+ } else {
+ // explicitly remove build config if we don't have any generated build artifacts
+ config.Build = v1alpha2.BuildConfig{}
+ }
config.Deploy = v1alpha2.DeployConfig{
DeployType: v1alpha2.DeployType{
