dockerfile: enable tmpfs mounts on run —mount
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
596b03a8a0
commit
6f569455d0
|
@ -16,11 +16,11 @@ func detectRunMount(cmd *command, dispatchStatesByName map[string]*dispatchState
|
|||
mounts := instructions.GetMounts(c)
|
||||
sources := make([]*dispatchState, len(mounts))
|
||||
for i, mount := range mounts {
|
||||
if mount.From == "" && mount.Type == "cache" {
|
||||
if mount.From == "" && mount.Type == instructions.MountTypeCache {
|
||||
mount.From = emptyImageName
|
||||
}
|
||||
from := mount.From
|
||||
if from == "" {
|
||||
if from == "" || mount.Type == instructions.MountTypeTmpfs {
|
||||
continue
|
||||
}
|
||||
stn, ok := dispatchStatesByName[strings.ToLower(from)]
|
||||
|
@ -45,7 +45,7 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []*
|
|||
mounts := instructions.GetMounts(c)
|
||||
|
||||
for i, mount := range mounts {
|
||||
if mount.From == "" && mount.Type == "cache" {
|
||||
if mount.From == "" && mount.Type == instructions.MountTypeCache {
|
||||
mount.From = emptyImageName
|
||||
}
|
||||
st := opt.buildContext
|
||||
|
@ -53,10 +53,14 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []*
|
|||
st = sources[i].state
|
||||
}
|
||||
var mountOpts []llb.MountOption
|
||||
if mount.Type == instructions.MountTypeTmpfs {
|
||||
st = llb.Scratch()
|
||||
mountOpts = append(mountOpts, llb.Tmpfs())
|
||||
}
|
||||
if mount.ReadOnly {
|
||||
mountOpts = append(mountOpts, llb.Readonly)
|
||||
}
|
||||
if mount.Type == "cache" {
|
||||
if mount.Type == instructions.MountTypeCache {
|
||||
mountOpts = append(mountOpts, llb.AsPersistentCacheDir(opt.cacheIDNamespace+"/"+mount.CacheID))
|
||||
}
|
||||
if src := path.Join("/", mount.Source); src != "/" {
|
||||
|
|
|
@ -10,6 +10,16 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const MountTypeBind = "bind"
|
||||
const MountTypeCache = "cache"
|
||||
const MountTypeTmpfs = "tmpfs"
|
||||
|
||||
var allowedMountTypes = map[string]struct{}{
|
||||
MountTypeBind: {},
|
||||
MountTypeCache: {},
|
||||
MountTypeTmpfs: {},
|
||||
}
|
||||
|
||||
type mountsKeyT string
|
||||
|
||||
var mountsKey = mountsKeyT("dockerfile/run/mounts")
|
||||
|
@ -19,6 +29,11 @@ func init() {
|
|||
parseRunPostHooks = append(parseRunPostHooks, runMountPostHook)
|
||||
}
|
||||
|
||||
func isValidMountType(s string) bool {
|
||||
_, ok := allowedMountTypes[s]
|
||||
return ok
|
||||
}
|
||||
|
||||
func runMountPreHook(cmd *RunCommand, req parseRequest) error {
|
||||
st := &mountState{}
|
||||
st.flag = req.flags.AddStrings("mount")
|
||||
|
@ -76,7 +91,7 @@ func parseMount(value string) (*Mount, error) {
|
|||
return nil, errors.Wrap(err, "failed to parse csv mounts")
|
||||
}
|
||||
|
||||
m := &Mount{Type: "bind"}
|
||||
m := &Mount{Type: MountTypeBind}
|
||||
|
||||
roAuto := true
|
||||
|
||||
|
@ -104,11 +119,7 @@ func parseMount(value string) (*Mount, error) {
|
|||
value := parts[1]
|
||||
switch key {
|
||||
case "type":
|
||||
allowedTypes := map[string]struct{}{
|
||||
"cache": {},
|
||||
"bind": {},
|
||||
}
|
||||
if _, ok := allowedTypes[strings.ToLower(value)]; !ok {
|
||||
if !isValidMountType(strings.ToLower(value)) {
|
||||
return nil, errors.Errorf("invalid mount type %q", value)
|
||||
}
|
||||
m.Type = strings.ToLower(value)
|
||||
|
@ -139,7 +150,7 @@ func parseMount(value string) (*Mount, error) {
|
|||
}
|
||||
|
||||
if roAuto {
|
||||
if m.Type == "cache" {
|
||||
if m.Type == MountTypeCache {
|
||||
m.ReadOnly = false
|
||||
} else {
|
||||
m.ReadOnly = true
|
||||
|
|
|
@ -401,7 +401,7 @@ func (m *tmpfsMount) Mount() ([]mount.Mount, error) {
|
|||
}
|
||||
return []mount.Mount{{
|
||||
Type: "tmpfs",
|
||||
Source: "none",
|
||||
Source: "tmpfs",
|
||||
Options: opt,
|
||||
}}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue