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

Commit afb1eb4

Browse files
Nathan Potternhooyr
Nathan Potter
authored andcommitted
Autocreate mount source if it doesn't exist
1 parent 874baf2 commit afb1eb4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

runner.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func (r *runner) runContainer(image string) error {
8888
"; code-server --host 127.0.0.1" +
8989
" --port " + r.port +
9090
" --data-dir ~/.config/Code --extensions-dir ~/.vscode/extensions --allow-http --no-auth 2>&1 | tee " + containerLogPath
91-
9291
if r.testCmd != "" {
9392
cmd = r.testCmd + "\n exit 1"
9493
}
@@ -205,9 +204,36 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
205204
}
206205

207206
r.resolveMounts(mounts)
207+
208+
err = r.ensureMountSources(mounts)
209+
if err != nil {
210+
return nil, err
211+
}
212+
208213
return mounts, nil
209214
}
210215

216+
// ensureMountSources ensures that the mount's source exists. If the source
217+
// doesn't exist, it will be created as a directory on the host.
218+
func (r *runner) ensureMountSources(mounts []mount.Mount) error {
219+
for _, mount := range mounts {
220+
_, err := os.Stat(mount.Source)
221+
if err == nil {
222+
continue
223+
}
224+
if !os.IsNotExist(err) {
225+
return xerrors.Errorf("failed to stat mount source %v: %w", mount.Source, err)
226+
}
227+
228+
err = os.MkdirAll(mount.Source, 0755)
229+
if err != nil {
230+
return xerrors.Errorf("failed to create mount source %v: %w", mount.Source, err)
231+
}
232+
}
233+
234+
return nil
235+
}
236+
211237
// imageDefinedMounts adds a list of shares to the shares map from the image.
212238
func (r *runner) imageDefinedMounts(image string, mounts []mount.Mount) ([]mount.Mount, error) {
213239
cli := dockerClient()

ubuntu-dev/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RUN apt-get install -y ripgrep
99
RUN apt-get install -y net-tools
1010

1111
LABEL share.ssh="~/.ssh:~/.ssh"
12-
LABEL share.gitconfig="~/.gitconfig:~/.gitconfig"
1312

1413
# Download in code-server into path. sail will typically override the binary
1514
# anyways, but it's nice to have this during the build pipepline so we can

0 commit comments

Comments
 (0)