mirror of
https://github.com/docker/compose.git
synced 2025-07-29 08:34:15 +02:00
add a test with multiple service builds using platforms in the same compose file
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
537f023a3b
commit
8ed2d8ad07
@ -56,10 +56,7 @@ func (s *composeService) doBuildBuildkit(ctx context.Context, opts map[string]bu
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
w := xprogress.NewPrinter(progressCtx, s.stdout(), os.Stdout, mode)
|
w := xprogress.NewPrinter(progressCtx, s.stdout(), os.Stdout, mode)
|
||||||
|
|
||||||
// Get the DockerAPI if a "docker" export is defined (ie: up and run command), otherwise get nil and let use the default buildx builder
|
response, err := build.Build(ctx, dis, opts, &internalAPI{dockerCli: s.dockerCli}, filepath.Dir(s.configFile().Filename), w)
|
||||||
API := getDockerAPI(s.dockerCli, opts)
|
|
||||||
|
|
||||||
response, err := build.Build(ctx, dis, opts, API, filepath.Dir(s.configFile().Filename), w)
|
|
||||||
errW := w.Wait()
|
errW := w.Wait()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = errW
|
err = errW
|
||||||
@ -265,18 +262,3 @@ func (a *internalAPI) DockerAPI(name string) (dockerclient.APIClient, error) {
|
|||||||
}
|
}
|
||||||
return clientForEndpoint(a.dockerCli, name)
|
return clientForEndpoint(a.dockerCli, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dockerAPI(dockerCli command.Cli) *internalAPI {
|
|
||||||
return &internalAPI{dockerCli: dockerCli}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getDockerAPI(cli command.Cli, opts map[string]build.Options) *internalAPI {
|
|
||||||
for _, opt := range opts {
|
|
||||||
for _, export := range opt.Exports {
|
|
||||||
if export.Type == "docker" {
|
|
||||||
return dockerAPI(cli)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -281,6 +281,22 @@ func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("multi-arch multi service builds ok", func(t *testing.T) {
|
||||||
|
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms",
|
||||||
|
"-f", "fixtures/build-test/platforms/compose-multiple-platform-builds.yaml", "build")
|
||||||
|
assert.NilError(t, res.Error, res.Stderr())
|
||||||
|
res = c.RunDockerCmd(t, "manifest", "inspect", "--insecure", "localhost:5001/build-test-platform-a:test")
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "amd64",`})
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "arm64",`})
|
||||||
|
res = c.RunDockerCmd(t, "manifest", "inspect", "--insecure", "localhost:5001/build-test-platform-b:test")
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "amd64",`})
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "arm64",`})
|
||||||
|
res = c.RunDockerCmd(t, "manifest", "inspect", "--insecure", "localhost:5001/build-test-platform-c:test")
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "amd64",`})
|
||||||
|
res.Assert(t, icmd.Expected{Out: `"architecture": "arm64",`})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("multi-arch up --build", func(t *testing.T) {
|
t.Run("multi-arch up --build", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "up", "--build")
|
res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test/platforms", "up", "--build")
|
||||||
assert.NilError(t, res.Error, res.Stderr())
|
assert.NilError(t, res.Error, res.Stderr())
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
services:
|
||||||
|
serviceA:
|
||||||
|
image: localhost:5001/build-test-platform-a:test
|
||||||
|
build:
|
||||||
|
context: ./contextServiceA
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
serviceB:
|
||||||
|
image: localhost:5001/build-test-platform-b:test
|
||||||
|
build:
|
||||||
|
context: ./contextServiceB
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
serviceC:
|
||||||
|
image: localhost:5001/build-test-platform-c:test
|
||||||
|
build:
|
||||||
|
context: ./contextServiceC
|
||||||
|
platforms:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
|
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2020 Docker Compose CLI authors
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:alpine AS build
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
RUN echo "I'm Service A and I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
COPY --from=build /log /log
|
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2020 Docker Compose CLI authors
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:alpine AS build
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
RUN echo "I'm Service B and I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
COPY --from=build /log /log
|
@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2020 Docker Compose CLI authors
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
FROM --platform=$BUILDPLATFORM golang:alpine AS build
|
||||||
|
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
RUN echo "I'm Service C and I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" > /log
|
||||||
|
|
||||||
|
FROM alpine
|
||||||
|
COPY --from=build /log /log
|
Loading…
x
Reference in New Issue
Block a user