Skip to content

Commit

Permalink
Store built image digest in the build status
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilata committed Jan 6, 2017
1 parent 9e682de commit 9babf9c
Show file tree
Hide file tree
Showing 28 changed files with 1,055 additions and 261 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/swagger-spec/oapi-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -23395,6 +23395,10 @@
"config": {
"$ref": "v1.ObjectReference",
"description": "config is an ObjectReference to the BuildConfig this Build is based on."
},
"outputDockerImageDigest": {
"type": "string",
"description": "outputDockerImageDigest is the digest of the built Docker image. The digest uniquely identifies the image in the registry to which it was pushed."
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions api/swagger-spec/openshift-openapi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -45669,6 +45669,10 @@
"description": "message is a human-readable message indicating details about why the build has this status.",
"type": "string"
},
"outputDockerImageDigest": {
"description": "outputDockerImageDigest is the digest of the built Docker image. The digest uniquely identifies the image in the registry to which it was pushed.",
"type": "string"
},
"outputDockerImageReference": {
"description": "outputDockerImageReference contains a reference to the Docker image that will be built by this build. Its value is computed from Build.Spec.Output.To, and should include the registry address, so that it can be used to push and pull the image.",
"type": "string"
Expand Down
5 changes: 5 additions & 0 deletions pkg/build/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ type BuildStatus struct {

// Config is an ObjectReference to the BuildConfig this Build is based on.
Config *kapi.ObjectReference

// outputDockerImageDigest is the digest of the built Docker image. The
// digest uniquely identifies the image in the registry to which it was
// pushed.
OutputDockerImageDigest string
}

// BuildPhase represents the status of a build at a point in time.
Expand Down
449 changes: 243 additions & 206 deletions pkg/build/api/v1/generated.pb.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/build/api/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/build/api/v1/swagger_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var map_BuildStatus = map[string]string{
"duration": "duration contains time.Duration object describing build time.",
"outputDockerImageReference": "outputDockerImageReference contains a reference to the Docker image that will be built by this build. Its value is computed from Build.Spec.Output.To, and should include the registry address, so that it can be used to push and pull the image.",
"config": "config is an ObjectReference to the BuildConfig this Build is based on.",
"outputDockerImageDigest": "outputDockerImageDigest is the digest of the built Docker image. The digest uniquely identifies the image in the registry to which it was pushed.",
}

func (BuildStatus) SwaggerDoc() map[string]string {
Expand Down
5 changes: 5 additions & 0 deletions pkg/build/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ type BuildStatus struct {

// config is an ObjectReference to the BuildConfig this Build is based on.
Config *kapi.ObjectReference `json:"config,omitempty" protobuf:"bytes,9,opt,name=config"`

// outputDockerImageDigest is the digest of the built Docker image. The
// digest uniquely identifies the image in the registry to which it was
// pushed.
OutputDockerImageDigest string `json:"outputDockerImageDigest,omitempty" protobuf:"bytes,10,opt,name=outputDockerImageDigest"`
}

// BuildPhase represents the status of a build at a point in time.
Expand Down
2 changes: 2 additions & 0 deletions pkg/build/api/v1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ func autoConvert_v1_BuildStatus_To_api_BuildStatus(in *BuildStatus, out *api.Bui
} else {
out.Config = nil
}
out.OutputDockerImageDigest = in.OutputDockerImageDigest
return nil
}

Expand All @@ -911,6 +912,7 @@ func autoConvert_api_BuildStatus_To_v1_BuildStatus(in *api.BuildStatus, out *Bui
} else {
out.Config = nil
}
out.OutputDockerImageDigest = in.OutputDockerImageDigest
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/build/api/v1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ func DeepCopy_v1_BuildStatus(in interface{}, out interface{}, c *conversion.Clon
} else {
out.Config = nil
}
out.OutputDockerImageDigest = in.OutputDockerImageDigest
return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/build/api/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ func DeepCopy_api_BuildStatus(in interface{}, out interface{}, c *conversion.Clo
} else {
out.Config = nil
}
out.OutputDockerImageDigest = in.OutputDockerImageDigest
return nil
}
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/build/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fsouza/go-dockerclient"

kclient "k8s.io/kubernetes/pkg/client/unversioned"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"

"github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/client"
Expand Down Expand Up @@ -195,10 +196,17 @@ func retryBuildStatusUpdate(build *api.Build, client client.BuildInterface, sour

latestBuild.Status.Reason = build.Status.Reason
latestBuild.Status.Message = build.Status.Message
latestBuild.Status.OutputDockerImageDigest = build.Status.OutputDockerImageDigest

if _, err := client.UpdateDetails(latestBuild); err != nil {
return err
}
return nil
})
}

func handleBuildStatusUpdate(build *api.Build, client client.BuildInterface, sourceRev *api.SourceRevision) {
if updateErr := retryBuildStatusUpdate(build, client, sourceRev); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error occurred while updating the build status: %v", updateErr))
}
}
32 changes: 12 additions & 20 deletions pkg/build/builder/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
docker "github.com/fsouza/go-dockerclient"

kapi "k8s.io/kubernetes/pkg/api"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"

s2iapi "github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/tar"
Expand Down Expand Up @@ -71,18 +70,14 @@ func (d *DockerBuilder) Build() error {
if err != nil {
d.build.Status.Reason = api.StatusReasonFetchSourceFailed
d.build.Status.Message = api.StatusMessageFetchSourceFailed
if updateErr := retryBuildStatusUpdate(d.build, d.client, nil); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, nil)
return err
}

if sourceInfo != nil {
glog.V(4).Infof("Setting build revision with details %#v", sourceInfo)
revision := updateBuildRevision(d.build, sourceInfo)
if updateErr := retryBuildStatusUpdate(d.build, d.client, revision); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, revision)
}
if err = d.addBuildParameters(buildDir, sourceInfo); err != nil {
return err
Expand Down Expand Up @@ -126,9 +121,7 @@ func (d *DockerBuilder) Build() error {
if err = pullImage(d.dockerClient, imageName, pullAuthConfig); err != nil {
d.build.Status.Reason = api.StatusReasonPullBuilderImageFailed
d.build.Status.Message = api.StatusMessagePullBuilderImageFailed
if updateErr := retryBuildStatusUpdate(d.build, d.client, nil); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, nil)
return fmt.Errorf("failed to pull image: %v", err)
}
}
Expand All @@ -137,19 +130,15 @@ func (d *DockerBuilder) Build() error {
if err = d.dockerBuild(buildDir, buildTag, d.build.Spec.Source.Secrets); err != nil {
d.build.Status.Reason = api.StatusReasonDockerBuildFailed
d.build.Status.Message = api.StatusMessageDockerBuildFailed
if updateErr := retryBuildStatusUpdate(d.build, d.client, nil); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, nil)
return err
}

cname := containerName("docker", d.build.Name, d.build.Namespace, "post-commit")
if err := execPostCommitHook(d.dockerClient, d.build.Spec.PostCommit, buildTag, cname); err != nil {
d.build.Status.Reason = api.StatusReasonPostCommitHookFailed
d.build.Status.Message = api.StatusMessagePostCommitHookFailed
if updateErr := retryBuildStatusUpdate(d.build, d.client, nil); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, nil)
return err
}

Expand All @@ -173,14 +162,17 @@ func (d *DockerBuilder) Build() error {
glog.V(4).Infof("Authenticating Docker push with user %q", pushAuthConfig.Username)
}
glog.V(0).Infof("\nPushing image %s ...", pushTag)
if err := pushImage(d.dockerClient, pushTag, pushAuthConfig); err != nil {
digest, err := pushImage(d.dockerClient, pushTag, pushAuthConfig)
if err != nil {
d.build.Status.Reason = api.StatusReasonPushImageToRegistryFailed
d.build.Status.Message = api.StatusMessagePushImageToRegistryFailed
if updateErr := retryBuildStatusUpdate(d.build, d.client, nil); updateErr != nil {
utilruntime.HandleError(fmt.Errorf("error: An error occured while updating the build status: %v", updateErr))
}
handleBuildStatusUpdate(d.build, d.client, nil)
return reportPushFailure(err, authPresent, pushAuthConfig)
}
if digest != "" {
d.build.Status.OutputDockerImageDigest = digest
handleBuildStatusUpdate(d.build, d.client, nil)
}
glog.V(0).Infof("Push successful")
}
return nil
Expand Down
Loading

0 comments on commit 9babf9c

Please sign in to comment.