Skip to content

Commit

Permalink
Remove random build ID (#1225)
Browse files Browse the repository at this point in the history
This ID was added for diagnostics and we haven't seen any warnings
reported so it should be safe to remove. More importantly the presence
of the random label causes perpetual diffs, which is undesirable.

Fixes #1219
Fixes #1224
Refs #846
  • Loading branch information
blampe authored Sep 19, 2024
1 parent fee3069 commit 96b658d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
2 changes: 2 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func TestDockerfileWithTarget(t *testing.T) {
}

func TestAzureContainerRegistry(t *testing.T) {
t.Skip("https://github.com/pulumi/pulumi-docker/issues/1238")

location := os.Getenv("AZURE_LOCATION")
if location == "" {
t.Skipf("Skipping test due to missing AZURE_LOCATION environment variable")
Expand Down
2 changes: 2 additions & 0 deletions examples/examples_py_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
)

func TestAzureContainerRegistryPy(t *testing.T) {
t.Skip("https://github.com/pulumi/pulumi-docker/issues/1238")

location := os.Getenv("AZURE_LOCATION")
if location == "" {
t.Skipf("Skipping test due to missing AZURE_LOCATION environment variable")
Expand Down
2 changes: 1 addition & 1 deletion provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v25.0.2+incompatible
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
github.com/moby/buildkit v0.13.0-beta3.0.20240205165705-d6e142600ee5
github.com/moby/moby v25.0.4+incompatible
github.com/moby/patternmatcher v0.6.0
Expand Down Expand Up @@ -125,6 +124,7 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/google/wire v0.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
Expand Down
37 changes: 3 additions & 34 deletions provider/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/jsonmessage"
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/google/uuid"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/session"
Expand Down Expand Up @@ -432,38 +431,14 @@ func (p *dockerNativeProvider) getRepoDigest(
}

// runImageBuild runs the image build and ensures that the correct image exists in the local image
// store. Due to reliability issues and a possible race condition, we use a defense-in-depth
// approach to add uniqueness to built images, and poll for the image store to contain a built image
// with the ID we expect.
//
// The returned image ID will be a sha that is unique to the image store, but cannot be used for
// pushing, e.g.: "sha256:39a1a41d26ee99b35c260e96b8fa21778885a4a67c8f1d81c7b58b1979d52319". These
// ids are only meaningful for the Docker Engine that built them.
//
// We take these steps to ensure that the image we built is the image we push:
//
// 1. We label the image with a unique buildID.
//
// 2. We obtain the Docker image store's imageID as a result of `ImageBuild`.
//
// 3. We poll the image store looking for the image.
//
// 4. We only return an imageID if the image in the store matches both (1.) and (2.)
// store.
func (p *dockerNativeProvider) runImageBuild(
ctx context.Context, docker *client.Client, tar io.Reader,
opts types.ImageBuildOptions, urn resource.URN,
) (string, error) {
if opts.Labels == nil {
opts.Labels = make(map[string]string)
}
// TODO: https://github.com/pulumi/pulumi-docker/issues/846 - Consider removing the build ID.
id, err := uuid.NewRandom()
if err != nil {
return "", fmt.Errorf("error generating random ID for build: %v", err)
}
buildIDLabel := "pulumi.com/build-id"
buildIDValue := id.String()
opts.Labels[buildIDLabel] = buildIDValue

// Close the imgBuildResp in a timely manner
_ = p.host.LogStatus(ctx, "info", urn, "Starting Docker build")
Expand Down Expand Up @@ -507,13 +482,7 @@ func (p *dockerNativeProvider) runImageBuild(
// Search for our imageID in listResult
for _, storedImage := range listResult {
if storedImage.ID == imageID {
if storedImage.Labels[buildIDLabel] == buildIDValue {
return true, nil
}
_ = p.host.Log(ctx, "warning", urn,
fmt.Sprintf("Found in store does not match built image, expected label %s=%s, found %s",
buildIDLabel, buildIDValue, storedImage.Labels[buildIDLabel]))
return false, nil
return true, nil
}
}
return false, nil
Expand Down Expand Up @@ -896,7 +865,7 @@ func processLogLine(jm jsonmessage.JSONMessage,
"credentials. Please double check you are using the correct credentials and registry name.",
jm.Error.Message)
}
return "", fmt.Errorf(jm.Error.Message)
return "", fmt.Errorf("%s", jm.Error.Message)
}
if jm.From != "" {
info += jm.From
Expand Down

0 comments on commit 96b658d

Please sign in to comment.