diff --git a/CHANGELOG.md b/CHANGELOG.md index bc953513..e19c0369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v2.4.0 + +* Add support for `skipBuild` configuration option for apps, which allows deploying apps without building an app-specific image. + # v2.3.0 * Introduce aliases `kbuild` for `kd build`, `kdeploy` for `kd deploy` and `kctl` for `kd ctl`. diff --git a/pkg/build/cmd.go b/pkg/build/cmd.go index 0c522f07..23f0be4e 100644 --- a/pkg/build/cmd.go +++ b/pkg/build/cmd.go @@ -9,6 +9,10 @@ import ( ) func Run(log *util.Logger, app *config.ResolvedApp) error { + if app.SkipBuild { + log.Fatal("Build is skipped for", app.Name) + } + if app.PreBuild != "" { if strings.Contains(app.PreBuild, "/.ssh") { log.Warn("Pre-build command in 'kdeploy.conf' contains reference to '.ssh'.") diff --git a/pkg/config/types.go b/pkg/config/types.go index e99aa201..de7e14d0 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -13,6 +13,7 @@ type App struct { Name string `yaml:"name,omitempty"` Path string `yaml:"path,omitempty"` Root string `yaml:"root,omitempty"` + SkipBuild bool `yaml:"skipBuild,omitempty"` Default bool `yaml:"default,omitempty"` Platform string `yaml:"platform,omitempty"` PreBuild string `yaml:"preBuild,omitempty"` diff --git a/pkg/deploy/cmd.go b/pkg/deploy/cmd.go index 5ccf464f..c5fdd49e 100644 --- a/pkg/deploy/cmd.go +++ b/pkg/deploy/cmd.go @@ -12,10 +12,14 @@ import ( ) func Run(log *util.Logger, app *config.ResolvedApp, target *config.ResolvedTarget) error { - log.Note("Retrieving image", app.Name+":"+app.Tag) - img, err := docker.GetImage(log, app.Repository()) - if err != nil { - return err + var img docker.ImageManifest + if !app.SkipBuild { + log.Note("Retrieving image", app.Name+":"+app.Tag) + image, err := docker.GetImage(log, app.Repository()) + if err != nil { + return err + } + img = image } res, err := kustomize.GetResources(log, app, target, img.Descriptor.Digest.String()) @@ -34,10 +38,12 @@ func Run(log *util.Logger, app *config.ResolvedApp, target *config.ResolvedTarge return err } - log.Note("Tagging image", app.Name+":"+target.Name) - err = docker.TagImage(log, img, app.RepositoryWithTag(target.Name)) - if err != nil { - return err + if !app.SkipBuild { + log.Note("Tagging image", app.Name+":"+target.Name) + err = docker.TagImage(log, img, app.RepositoryWithTag(target.Name)) + if err != nil { + return err + } } ingresses, err := kubectl.GetGCEIngresses(log, target) @@ -62,6 +68,10 @@ func Run(log *util.Logger, app *config.ResolvedApp, target *config.ResolvedTarge log.Note("Requesting cache flush for", strings.Join(names, ", ")) } - log.Success("Successfully deployed", app.Repository(), "to", target.Name) + if app.SkipBuild { + log.Success("Successfully deployed", app.Name, "to", target.Name) + } else { + log.Success("Successfully deployed", app.Repository(), "to", target.Name) + } return nil } diff --git a/pkg/internal/kustomize/resources.go b/pkg/internal/kustomize/resources.go index 54a252f8..35924c5a 100644 --- a/pkg/internal/kustomize/resources.go +++ b/pkg/internal/kustomize/resources.go @@ -44,6 +44,13 @@ func GetResources(log *util.Logger, app *config.ResolvedApp, target *config.Reso // Search and replace in the generated YAML to set the actual deployment // image. This is the reason we cannot use 'kubectl -k ..' directly. + + if app.SkipBuild { + if bytes.Contains(yml, []byte(" image: "+app.Name)) { + log.Fatal("Image reference found, but build was skipped for", app.Name) + } + } + url := app.RepositoryWithDigest(digest) buf := bytes.NewBuffer(bytes.Replace(yml, []byte(" image: "+app.Name), []byte(" image: "+url), -1))