Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 025e1bd

Browse files
committed
Adds working bind mount
1 parent 2932fe9 commit 025e1bd

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
ci/bin
33
cmd/coder/coder
4+
ci/integration/bin

ci/integration/integration_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ package integration
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
57
"os/exec"
8+
"path/filepath"
69
"strings"
710
"testing"
811
"time"
@@ -11,12 +14,33 @@ import (
1114
"cdr.dev/slog/sloggers/slogtest/assert"
1215
)
1316

17+
func build(t *testing.T, path string) {
18+
cmd := exec.Command(
19+
"sh", "-c",
20+
fmt.Sprintf("cd ../../ && go build -o %s ./cmd/coder", path),
21+
)
22+
cmd.Env = append(os.Environ(), "GOOS=linux", "CGO_ENABLED=0")
23+
24+
out, err := cmd.CombinedOutput()
25+
t.Logf("%s", string(out))
26+
assert.Success(t, "build go binary", err)
27+
}
28+
1429
func TestTCli(t *testing.T) {
1530
ctx := context.Background()
1631

32+
cwd, err := os.Getwd()
33+
assert.Success(t, "get working dir", err)
34+
35+
binpath := filepath.Join(cwd, "bin", "coder")
36+
build(t, binpath)
37+
1738
container, err := tcli.NewRunContainer(ctx, &tcli.ContainerConfig{
1839
Image: "ubuntu:latest",
1940
Name: "test-container",
41+
BindMounts: map[string]string{
42+
binpath: "/bin/coder",
43+
},
2044
})
2145

2246
assert.Success(t, "new run container", err)
@@ -43,4 +67,10 @@ func TestTCli(t *testing.T) {
4367
tcli.StderrEmpty(),
4468
tcli.StdoutMatches("testing"),
4569
)
70+
71+
container.Run(ctx, "which coder").Assert(t,
72+
tcli.Success(),
73+
tcli.StdoutMatches("/bin/coder"),
74+
tcli.StderrEmpty(),
75+
)
4676
}

ci/tcli/tcli.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ type RunContainer struct {
2020
}
2121

2222
type ContainerConfig struct {
23-
Name string
24-
Image string
25-
Mounts map[string]string
23+
Name string
24+
Image string
25+
BindMounts map[string]string
2626
}
2727

2828
func mountArgs(m map[string]string) (args []string) {
2929
for src, dest := range m {
30-
args = append(args, "--mount", fmt.Sprintf("source=%s,target=%s", src, dest))
30+
args = append(args, "--mount", fmt.Sprintf("type=bind,source=%s,target=%s", src, dest))
3131
}
3232
return args
3333
}
@@ -50,7 +50,7 @@ func NewRunContainer(ctx context.Context, config *ContainerConfig) (*RunContaine
5050
"--name", config.Name,
5151
"-it", "-d",
5252
}
53-
args = append(args, mountArgs(config.Mounts)...)
53+
args = append(args, mountArgs(config.BindMounts)...)
5454
args = append(args, config.Image)
5555

5656
cmd := exec.CommandContext(ctx, "docker", args...)

0 commit comments

Comments
 (0)