Skip to content

Commit

Permalink
Fix bind mount using relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Dec 14, 2020
1 parent 4bf6f86 commit e3111ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion env/mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package env
import (
"fmt"
"io/ioutil"
"os"
"path"

"github.com/criyle/go-sandbox/pkg/mount"
Expand Down Expand Up @@ -44,14 +45,22 @@ func readMountConfig(p string) (*Mounts, error) {

func parseMountConfig(m *Mounts) (*mount.Builder, error) {
b := mount.NewBuilder()
wd, err := os.Getwd()
if err != nil {
return nil, err
}
for _, mt := range m.Mount {
target := mt.Target
if path.IsAbs(target) {
target = path.Clean(target[1:])
}
source := mt.Source
if !path.IsAbs(source) {
source = path.Join(wd, source)
}
switch mt.Type {
case "bind":
b.WithBind(mt.Source, target, mt.Readonly)
b.WithBind(source, target, mt.Readonly)
case "tmpfs":
b.WithTmpfs(target, mt.Data)
default:
Expand Down
8 changes: 4 additions & 4 deletions mount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ mount:
- type: tmpfs
target: /tmp
data: size=16m,nr_inodes=4k
# bind a /etc/passed to show customized user name
# - type: bind
# source: /home/criyle/go-judge/containerPasswd.txt
# target: /etc/passwd
# (optional) bind a /etc/passed to show customized user name
- type: bind
source: containerPasswd.txt
target: /etc/passwd
# java & ghc wants /proc/self/exe
proc: true
# container work directory
Expand Down

0 comments on commit e3111ee

Please sign in to comment.