From cc2a3a645fab2cca8726afd030923f410fd44737 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Tue, 9 May 2017 13:06:04 +0100 Subject: [PATCH] Add support for symlinks in files section Signed-off-by: Justin Cormack --- cmd/moby/config.go | 14 +++++++++++++- cmd/moby/schema.go | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/moby/config.go b/cmd/moby/config.go index 90b807aa8..4d34613dd 100644 --- a/cmd/moby/config.go +++ b/cmd/moby/config.go @@ -32,6 +32,7 @@ type Moby struct { Files []struct { Path string Directory bool + Symlink string Contents string } Outputs []struct { @@ -438,7 +439,7 @@ func filesystem(m *Moby) (*bytes.Buffer, error) { if f.Path == "" { return buf, errors.New("Did not specify path for file") } - if !f.Directory && f.Contents == "" { + if !f.Directory && f.Contents == "" && f.Symlink == "" { return buf, errors.New("Contents of file not specified") } // we need all the leading directories @@ -477,6 +478,17 @@ func filesystem(m *Moby) (*bytes.Buffer, error) { if err != nil { return buf, err } + } else if f.Symlink != "" { + hdr := &tar.Header{ + Name: f.Path, + Typeflag: tar.TypeSymlink, + Mode: 0600, + Linkname: f.Symlink, + } + err := tw.WriteHeader(hdr) + if err != nil { + return buf, err + } } else { hdr := &tar.Header{ Name: f.Path, diff --git a/cmd/moby/schema.go b/cmd/moby/schema.go index 379c480aa..e36354892 100644 --- a/cmd/moby/schema.go +++ b/cmd/moby/schema.go @@ -20,6 +20,7 @@ var schema = string(` "properties": { "path": {"type": "string"}, "directory": {"type": "boolean"}, + "symlink": {"type": "string"}, "contents": {"type": "string"} } },