use `opts.MemBytes` for tmpfs size run mount instruction
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>master
parent
954c4721f7
commit
94378a87b4
|
@ -25,6 +25,7 @@ var mountTests = []integration.Test{
|
|||
testMountMetaArg,
|
||||
testMountFromError,
|
||||
testMountInvalid,
|
||||
testMountTmpfsSize,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -452,3 +453,46 @@ RUN --mount=from=$ttt,type=cache,target=/tmp ls
|
|||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "'from' doesn't support variable expansion, define alias stage instead")
|
||||
}
|
||||
|
||||
func testMountTmpfsSize(t *testing.T, sb integration.Sandbox) {
|
||||
f := getFrontend(t, sb)
|
||||
|
||||
dockerfile := []byte(`
|
||||
FROM busybox AS base
|
||||
RUN --mount=type=tmpfs,target=/dev/shm,size=128m mount | grep /dev/shm > /tmpfssize
|
||||
FROM scratch
|
||||
COPY --from=base /tmpfssize /
|
||||
`)
|
||||
|
||||
dir, err := tmpdir(
|
||||
fstest.CreateFile("Dockerfile", dockerfile, 0600),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
c, err := client.New(sb.Context(), sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
destDir, err := ioutil.TempDir("", "buildkit")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(destDir)
|
||||
|
||||
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
|
||||
Exports: []client.ExportEntry{
|
||||
{
|
||||
Type: client.ExporterLocal,
|
||||
OutputDir: destDir,
|
||||
},
|
||||
},
|
||||
LocalDirs: map[string]string{
|
||||
builder.DefaultLocalNameDockerfile: dir,
|
||||
builder.DefaultLocalNameContext: dir,
|
||||
},
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
dt, err := ioutil.ReadFile(filepath.Join(destDir, "tmpfssize"))
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, string(dt), `size=131072k`)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
dockeropts "github.com/docker/docker/opts"
|
||||
"github.com/moby/buildkit/util/suggest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -230,11 +231,11 @@ func parseMount(value string, expander SingleWordExpander) (*Mount, error) {
|
|||
}
|
||||
case "size":
|
||||
if m.Type == "tmpfs" {
|
||||
v, err := strconv.ParseInt(value, 10, 64)
|
||||
if err != nil {
|
||||
tmpfsSize := new(dockeropts.MemBytes)
|
||||
if err := tmpfsSize.Set(value); err != nil {
|
||||
return nil, errors.Errorf("invalid value for %s: %s", key, value)
|
||||
}
|
||||
m.SizeLimit = v
|
||||
m.SizeLimit = tmpfsSize.Value()
|
||||
} else {
|
||||
return nil, errors.Errorf("unexpected key '%s' for mount type '%s'", key, m.Type)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue