Skip to content

Commit

Permalink
Add support for configuration option for apps, which allows deploying…
Browse files Browse the repository at this point in the history
… apps without building an app-specific image.
  • Loading branch information
rolftimmermans committed Nov 6, 2024
1 parent 0aeeacf commit 5b9e810
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
4 changes: 4 additions & 0 deletions pkg/build/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'.")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
28 changes: 19 additions & 9 deletions pkg/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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
}
7 changes: 7 additions & 0 deletions pkg/internal/kustomize/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 5b9e810

Please sign in to comment.