Skip to content

Commit

Permalink
add event for image build
Browse files Browse the repository at this point in the history
upon image build completion, a new image type event is written for "build". more intricate details, like pulling an image, that might be done by build must be implemented in different vendored packages only after libpod is split from podman.

Fixes: containers#7022

Signed-off-by: Brent Baude <[email protected]>

<MH: Fixed imports during cherry-pick>

Signed-off-by: Matt Heon <[email protected]>
  • Loading branch information
baude authored and mheon committed Aug 17, 2020
1 parent dae6932 commit 0286cfe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libpod/events/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ const (
Attach Status = "attach"
// AutoUpdate ...
AutoUpdate Status = "auto-update"
// Build ...
Build Status = "build"
// Checkpoint ...
Checkpoint Status = "checkpoint"
// Cleanup ...
Expand Down
2 changes: 2 additions & 0 deletions libpod/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func StringToStatus(name string) (Status, error) {
switch name {
case Attach.String():
return Attach, nil
case Build.String():
return Build, nil
case Checkpoint.String():
return Checkpoint, nil
case Cleanup.String():
Expand Down
16 changes: 16 additions & 0 deletions libpod/runtime_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (

"github.com/containers/buildah/imagebuildah"
"github.com/containers/image/v5/docker/reference"
ociarchive "github.com/containers/image/v5/oci/archive"
"github.com/containers/image/v5/oci/layout"
"github.com/containers/image/v5/types"
"github.com/containers/libpod/v2/libpod/define"
"github.com/containers/libpod/v2/libpod/events"
"github.com/containers/libpod/v2/libpod/image"
"github.com/containers/libpod/v2/pkg/util"
"github.com/containers/storage"
Expand Down Expand Up @@ -147,9 +151,21 @@ func removeStorageContainers(ctrIDs []string, store storage.Store) error {
return nil
}

// newBuildEvent creates a new event based on completion of a built image
func (r *Runtime) newImageBuildCompleteEvent(idOrName string) {
e := events.NewEvent(events.Build)
e.Type = events.Image
e.Name = idOrName
if err := r.eventer.Write(e); err != nil {
logrus.Errorf("unable to write build event: %q", err)
}
}

// Build adds the runtime to the imagebuildah call
func (r *Runtime) Build(ctx context.Context, options imagebuildah.BuildOptions, dockerfiles ...string) (string, reference.Canonical, error) {
id, ref, err := imagebuildah.BuildDockerfiles(ctx, r.store, options, dockerfiles...)
// Write event for build completion
r.newImageBuildCompleteEvent(id)
return id, ref, err
}

Expand Down

0 comments on commit 0286cfe

Please sign in to comment.