mirror of
https://github.com/mudler/luet.git
synced 2025-07-31 23:05:03 +00:00
Generate backend bus events in the backends
This commit is contained in:
parent
f8ef1c0889
commit
662742851a
@ -24,6 +24,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
bus "github.com/mudler/luet/pkg/bus"
|
||||||
|
|
||||||
docker "github.com/fsouza/go-dockerclient"
|
docker "github.com/fsouza/go-dockerclient"
|
||||||
capi "github.com/mudler/docker-companion/api"
|
capi "github.com/mudler/docker-companion/api"
|
||||||
|
|
||||||
@ -44,6 +46,7 @@ func NewSimpleDockerBackend() compiler.CompilerBackend {
|
|||||||
// TODO: Missing still: labels, and build args expansion
|
// TODO: Missing still: labels, and build args expansion
|
||||||
func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
|
bus.Manager.Publish(bus.EventImagePreBuild, opts)
|
||||||
|
|
||||||
buildarg := genBuildCommand(opts)
|
buildarg := genBuildCommand(opts)
|
||||||
Info(":whale2: Building image " + name)
|
Info(":whale2: Building image " + name)
|
||||||
@ -74,6 +77,8 @@ func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
Info(":whale: Squashing image " + name + " done")
|
Info(":whale: Squashing image " + name + " done")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bus.Manager.Publish(bus.EventImagePostBuild, opts)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +95,8 @@ func (*SimpleDocker) CopyImage(src, dst string) error {
|
|||||||
|
|
||||||
func (*SimpleDocker) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleDocker) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
|
bus.Manager.Publish(bus.EventImagePrePull, opts)
|
||||||
|
|
||||||
buildarg := []string{"pull", name}
|
buildarg := []string{"pull", name}
|
||||||
Debug(":whale: Downloading image " + name)
|
Debug(":whale: Downloading image " + name)
|
||||||
|
|
||||||
@ -103,6 +110,8 @@ func (*SimpleDocker) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Info(":whale: Downloaded image:", name)
|
Info(":whale: Downloaded image:", name)
|
||||||
|
bus.Manager.Publish(bus.EventImagePostPull, opts)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +147,7 @@ func (*SimpleDocker) RemoveImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
pusharg := []string{"push", name}
|
pusharg := []string{"push", name}
|
||||||
|
bus.Manager.Publish(bus.EventImagePrePush, opts)
|
||||||
|
|
||||||
Spinner(22)
|
Spinner(22)
|
||||||
defer SpinnerStop()
|
defer SpinnerStop()
|
||||||
@ -147,6 +157,8 @@ func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
|
|||||||
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
||||||
}
|
}
|
||||||
Info(":whale: Pushed image:", name)
|
Info(":whale: Pushed image:", name)
|
||||||
|
bus.Manager.Publish(bus.EventImagePostPush, opts)
|
||||||
|
|
||||||
//Info(string(out))
|
//Info(string(out))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
bus "github.com/mudler/luet/pkg/bus"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ func NewSimpleImgBackend() compiler.CompilerBackend {
|
|||||||
// TODO: Missing still: labels, and build args expansion
|
// TODO: Missing still: labels, and build args expansion
|
||||||
func (*SimpleImg) BuildImage(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleImg) BuildImage(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
|
bus.Manager.Publish(bus.EventImagePreBuild, opts)
|
||||||
|
|
||||||
buildarg := genBuildCommand(opts)
|
buildarg := genBuildCommand(opts)
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ func (*SimpleImg) BuildImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
bus.Manager.Publish(bus.EventImagePostBuild, opts)
|
||||||
|
|
||||||
Info(":tea: Building image " + name + " done")
|
Info(":tea: Building image " + name + " done")
|
||||||
|
|
||||||
@ -68,6 +72,8 @@ func (*SimpleImg) RemoveImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
|
|
||||||
func (*SimpleImg) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleImg) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
|
bus.Manager.Publish(bus.EventImagePrePull, opts)
|
||||||
|
|
||||||
buildarg := []string{"pull", name}
|
buildarg := []string{"pull", name}
|
||||||
Debug(":tea: Downloading image " + name)
|
Debug(":tea: Downloading image " + name)
|
||||||
|
|
||||||
@ -81,6 +87,7 @@ func (*SimpleImg) DownloadImage(opts compiler.CompilerBackendOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Info(":tea: Image " + name + " downloaded")
|
Info(":tea: Image " + name + " downloaded")
|
||||||
|
bus.Manager.Publish(bus.EventImagePostPull, opts)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -181,12 +188,16 @@ func (i *SimpleImg) Changes(fromImage, toImage compiler.CompilerBackendOptions)
|
|||||||
|
|
||||||
func (*SimpleImg) Push(opts compiler.CompilerBackendOptions) error {
|
func (*SimpleImg) Push(opts compiler.CompilerBackendOptions) error {
|
||||||
name := opts.ImageName
|
name := opts.ImageName
|
||||||
|
bus.Manager.Publish(bus.EventImagePrePush, opts)
|
||||||
|
|
||||||
pusharg := []string{"push", name}
|
pusharg := []string{"push", name}
|
||||||
out, err := exec.Command("img", pusharg...).CombinedOutput()
|
out, err := exec.Command("img", pusharg...).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
return errors.Wrap(err, "Failed pushing image: "+string(out))
|
||||||
}
|
}
|
||||||
Info(":tea: Pushed image:", name)
|
Info(":tea: Pushed image:", name)
|
||||||
|
bus.Manager.Publish(bus.EventImagePostPush, opts)
|
||||||
|
|
||||||
//Info(string(out))
|
//Info(string(out))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,6 @@ func (cs *LuetCompiler) buildPackageImage(image, buildertaggedImage, packageImag
|
|||||||
buildAndPush := func(opts CompilerBackendOptions) error {
|
buildAndPush := func(opts CompilerBackendOptions) error {
|
||||||
buildImage := true
|
buildImage := true
|
||||||
if cs.Options.PullFirst {
|
if cs.Options.PullFirst {
|
||||||
bus.Manager.Publish(bus.EventImagePrePull, opts)
|
|
||||||
err := cs.Backend.DownloadImage(opts)
|
err := cs.Backend.DownloadImage(opts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
buildImage = false
|
buildImage = false
|
||||||
@ -405,20 +404,15 @@ func (cs *LuetCompiler) buildPackageImage(image, buildertaggedImage, packageImag
|
|||||||
Warning("Failed to download '" + opts.ImageName + "'. Will keep going and build the image unless you use --fatal")
|
Warning("Failed to download '" + opts.ImageName + "'. Will keep going and build the image unless you use --fatal")
|
||||||
Warning(err.Error())
|
Warning(err.Error())
|
||||||
}
|
}
|
||||||
bus.Manager.Publish(bus.EventImagePostPull, opts)
|
|
||||||
}
|
}
|
||||||
if buildImage {
|
if buildImage {
|
||||||
bus.Manager.Publish(bus.EventImagePreBuild, opts)
|
|
||||||
if err := cs.Backend.BuildImage(opts); err != nil {
|
if err := cs.Backend.BuildImage(opts); err != nil {
|
||||||
return errors.Wrap(err, "Could not build image: "+image+" "+opts.DockerFileName)
|
return errors.Wrap(err, "Could not build image: "+image+" "+opts.DockerFileName)
|
||||||
}
|
}
|
||||||
bus.Manager.Publish(bus.EventImagePostBuild, opts)
|
|
||||||
if cs.Options.Push {
|
if cs.Options.Push {
|
||||||
bus.Manager.Publish(bus.EventImagePrePush, opts)
|
|
||||||
if err = cs.Backend.Push(opts); err != nil {
|
if err = cs.Backend.Push(opts); err != nil {
|
||||||
return errors.Wrap(err, "Could not push image: "+image+" "+opts.DockerFileName)
|
return errors.Wrap(err, "Could not push image: "+image+" "+opts.DockerFileName)
|
||||||
}
|
}
|
||||||
bus.Manager.Publish(bus.EventImagePostPush, opts)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user