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

Commit 9a5464d

Browse files
author
Nathan Potter
authored
Merge pull request #42 from codercom/mount-hat
Mount hat
2 parents 6a593c1 + b53146c commit 9a5464d

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
@@ -62,16 +62,6 @@ func (r *runner) runContainer(image string) error {
6262
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
6363
defer cancel()
6464

65-
var (
66-
err error
67-
mounts []mount.Mount
68-
)
69-
70-
mounts, err = r.mounts(mounts, image)
71-
if err != nil {
72-
return xerrors.Errorf("failed to assemble mounts: %w", err)
73-
}
74-
7565
projectDir, err := r.projectDir(image)
7666
if err != nil {
7767
return err
@@ -116,6 +106,14 @@ func (r *runner) runContainer(image string) error {
116106
return xerrors.Errorf("failed to add image defined labels: %w", err)
117107
}
118108

109+
var mounts []mount.Mount
110+
mounts = r.addHatMount(mounts, containerConfig.Labels)
111+
112+
mounts, err = r.mounts(mounts, image)
113+
if err != nil {
114+
return xerrors.Errorf("failed to assemble mounts: %w", err)
115+
}
116+
119117
hostConfig := &container.HostConfig{
120118
Mounts: mounts,
121119
NetworkMode: "host",
@@ -138,6 +136,20 @@ func (r *runner) runContainer(image string) error {
138136
return nil
139137
}
140138

139+
// addHatMount mounts the hat into the user's container if they've specified one.
140+
func (r *runner) addHatMount(mounts []mount.Mount, labels map[string]string) []mount.Mount {
141+
hatPath, ok := labels[hatLabel]
142+
if !ok {
143+
return mounts
144+
}
145+
146+
return append(mounts, mount.Mount{
147+
Type: "bind",
148+
Source: hatPath,
149+
Target: "~/.hat",
150+
})
151+
}
152+
141153
func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, error) {
142154
// Mount in VS Code configs.
143155
mounts = append(mounts, mount.Mount{

0 commit comments

Comments
 (0)