Skip to content

Commit 8caa6f1

Browse files
committed
pkg/api: replace uuid for basic random id
The uuid package in distribution was created as a utility for the distribution project itself, to cut down external dependencies (see [1][1]). For compose, this has the reverse effect, as it now brings all the dependencies of the distribution module with it. This patch switches to the uuid generation to crypto/rand to produce a random id. I was considering using a different uuid implementation, or docker's "stringid.GenerateRandomID", but all of those are doing more than needed, so keep it simple. Currently, this change has little effect, because compose also uses the distribution module for other purposes, but the distribution project is in the process of moving the "reference" package to a separate module, in which case we don't want to depend on the distribution module only for the uuid package. [1]: distribution/distribution@36e34a5 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent d6f842b commit 8caa6f1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pkg/api/dryrunclient.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package api
1919
import (
2020
"bytes"
2121
"context"
22+
"crypto/rand"
2223
"encoding/json"
2324
"fmt"
2425
"io"
@@ -31,8 +32,6 @@ import (
3132
"github.com/docker/buildx/builder"
3233
"github.com/docker/buildx/util/imagetools"
3334
"github.com/docker/cli/cli/command"
34-
35-
"github.com/distribution/distribution/v3/uuid"
3635
moby "github.com/docker/docker/api/types"
3736
containerType "github.com/docker/docker/api/types/container"
3837
"github.com/docker/docker/api/types/events"
@@ -298,7 +297,9 @@ func (d *DryRunClient) VolumeRemove(ctx context.Context, volumeID string, force
298297
}
299298

300299
func (d *DryRunClient) ContainerExecCreate(ctx context.Context, container string, config moby.ExecConfig) (moby.IDResponse, error) {
301-
id := uuid.Generate().String()
300+
b := make([]byte, 32)
301+
_, _ = rand.Read(b)
302+
id := fmt.Sprintf("%x", b)
302303
d.execs.Store(id, execDetails{
303304
container: container,
304305
command: config.Cmd,

pkg/e2e/watch_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package e2e
1818

1919
import (
20+
"crypto/rand"
2021
"fmt"
2122
"os"
2223
"path/filepath"
@@ -26,7 +27,6 @@ import (
2627
"testing"
2728
"time"
2829

29-
"github.com/distribution/distribution/v3/uuid"
3030
"github.com/stretchr/testify/require"
3131
"gotest.tools/v3/assert"
3232
"gotest.tools/v3/assert/cmp"
@@ -127,7 +127,9 @@ func doTest(t *testing.T, svcName string, tarSync bool) {
127127
}
128128

129129
waitForFlush := func() {
130-
sentinelVal := uuid.Generate().String()
130+
b := make([]byte, 32)
131+
_, _ = rand.Read(b)
132+
sentinelVal := fmt.Sprintf("%x", b)
131133
writeDataFile("wait.txt", sentinelVal)
132134
poll.WaitOn(t, checkFileContents("/app/data/wait.txt", sentinelVal))
133135
}

0 commit comments

Comments
 (0)