Skip to content

Commit f5f0a62

Browse files
jjbustamanteclaude
andauthored
Use Docker API version negotiation instead of hardcoded version (#2474)
* Use Docker API version negotiation instead of hardcoded version Fixes #2464 This change replaces all hardcoded Docker API version 1.38 references with WithAPIVersionNegotiation(), allowing pack to automatically adapt to the Docker daemon's supported API version. Changes: - Updated main client initialization to use API version negotiation - Updated SSH Docker client to use API version negotiation - Updated all test files to use API version negotiation - Upgraded fake-lifecycle test dependencies from Docker client v1.4.2 (2019) to v28.5.1 - Fixed fake-lifecycle imports and API calls for compatibility with modern Docker client Benefits: - Works with modern Docker daemons requiring API 1.44+ (Docker 27+) - Backward compatible with older Docker versions - Future-proof - no need to update hardcoded versions - Solves Windows runner issue without requiring Docker 27 upgrade 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Juan Bustamante <bustamantejj@gmail.com> * Update Example_build test to use newer builder with modern lifecycle The cnbs/sample-builder:noble builder includes a recent lifecycle version that supports Docker API 1.44+, fixing the test failure on systems with modern Docker daemons (Docker 27+). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Juan Bustamante <bustamantejj@gmail.com> * Downgrade fake-lifecycle dependencies for Go 1.23 compatibility Updated fake-lifecycle test module to support Go 1.23.4 (Windows runner): - Downgraded lifecycle from v0.20.11 to v0.19.3 - Downgraded go-containerregistry from v0.20.6 to v0.19.2 - Set Go requirement to 1.23 (compatible with Go 1.23.4) - Updated Dockerfile to use golang:1.23 base image The older versions still support Docker API 1.44+ and work correctly with modern Docker daemons requiring minimum API version 1.44. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Juan Bustamante <bustamantejj@gmail.com> --------- Signed-off-by: Juan Bustamante <bustamantejj@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent d1a30b6 commit f5f0a62

20 files changed

Lines changed: 396 additions & 236 deletions

acceptance/acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestAcceptance(t *testing.T) {
6161

6262
assert := h.NewAssertionManager(t)
6363

64-
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
64+
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
6565
assert.Nil(err)
6666

6767
imageManager = managers.NewImageManager(t, dockerCli)

benchmarks/build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var (
3232

3333
func BenchmarkBuild(b *testing.B) {
3434
setEnv()
35-
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithVersion("1.38"))
35+
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithAPIVersionNegotiation())
3636
if err != nil {
3737
b.Error(errors.Wrap(err, "creating docker client"))
3838
}

cmd/docker_init.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"golang.org/x/term"
1818

1919
"github.com/buildpacks/pack/internal/sshdialer"
20-
"github.com/buildpacks/pack/pkg/client"
2120
)
2221

2322
func tryInitSSHDockerClient() (dockerClient.APIClient, error) {
@@ -50,7 +49,7 @@ func tryInitSSHDockerClient() (dockerClient.APIClient, error) {
5049
}
5150

5251
dockerClientOpts := []dockerClient.Opt{
53-
dockerClient.WithVersion(client.DockerAPIVersion),
52+
dockerClient.WithAPIVersionNegotiation(),
5453
dockerClient.WithHTTPClient(httpClient),
5554
dockerClient.WithHost("http://dummy"),
5655
dockerClient.WithDialContext(dialContext),

internal/build/container_ops_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestContainerOperations(t *testing.T) {
3434
h.RequireDocker(t)
3535

3636
var err error
37-
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
37+
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
3838
h.AssertNil(t, err)
3939

4040
spec.Run(t, "container-ops", testContainerOps, spec.Report(report.Terminal{}), spec.Sequential())

internal/build/lifecycle_execution_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ func (f *fakeDockerClient) NetworkRemove(ctx context.Context, network string) er
27192719
}
27202720

27212721
func newTestLifecycleExecErr(t *testing.T, logVerbose bool, tmpDir string, ops ...func(*build.LifecycleOptions)) (*build.LifecycleExecution, error) {
2722-
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
2722+
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
27232723
h.AssertNil(t, err)
27242724

27252725
var outBuf bytes.Buffer

internal/build/phase_config_provider_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
313313
var outBuf bytes.Buffer
314314
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())
315315

316-
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
316+
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
317317
h.AssertNil(t, err)
318318

319319
defaultBuilder, err := fakes.NewFakeBuilder()
@@ -350,7 +350,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
350350
var outBuf bytes.Buffer
351351
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())
352352

353-
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
353+
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
354354
h.AssertNil(t, err)
355355

356356
defaultBuilder, err := fakes.NewFakeBuilder()

internal/build/phase_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestPhase(t *testing.T) {
4949
h.RequireDocker(t)
5050

5151
var err error
52-
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
52+
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
5353
h.AssertNil(t, err)
5454

5555
info, err := ctrClient.Info(context.TODO())
@@ -79,7 +79,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
7979
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
8080

8181
var err error
82-
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
82+
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
8383
h.AssertNil(t, err)
8484

8585
info, err := ctrClient.Info(context.Background())

internal/build/testdata/fake-lifecycle/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM golang
1+
FROM golang:1.23
22

33
RUN mkdir /lifecycle
44
WORKDIR /go/src/step
55
COPY . .
6-
RUN GO111MODULE=on go build -o /cnb/lifecycle/phase ./phase.go
6+
RUN GO111MODULE=on GOFLAGS=-mod=mod go build -o /cnb/lifecycle/phase ./phase.go
77

88
ENV CNB_USER_ID 111
99
ENV CNB_GROUP_ID 222
Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,85 @@
11
module step
22

33
require (
4-
github.com/buildpacks/lifecycle v0.5.1-0.20191212164213-3b2b120be460
5-
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7
6-
github.com/google/go-containerregistry v0.0.0-20191018211754-b77a90c667af
4+
github.com/buildpacks/lifecycle v0.19.3
5+
github.com/docker/docker v28.5.1+incompatible
6+
github.com/google/go-containerregistry v0.19.2
77
)
88

9-
go 1.17
9+
require (
10+
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
11+
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
12+
github.com/Azure/go-autorest/autorest v0.11.30 // indirect
13+
github.com/Azure/go-autorest/autorest/adal v0.9.24 // indirect
14+
github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 // indirect
15+
github.com/Azure/go-autorest/autorest/azure/cli v0.4.7 // indirect
16+
github.com/Azure/go-autorest/autorest/date v0.3.1 // indirect
17+
github.com/Azure/go-autorest/logger v0.2.2 // indirect
18+
github.com/Azure/go-autorest/tracing v0.6.1 // indirect
19+
github.com/Microsoft/go-winio v0.6.2 // indirect
20+
github.com/aws/aws-sdk-go-v2 v1.36.3 // indirect
21+
github.com/aws/aws-sdk-go-v2/config v1.29.14 // indirect
22+
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
23+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
24+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
25+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
26+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
27+
github.com/aws/aws-sdk-go-v2/service/ecr v1.44.0 // indirect
28+
github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.33.0 // indirect
29+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
30+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
31+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
32+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
33+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
34+
github.com/aws/smithy-go v1.22.3 // indirect
35+
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.9.1 // indirect
36+
github.com/beorn7/perks v1.0.1 // indirect
37+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
38+
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
39+
github.com/containerd/errdefs v1.0.0 // indirect
40+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
41+
github.com/containerd/log v0.1.0 // indirect
42+
github.com/containerd/stargz-snapshotter/estargz v0.16.3 // indirect
43+
github.com/dimchansky/utfbom v1.1.1 // indirect
44+
github.com/distribution/reference v0.6.0 // indirect
45+
github.com/docker/cli v28.2.2+incompatible // indirect
46+
github.com/docker/distribution v2.8.3+incompatible // indirect
47+
github.com/docker/docker-credential-helpers v0.9.3 // indirect
48+
github.com/docker/go-connections v0.5.0 // indirect
49+
github.com/docker/go-metrics v0.0.1 // indirect
50+
github.com/docker/go-units v0.5.0 // indirect
51+
github.com/felixge/httpsnoop v1.0.4 // indirect
52+
github.com/go-logr/logr v1.4.3 // indirect
53+
github.com/go-logr/stdr v1.2.2 // indirect
54+
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
55+
github.com/gorilla/mux v1.8.1 // indirect
56+
github.com/klauspost/compress v1.18.0 // indirect
57+
github.com/mitchellh/go-homedir v1.1.0 // indirect
58+
github.com/moby/docker-image-spec v1.3.1 // indirect
59+
github.com/moby/sys/atomicwriter v0.1.0 // indirect
60+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
61+
github.com/opencontainers/go-digest v1.0.0 // indirect
62+
github.com/opencontainers/image-spec v1.1.1 // indirect
63+
github.com/pkg/errors v0.9.1 // indirect
64+
github.com/prometheus/client_golang v1.22.0 // indirect
65+
github.com/prometheus/client_model v0.6.2 // indirect
66+
github.com/prometheus/common v0.64.0 // indirect
67+
github.com/prometheus/procfs v0.16.1 // indirect
68+
github.com/sirupsen/logrus v1.9.3 // indirect
69+
github.com/vbatts/tar-split v0.12.1 // indirect
70+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
71+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
72+
go.opentelemetry.io/otel v1.38.0 // indirect
73+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect
74+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
75+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
76+
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
77+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
78+
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
79+
golang.org/x/crypto v0.38.0 // indirect
80+
golang.org/x/sync v0.15.0 // indirect
81+
golang.org/x/sys v0.35.0 // indirect
82+
google.golang.org/protobuf v1.36.10 // indirect
83+
)
84+
85+
go 1.23

0 commit comments

Comments
 (0)