4
4
"fmt"
5
5
"io"
6
6
"io/ioutil"
7
+ "os"
7
8
"path/filepath"
8
9
"strings"
9
10
@@ -69,44 +70,24 @@ func trimLeftSlash(name string) string {
69
70
}
70
71
71
72
// make mount paths
72
- // app.yaml支持三种写法.
73
- // app.yaml里可以支持mount_paths的写法, 例如
74
- // mount_paths:
75
- // - "/var/www/html"
76
- // - "/data/eggsy"
77
- // 这样的路径会被直接挂载到permdir下面去, 例如上面的路径就是
78
- // /mnt/mfs/permdirs/eggsy/data/eggsy
79
- // /mnt/mfs/permdirs/eggsy/var/www/html
80
- // 而且这些路径是可以读写的.
81
- //
82
- // 或者使用volumes, 参数格式跟docker一样, 例如
73
+ // 使用volumes, 参数格式跟docker一样, 支持 $PERMDIR $APPDIR 的展开
83
74
// volumes:
84
- // - "/data/test:/test:ro"
85
- // - "/data/testx:/testx"
86
- // 说明把宿主机的/data/test映射到容器里的/test, 只读, 同时
87
- // 把宿主机的/data/tests映射到容器里的/testx, 读写.
88
- //
89
- // 或者使用binds, 例如
90
- // binds:
91
- // "/host/path":
92
- // bind: "/container/path"
93
- // ro: true
94
- // 说明把宿主机的/host/path映射到容器里的/container/path, 并且只读
75
+ // - "$PERMDIR/foo-data:$APPDIR/foodata:rw"
95
76
func makeMountPaths (specs types.Specs , config types.Config ) ([]string , map [string ]struct {}) {
96
77
binds := []string {}
97
78
volumes := make (map [string ]struct {})
98
- permDirHost := filepath .Join (config .PermDir , specs .Appname )
99
79
100
- // mount_paths
101
- for _ , path := range specs . MountPaths {
102
- hostPath : = filepath .Join (permDirHost , path )
103
- binds = append ( binds , fmt . Sprintf ( "%s:%s:rw" , hostPath , path ) )
104
- volumes [ path ] = struct {}{}
80
+ var expandENV = func ( env string ) string {
81
+ envMap := make ( map [ string ] string )
82
+ envMap [ "PERMDIR" ] = filepath .Join (config . PermDir , specs . Appname )
83
+ envMap [ "APPDIR" ] = filepath . Join ( config . AppDir , specs . Appname )
84
+ return envMap [ env ]
105
85
}
106
86
107
87
// volumes
108
88
for _ , path := range specs .Volumes {
109
- parts := strings .Split (path , ":" )
89
+ expanded := os .Expand (path , expandENV )
90
+ parts := strings .Split (expanded , ":" )
110
91
if len (parts ) == 2 {
111
92
binds = append (binds , fmt .Sprintf ("%s:%s:ro" , parts [0 ], parts [1 ]))
112
93
volumes [parts [1 ]] = struct {}{}
@@ -116,21 +97,10 @@ func makeMountPaths(specs types.Specs, config types.Config) ([]string, map[strin
116
97
}
117
98
}
118
99
119
- // binds
120
- var mode string
121
- for hostPath , bind := range specs .Binds {
122
- if bind .ReadOnly {
123
- mode = "ro"
124
- } else {
125
- mode = "rw"
126
- }
127
- binds = append (binds , fmt .Sprintf ("%s:%s:%s" , hostPath , bind .InContainerPath , mode ))
128
- volumes [bind .InContainerPath ] = struct {}{}
129
- }
130
-
131
100
// /proc/sys
132
101
volumes ["/writable-proc/sys" ] = struct {}{}
133
102
binds = append (binds , "/proc/sys:/writable-proc/sys:rw" )
103
+ volumes ["/writable-sys/kernel/mm/transparent_hugepage" ] = struct {}{}
134
104
binds = append (binds , "/sys/kernel/mm/transparent_hugepage:/writable-sys/kernel/mm/transparent_hugepage:rw" )
135
105
return binds , volumes
136
106
}
0 commit comments