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

Commit cd18c5f

Browse files
author
Nathan Potter
authored
Merge pull request #40 from codercom/check-volume
Autocreate mount source if it doesn't exist
2 parents 620f1e0 + 268733f commit cd18c5f

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
@@ -85,7 +85,6 @@ func (r *runner) runContainer(image string) error {
8585
"; code-server --host 127.0.0.1" +
8686
" --port " + r.port +
8787
" --data-dir ~/.config/Code --extensions-dir ~/.vscode/extensions --allow-http --no-auth 2>&1 | tee " + containerLogPath
88-
8988
if r.testCmd != "" {
9089
cmd = r.testCmd + "; exit 1"
9190
}
@@ -189,9 +188,36 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
189188
}
190189

191190
r.resolveMounts(mounts)
191+
192+
err = r.ensureMountSources(mounts)
193+
if err != nil {
194+
return nil, err
195+
}
196+
192197
return mounts, nil
193198
}
194199

200+
// ensureMountSources ensures that the mount's source exists. If the source
201+
// doesn't exist, it will be created as a directory on the host.
202+
func (r *runner) ensureMountSources(mounts []mount.Mount) error {
203+
for _, mount := range mounts {
204+
_, err := os.Stat(mount.Source)
205+
if err == nil {
206+
continue
207+
}
208+
if !os.IsNotExist(err) {
209+
return xerrors.Errorf("failed to stat mount source %v: %w", mount.Source, err)
210+
}
211+
212+
err = os.MkdirAll(mount.Source, 0755)
213+
if err != nil {
214+
return xerrors.Errorf("failed to create mount source %v: %w", mount.Source, err)
215+
}
216+
}
217+
218+
return nil
219+
}
220+
195221
// imageDefinedMounts adds a list of shares to the shares map from the image.
196222
func (r *runner) imageDefinedMounts(image string, mounts []mount.Mount) ([]mount.Mount, error) {
197223
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)