Skip to content

Commit a429c09

Browse files
ndeloofglours
authored andcommitted
fix support for build with bake when target docker endpoint requires TLS
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent df3c27c commit a429c09

File tree

5 files changed

+58
-125
lines changed

5 files changed

+58
-125
lines changed

MAINTAINERS

Lines changed: 0 additions & 124 deletions
This file was deleted.

pkg/compose/shellout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (s *composeService) propagateDockerEndpoint() ([]string, func(), error) {
6565
_ = os.RemoveAll(certs)
6666
}
6767
env[client.EnvOverrideCertPath] = certs
68+
env["DOCKER_TLS"] = "1"
6869
if !endpoint.SkipTLSVerify {
6970
env[client.EnvTLSVerify] = "1"
7071
}
@@ -73,7 +74,7 @@ func (s *composeService) propagateDockerEndpoint() ([]string, func(), error) {
7374
if err != nil {
7475
return nil, cleanup, err
7576
}
76-
err = os.WriteFile(filepath.Join(certs, flags.DefaultCaFile), endpoint.TLSData.Cert, 0o600)
77+
err = os.WriteFile(filepath.Join(certs, flags.DefaultCertFile), endpoint.TLSData.Cert, 0o600)
7778
if err != nil {
7879
return nil, cleanup, err
7980
}

pkg/e2e/build_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"fmt"
2121
"net/http"
22+
"os"
2223
"regexp"
2324
"runtime"
2425
"strconv"
@@ -29,6 +30,7 @@ import (
2930
"github.com/stretchr/testify/require"
3031
"gotest.tools/v3/assert"
3132
"gotest.tools/v3/icmd"
33+
"gotest.tools/v3/poll"
3234
)
3335

3436
func TestLocalComposeBuild(t *testing.T) {
@@ -608,3 +610,38 @@ func TestBuildDependentImageWithProfile(t *testing.T) {
608610
out := res.Combined()
609611
assert.Check(t, strings.Contains(out, "secret-build-test Built"))
610612
}
613+
614+
func TestBuildTLS(t *testing.T) {
615+
t.Helper()
616+
617+
c := NewParallelCLI(t)
618+
const dindBuilder = "e2e-dind-builder"
619+
tmp := t.TempDir()
620+
621+
t.Cleanup(func() {
622+
c.RunDockerCmd(t, "rm", "-f", dindBuilder)
623+
c.RunDockerCmd(t, "context", "rm", dindBuilder)
624+
})
625+
626+
c.RunDockerCmd(t, "run", "--name", dindBuilder, "--privileged", "-p", "2376:2376", "-d", "docker:dind")
627+
628+
poll.WaitOn(t, func(_ poll.LogT) poll.Result {
629+
res := c.RunDockerCmd(t, "logs", dindBuilder)
630+
if strings.Contains(res.Combined(), "API listen on [::]:2376") {
631+
return poll.Success()
632+
}
633+
return poll.Continue("waiting for Docker daemon to be running")
634+
}, poll.WithTimeout(10*time.Second))
635+
636+
time.Sleep(1 * time.Second) // wait for dind setup
637+
c.RunDockerCmd(t, "cp", dindBuilder+":/certs/client", tmp)
638+
639+
c.RunDockerCmd(t, "context", "create", dindBuilder, "--docker",
640+
fmt.Sprintf("host=tcp://localhost:2376,ca=%s/client/ca.pem,cert=%s/client/cert.pem,key=%s/client/key.pem,skip-tls-verify=1", tmp, tmp, tmp))
641+
642+
cmd := c.NewDockerComposeCmd(t, "-f", "fixtures/build-test/minimal/compose.yaml", "build")
643+
cmd.Env = append(cmd.Env, "DOCKER_CONTEXT="+dindBuilder)
644+
cmd.Stdout = os.Stdout
645+
res := icmd.RunCmd(cmd)
646+
res.Assert(t, icmd.Expected{Err: "Built"})
647+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM scratch
16+
COPY . .
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
test:
3+
build: .

0 commit comments

Comments
 (0)