Generate backend bus events in the backends

This commit is contained in:
Ettore Di Giacinto
2021-03-16 14:46:28 +01:00
parent f8ef1c0889
commit 662742851a
3 changed files with 23 additions and 6 deletions

View File

@@ -24,6 +24,8 @@ import (
"path/filepath"
"strings"
bus "github.com/mudler/luet/pkg/bus"
docker "github.com/fsouza/go-dockerclient"
capi "github.com/mudler/docker-companion/api"
@@ -44,6 +46,7 @@ func NewSimpleDockerBackend() compiler.CompilerBackend {
// TODO: Missing still: labels, and build args expansion
func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
name := opts.ImageName
bus.Manager.Publish(bus.EventImagePreBuild, opts)
buildarg := genBuildCommand(opts)
Info(":whale2: Building image " + name)
@@ -74,6 +77,8 @@ func (*SimpleDocker) BuildImage(opts compiler.CompilerBackendOptions) error {
Info(":whale: Squashing image " + name + " done")
}
bus.Manager.Publish(bus.EventImagePostBuild, opts)
return nil
}
@@ -90,6 +95,8 @@ func (*SimpleDocker) CopyImage(src, dst string) error {
func (*SimpleDocker) DownloadImage(opts compiler.CompilerBackendOptions) error {
name := opts.ImageName
bus.Manager.Publish(bus.EventImagePrePull, opts)
buildarg := []string{"pull", name}
Debug(":whale: Downloading image " + name)
@@ -103,6 +110,8 @@ func (*SimpleDocker) DownloadImage(opts compiler.CompilerBackendOptions) error {
}
Info(":whale: Downloaded image:", name)
bus.Manager.Publish(bus.EventImagePostPull, opts)
return nil
}
@@ -138,6 +147,7 @@ func (*SimpleDocker) RemoveImage(opts compiler.CompilerBackendOptions) error {
func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
name := opts.ImageName
pusharg := []string{"push", name}
bus.Manager.Publish(bus.EventImagePrePush, opts)
Spinner(22)
defer SpinnerStop()
@@ -147,6 +157,8 @@ func (*SimpleDocker) Push(opts compiler.CompilerBackendOptions) error {
return errors.Wrap(err, "Failed pushing image: "+string(out))
}
Info(":whale: Pushed image:", name)
bus.Manager.Publish(bus.EventImagePostPush, opts)
//Info(string(out))
return nil
}