Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit e4aef86

Browse files
Nathan Potternhooyr
Nathan Potter
authored andcommitted
Mount hat to user's home directory if one is specified
1 parent a49ed8e commit e4aef86

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

runner.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ func (r *runner) runContainer(image string) error {
6565
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
6666
defer cancel()
6767

68-
var (
69-
err error
70-
mounts []mount.Mount
71-
)
72-
73-
mounts, err = r.mounts(mounts, image)
74-
if err != nil {
75-
return xerrors.Errorf("failed to assemble mounts: %w", err)
76-
}
77-
7868
projectDir, err := r.projectDir(image)
7969
if err != nil {
8070
return err
@@ -122,6 +112,14 @@ func (r *runner) runContainer(image string) error {
122112
return xerrors.Errorf("failed to add image defined labels: %w", err)
123113
}
124114

115+
var mounts []mount.Mount
116+
mounts = r.addHatMount(mounts, containerConfig.Labels)
117+
118+
mounts, err = r.mounts(mounts, image)
119+
if err != nil {
120+
return xerrors.Errorf("failed to assemble mounts: %w", err)
121+
}
122+
125123
hostConfig := &container.HostConfig{
126124
Mounts: mounts,
127125
NetworkMode: "host",
@@ -154,6 +152,20 @@ func (r *runner) runContainer(image string) error {
154152
return nil
155153
}
156154

155+
// addHatMount mounts the hat into the user's container if they've specified one.
156+
func (r *runner) addHatMount(mounts []mount.Mount, labels map[string]string) []mount.Mount {
157+
hatPath, ok := labels[hatLabel]
158+
if !ok {
159+
return mounts
160+
}
161+
162+
return append(mounts, mount.Mount{
163+
Type: "bind",
164+
Source: hatPath,
165+
Target: "~/.hat",
166+
})
167+
}
168+
157169
func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, error) {
158170
// Mount in VS Code configs.
159171
mounts = append(mounts, mount.Mount{

0 commit comments

Comments
 (0)