Revert "update to use containerd seccomp package"

This reverts commit 4f8e065faf055d3f0463a92622297ca3afac07f4.
This commit is contained in:
Jess Frazelle 2018-03-22 09:15:36 -04:00
parent 09243b740c
commit 60f032f6f5
8199 changed files with 1598219 additions and 30742 deletions

View file

@ -0,0 +1,36 @@
package commands
import (
"io/ioutil"
"log"
"github.com/containerd/continuity"
"github.com/spf13/cobra"
)
var ApplyCmd = &cobra.Command{
Use: "apply <root> [<manifest>]",
Short: "Apply the manifest to the provided root",
Run: func(cmd *cobra.Command, args []string) {
root, path := args[0], args[1]
p, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
m, err := continuity.Unmarshal(p)
if err != nil {
log.Fatalf("error unmarshaling manifest: %v", err)
}
ctx, err := continuity.NewContext(root)
if err != nil {
log.Fatalf("error getting context: %v", err)
}
if err := continuity.ApplyManifest(ctx, m); err != nil {
log.Fatalf("error applying manifest: %v", err)
}
},
}

View file

@ -0,0 +1,48 @@
package commands
import (
"log"
"os"
"github.com/containerd/continuity"
"github.com/spf13/cobra"
)
var (
buildCmdConfig struct {
format string
}
BuildCmd = &cobra.Command{
Use: "build <root>",
Short: "Build a manifest for the provided root",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalln("please specify a root")
}
ctx, err := continuity.NewContext(args[0])
if err != nil {
log.Fatalf("error creating path context: %v", err)
}
m, err := continuity.BuildManifest(ctx)
if err != nil {
log.Fatalf("error generating manifest: %v", err)
}
p, err := continuity.Marshal(m)
if err != nil {
log.Fatalf("error marshaling manifest: %v", err)
}
if _, err := os.Stdout.Write(p); err != nil {
log.Fatalf("error writing to stdout: %v", err)
}
},
}
)
func init() {
BuildCmd.Flags().StringVar(&buildCmdConfig.format, "format", "pb", "specify the output format of the manifest")
}

View file

@ -0,0 +1,44 @@
package commands
import (
"io/ioutil"
"log"
"os"
pb "github.com/containerd/continuity/proto"
"github.com/golang/protobuf/proto"
"github.com/spf13/cobra"
)
var DumpCmd = &cobra.Command{
Use: "dump <manifest>",
Short: "Dump the contents of the manifest in protobuf text format",
Run: func(cmd *cobra.Command, args []string) {
var p []byte
var err error
if len(args) < 1 {
p, err = ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
} else {
p, err = ioutil.ReadFile(args[0])
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
}
var bm pb.Manifest
if err := proto.Unmarshal(p, &bm); err != nil {
log.Fatalf("error unmarshaling manifest: %v", err)
}
// TODO(stevvooe): For now, just dump the text format. Turn this into
// nice text output later.
if err := proto.MarshalText(os.Stdout, &bm); err != nil {
log.Fatalf("error dumping manifest: %v", err)
}
},
}

41
vendor/github.com/containerd/continuity/commands/ls.go generated vendored Normal file
View file

@ -0,0 +1,41 @@
package commands
import (
"fmt"
"log"
"os"
"text/tabwriter"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
)
var LSCmd = &cobra.Command{
Use: "ls <manifest>",
Short: "List the contents of the manifest.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalln("please specify a manifest")
}
bm, err := readManifestFile(args[0])
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
w := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
for _, entry := range bm.Resource {
for _, path := range entry.Path {
if os.FileMode(entry.Mode)&os.ModeSymlink != 0 {
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v -> %v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path, entry.Target)
} else {
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path)
}
}
}
w.Flush()
},
}

View file

@ -0,0 +1,82 @@
package commands
import (
"io"
"io/ioutil"
"os"
"text/tabwriter"
pb "github.com/containerd/continuity/proto"
"github.com/golang/protobuf/proto"
"github.com/spf13/cobra"
)
var (
MainCmd = &cobra.Command{
Use: "continuity <command>",
Short: "A transport-agnostic filesytem metadata tool.",
}
// usageTemplate is nearly identical to the default template without the
// automatic addition of flags. Instead, Command.Use is used unmodified.
usageTemplate = `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasSubCommands}}
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
Aliases:
{{.NameAndAliases}}
{{end}}{{if .HasExample}}
Examples:
{{ .Example }}{{end}}{{ if .HasAvailableSubCommands}}
Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}
Flags:
{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasInheritedFlags}}
Global Flags:
{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}
Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasSubCommands }}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
)
func init() {
MainCmd.AddCommand(BuildCmd)
MainCmd.AddCommand(VerifyCmd)
MainCmd.AddCommand(ApplyCmd)
MainCmd.AddCommand(LSCmd)
MainCmd.AddCommand(StatsCmd)
MainCmd.AddCommand(DumpCmd)
if MountCmd != nil {
MainCmd.AddCommand(MountCmd)
}
MainCmd.SetUsageTemplate(usageTemplate)
}
// readManifestFile reads the manifest from the given path. This should
// probably be provided by the continuity library.
func readManifestFile(path string) (*pb.Manifest, error) {
p, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
var bm pb.Manifest
if err := proto.Unmarshal(p, &bm); err != nil {
return nil, err
}
return &bm, nil
}
// newTabwriter provides a common tabwriter with defaults.
func newTabwriter(w io.Writer) *tabwriter.Writer {
return tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)
}

View file

@ -0,0 +1,115 @@
// +build linux darwin freebsd
package commands
import (
"io/ioutil"
"log"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/containerd/continuity"
"github.com/containerd/continuity/continuityfs"
"github.com/containerd/continuity/driver"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var MountCmd = &cobra.Command{
Use: "mount <mountpoint> [<manifest>] [<source directory>]",
Short: "Mount the manifest to the provided mountpoint using content from a source directory",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 3 {
log.Fatal("Must specify mountpoint, manifest, and source directory")
}
mountpoint := args[0]
manifest, source := args[1], args[2]
manifestName := filepath.Base(manifest)
p, err := ioutil.ReadFile(manifest)
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
m, err := continuity.Unmarshal(p)
if err != nil {
log.Fatalf("error unmarshaling manifest: %v", err)
}
driver, err := driver.NewSystemDriver()
if err != nil {
logrus.Fatal(err)
}
provider := continuityfs.NewFSFileContentProvider(source, driver)
contfs, err := continuityfs.NewFSFromManifest(m, mountpoint, provider)
if err != nil {
logrus.Fatal(err)
}
c, err := fuse.Mount(
mountpoint,
fuse.ReadOnly(),
fuse.FSName(manifestName),
fuse.Subtype("continuity"),
// OSX Only options
fuse.LocalVolume(),
fuse.VolumeName("Continuity FileSystem"),
)
if err != nil {
logrus.Fatal(err)
}
<-c.Ready
if err := c.MountError; err != nil {
c.Close()
logrus.Fatal(err)
}
errChan := make(chan error, 1)
go func() {
// TODO: Create server directory to use context
err = fs.Serve(c, contfs)
if err != nil {
errChan <- err
}
}()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
signal.Notify(sigChan, syscall.SIGTERM)
select {
case <-sigChan:
logrus.Infof("Shutting down")
case err = <-errChan:
}
go func() {
if err := c.Close(); err != nil {
logrus.Errorf("Unable to close connection %s", err)
}
}()
// Wait for any inprogress requests to be handled
time.Sleep(time.Second)
logrus.Infof("Attempting unmount")
if err := fuse.Unmount(mountpoint); err != nil {
logrus.Errorf("Error unmounting %s: %v", mountpoint, err)
}
// Handle server error
if err != nil {
logrus.Fatalf("Error serving fuse server: %v", err)
}
},
}

View file

@ -0,0 +1,9 @@
// +build windows solaris
package commands
import (
"github.com/spf13/cobra"
)
var MountCmd *cobra.Command = nil

View file

@ -0,0 +1,58 @@
package commands
import (
"fmt"
"log"
"os"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
)
var (
StatsCmd = &cobra.Command{
Use: "stats <manifest>",
Short: "display statistics about the specified manifest",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatalln("please specify a manifest")
}
bm, err := readManifestFile(args[0])
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
var stats struct {
resources int
files int
directories int
totalSize int64
symlinks int
}
for _, entry := range bm.Resource {
stats.resources++
stats.totalSize += int64(entry.Size)
mode := os.FileMode(entry.Mode)
if mode.IsRegular() {
stats.files += len(entry.Path) // count hardlinks!
} else if mode.IsDir() {
stats.directories++
} else if mode&os.ModeSymlink != 0 {
stats.symlinks++
}
}
w := newTabwriter(os.Stdout)
defer w.Flush()
fmt.Fprintf(w, "resources\t%v\n", stats.resources)
fmt.Fprintf(w, "directories\t%v\n", stats.directories)
fmt.Fprintf(w, "files\t%v\n", stats.files)
fmt.Fprintf(w, "symlinks\t%v\n", stats.symlinks)
fmt.Fprintf(w, "size\t%v\n", humanize.Bytes(uint64(stats.totalSize)))
},
}
)

View file

@ -0,0 +1,41 @@
package commands
import (
"io/ioutil"
"log"
"github.com/containerd/continuity"
"github.com/spf13/cobra"
)
var VerifyCmd = &cobra.Command{
Use: "verify <root> [<manifest>]",
Short: "Verify the root against the provided manifest",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
log.Fatalln("please specify a root and manifest")
}
root, path := args[0], args[1]
p, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("error reading manifest: %v", err)
}
m, err := continuity.Unmarshal(p)
if err != nil {
log.Fatalf("error unmarshaling manifest: %v", err)
}
ctx, err := continuity.NewContext(root)
if err != nil {
log.Fatalf("error getting context: %v", err)
}
if err := continuity.VerifyManifest(ctx, m); err != nil {
// TODO(stevvooe): Support more interesting error reporting.
log.Fatalf("error verifying manifest: %v", err)
}
},
}