Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TESTING ONLY] #2063

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAcceptance(t *testing.T) {

assert := h.NewAssertionManager(t)

dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerCli, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
assert.Nil(err)

imageManager = managers.NewImageManager(t, dockerCli)
Expand Down Expand Up @@ -2346,6 +2346,32 @@ include = [ "*.jar", "media/mountain.jpg", "/media/person.png", ]
})
})
})

when("--mac-address", func() {
var randomMacAddress = "D5:C7:2F:43:F3:64"
var network = "host"

it.Before(func() {
h.SkipIf(t, !pack.SupportsFeature(invoke.MacAddressFlag), "mac-address is supported after pack version 0.34.0")
h.SkipIf(t, imageManager.HostOS() == "windows", "temporarily disabled on WCOW due to CI flakiness")
})

it("creates image on the registry", func() {
buildArgs := []string{
repoName,
"-p", filepath.Join("testdata", "mock_app"),
"--publish",
"--verbose",
"--network", network,
"--mac-address", randomMacAddress,
}

output := pack.RunSuccessfully("build", buildArgs...)
outputAssertionManager := assertions.NewOutputAssertionManager(t, output)
outputAssertionManager.ReportsSuccessfulImageBuild(repoName)
outputAssertionManager.ReportMacAddress(network, randomMacAddress)
})
})
})

when("build --buildpack <flattened buildpack>", func() {
Expand Down
5 changes: 5 additions & 0 deletions acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ func (o OutputAssertionManager) ReportsInvalidBuilderToml() {

o.assert.Contains(o.output, "invalid builder toml")
}

func (o OutputAssertionManager) ReportMacAddress(host, address string) {
o.testObject.Helper()
o.assert.Contains(o.output, fmt.Sprintf("Network Mode: '%s', MAC Address '%s'", host, address))
}
4 changes: 4 additions & 0 deletions acceptance/invoke/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const (
MetaBuildpackFolder
PlatformRetries
FlattenBuilderCreationV2
MacAddressFlag
)

var featureTests = map[Feature]func(i *PackInvoker) bool{
Expand Down Expand Up @@ -270,6 +271,9 @@ var featureTests = map[Feature]func(i *PackInvoker) bool{
FlattenBuilderCreationV2: func(i *PackInvoker) bool {
return i.atLeast("v0.33.1")
},
MacAddressFlag: func(i *PackInvoker) bool {
return i.atLeast("v0.34.0")
},
}

func (i *PackInvoker) SupportsFeature(f Feature) bool {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (

func BenchmarkBuild(b *testing.B) {
setEnv()
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithVersion("1.38"))
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithVersion("1.41"))
if err != nil {
b.Error(errors.Wrap(err, "creating docker client"))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/build/container_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestContainerOperations(t *testing.T) {
h.RequireDocker(t)

var err error
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)

spec.Run(t, "container-ops", testContainerOps, spec.Report(report.Terminal{}), spec.Sequential())
Expand Down
4 changes: 2 additions & 2 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
fakeBuilder, err = fakes.NewFakeBuilder(fakes.WithSupportedPlatformAPIs([]*api.Version{api.MustParse("0.3")}))
h.AssertNil(t, err)
logger = logging.NewLogWithWriters(&outBuf, &outBuf)
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
fakePhaseFactory = fakes.NewFakePhaseFactory()
})
Expand Down Expand Up @@ -2583,7 +2583,7 @@ func (f *fakeImageFetcher) fetchRunImage(name string) error {
}

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

var outBuf bytes.Buffer
Expand Down
4 changes: 3 additions & 1 deletion internal/build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

dcontainer "github.com/docker/docker/api/types/container"
dnetwork "github.com/docker/docker/api/types/network"
"github.com/pkg/errors"

"github.com/buildpacks/pack/internal/container"
Expand All @@ -18,6 +19,7 @@ type Phase struct {
handler container.Handler
ctrConf *dcontainer.Config
hostConf *dcontainer.HostConfig
netConf *dnetwork.NetworkingConfig
ctr dcontainer.CreateResponse
uid, gid int
appPath string
Expand All @@ -28,7 +30,7 @@ type Phase struct {

func (p *Phase) Run(ctx context.Context) error {
var err error
p.ctr, err = p.docker.ContainerCreate(ctx, p.ctrConf, p.hostConf, nil, nil, "")
p.ctr, err = p.docker.ContainerCreate(ctx, p.ctrConf, p.hostConf, p.netConf, nil, "")
if err != nil {
return errors.Wrapf(err, "failed to create '%s' container", p.name)
}
Expand Down
39 changes: 31 additions & 8 deletions internal/build/phase_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"

pcontainer "github.com/buildpacks/pack/internal/container"
"github.com/buildpacks/pack/internal/style"
Expand All @@ -24,6 +25,7 @@ type PhaseConfigProviderOperation func(*PhaseConfigProvider)
type PhaseConfigProvider struct {
ctrConf *container.Config
hostConf *container.HostConfig
netConfig *network.NetworkingConfig
name string
os string
containerOps []ContainerOperation
Expand All @@ -37,6 +39,7 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops
provider := &PhaseConfigProvider{
ctrConf: new(container.Config),
hostConf: new(container.HostConfig),
netConfig: new(network.NetworkingConfig),
name: name,
os: lifecycleExec.os,
infoWriter: logging.GetWriterForLevel(lifecycleExec.logger, logging.InfoLevel),
Expand All @@ -46,13 +49,6 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops
provider.ctrConf.Image = lifecycleExec.opts.Builder.Name()
provider.ctrConf.Labels = map[string]string{"author": "pack"}

if lifecycleExec.opts.MacAddress != "" {
// TODO fix this
//nolint:staticcheck
provider.ctrConf.MacAddress = lifecycleExec.opts.MacAddress
lifecycleExec.logger.Debugf("MAC Address: %s", style.Symbol(lifecycleExec.opts.MacAddress))
}

if lifecycleExec.os == "windows" {
provider.hostConf.Isolation = container.IsolationProcess
}
Expand All @@ -70,6 +66,23 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops
op(provider)
}

if lifecycleExec.opts.MacAddress != "" {
if provider.hostConf.NetworkMode == "" {
provider.hostConf.NetworkMode = network.NetworkDefault
}
if provider.netConfig.EndpointsConfig == nil {
provider.netConfig.EndpointsConfig = make(map[string]*network.EndpointSettings)
}
netName := provider.hostConf.NetworkMode.NetworkName()
if _, ok := provider.netConfig.EndpointsConfig[netName]; ok {
provider.netConfig.EndpointsConfig[netName].MacAddress = lifecycleExec.opts.MacAddress
} else {
provider.netConfig.EndpointsConfig[netName] = &network.EndpointSettings{
MacAddress: lifecycleExec.opts.MacAddress,
}
}
}

provider.ctrConf.Entrypoint = []string{""} // override entrypoint in case it is set
provider.ctrConf.Cmd = append([]string{"/cnb/lifecycle/" + name}, provider.ctrConf.Cmd...)

Expand All @@ -83,7 +96,13 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops

lifecycleExec.logger.Debug("Host Settings:")
lifecycleExec.logger.Debugf(" Binds: %s", style.Symbol(strings.Join(provider.hostConf.Binds, " ")))
lifecycleExec.logger.Debugf(" Network Mode: %s", style.Symbol(string(provider.hostConf.NetworkMode)))
if provider.netConfig.EndpointsConfig != nil {
if v, ok := provider.netConfig.EndpointsConfig[provider.hostConf.NetworkMode.NetworkName()]; ok {
lifecycleExec.logger.Debugf(" Network Mode: %s, MAC Address %s", style.Symbol(string(provider.hostConf.NetworkMode)), style.Symbol(v.MacAddress))
}
} else {
lifecycleExec.logger.Debugf(" Network Mode: %s", style.Symbol(string(provider.hostConf.NetworkMode)))
}

if lifecycleExec.opts.Interactive {
provider.handler = lifecycleExec.opts.Termui.Handler()
Expand All @@ -108,6 +127,10 @@ func (p *PhaseConfigProvider) ContainerConfig() *container.Config {
return p.ctrConf
}

func (p *PhaseConfigProvider) NetworkConfig() *network.NetworkingConfig {
return p.netConfig
}

func (p *PhaseConfigProvider) ContainerOps() []ContainerOperation {
return p.containerOps
}
Expand Down
8 changes: 3 additions & 5 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {

phaseConfigProvider := build.NewPhaseConfigProvider("some-name", lifecycle)

// TODO fix this
//nolint:staticcheck
h.AssertEq(t, phaseConfigProvider.ContainerConfig().MacAddress, expectedMacAddress)
h.AssertEq(t, phaseConfigProvider.NetworkConfig().EndpointsConfig[phaseConfigProvider.HostConfig().NetworkMode.NetworkName()].MacAddress, expectedMacAddress)
})
})

Expand Down Expand Up @@ -309,7 +307,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
var outBuf bytes.Buffer
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())

docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)

defaultBuilder, err := fakes.NewFakeBuilder()
Expand Down Expand Up @@ -346,7 +344,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
var outBuf bytes.Buffer
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())

docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)

defaultBuilder, err := fakes.NewFakeBuilder()
Expand Down
1 change: 1 addition & 0 deletions internal/build/phase_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (m *DefaultPhaseFactory) New(provider *PhaseConfigProvider) RunnerCleaner {
return &Phase{
ctrConf: provider.ContainerConfig(),
hostConf: provider.HostConfig(),
netConf: provider.NetworkConfig(),
name: provider.Name(),
docker: m.lifecycleExec.docker,
infoWriter: provider.InfoWriter(),
Expand Down
4 changes: 2 additions & 2 deletions internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestPhase(t *testing.T) {
h.RequireDocker(t)

var err error
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
ctrClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)

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

var err error
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)

info, err := ctrClient.Info(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion internal/build/testdata/fake-lifecycle/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func testWrite(filename, contents string) {

func testDaemon() {
fmt.Println("daemon test")
cli, err := dockercli.NewClientWithOpts(dockercli.FromEnv, dockercli.WithVersion("1.38"))
cli, err := dockercli.NewClientWithOpts(dockercli.FromEnv, dockercli.WithVersion("1.41"))
if err != nil {
fmt.Printf("failed to create new docker client: %s\n", err)
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions pkg/cache/image_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
})

Expand Down Expand Up @@ -81,7 +81,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
})

Expand All @@ -104,7 +104,7 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
ctx = context.TODO()

Expand Down
4 changes: 2 additions & 2 deletions pkg/cache/volume_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
})
when("#NewVolumeCache", func() {
Expand Down Expand Up @@ -210,7 +210,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
ctx = context.TODO()

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
fakeLifecycleImage = newLinuxImage(fmt.Sprintf("%s:%s", cfg.DefaultLifecycleImageRepo, builder.DefaultLifecycleVersion), "", nil)
fakeImageFetcher.LocalImages[fakeLifecycleImage.Name()] = fakeLifecycleImage

docker, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithVersion("1.38"))
docker, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv, dockerclient.WithVersion("1.41"))
h.AssertNil(t, err)

logger = logging.NewLogWithWriters(&outBuf, &outBuf)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func WithKeychain(keychain authn.Keychain) Option {
}
}

const DockerAPIVersion = "1.38"
const DockerAPIVersion = "1.41"

// NewClient allocates and returns a Client configured with the specified options.
func NewClient(opts ...Option) (*Client, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFetcher(t *testing.T) {
os.Setenv("DOCKER_CONFIG", registryConfig.DockerConfigDir)

var err error
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
docker, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
h.AssertNil(t, err)
spec.Run(t, "Fetcher", testFetcher, spec.Report(report.Terminal{}))
}
Expand Down
2 changes: 1 addition & 1 deletion testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ var dockerCliErr error

func dockerCli(t *testing.T) client.CommonAPIClient {
dockerCliOnce.Do(func() {
dockerCliVal, dockerCliErr = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
dockerCliVal, dockerCliErr = client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.41"))
})
AssertNil(t, dockerCliErr)
return dockerCliVal
Expand Down
Loading