update cl-k8s

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-03-20 03:02:29 -04:00
parent 1d95b0a02a
commit b9808eb70c

View file

@ -2,7 +2,6 @@ package main
import ( import (
"flag" "flag"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -25,7 +24,9 @@ var (
containerID string containerID string
root string root string
file string file string
dir string
shortpath string
) )
func init() { func init() {
@ -42,28 +43,6 @@ func init() {
if flag.NArg() < 1 { if flag.NArg() < 1 {
logrus.Fatal("pass a file to run with cl-k8s") logrus.Fatal("pass a file to run with cl-k8s")
} }
// Get the file args passed.
file := flag.Arg(0)
// Get the absolute path.
var err error
file, err = filepath.Abs(file)
if err != nil {
logrus.Fatal(err)
}
// Check if its directory.
fi, err := os.Stat(file)
if err != nil {
logrus.Fatal(err)
}
if !fi.Mode().IsDir() {
// Copy the file to a temporary directory.
file, err = copyFile(file)
if err != nil {
logrus.Fatal(err)
}
fmt.Printf("new file is %s\n", file)
}
} }
//go:generate go run generate.go //go:generate go run generate.go
@ -73,6 +52,32 @@ func main() {
return return
} }
// Get the file args passed.
file = flag.Arg(0)
// Get the absolute path.
var err error
file, err = filepath.Abs(file)
if err != nil {
logrus.Fatal(err)
}
// Check if its directory.
fi, err := os.Stat(file)
if err != nil {
logrus.Fatal(err)
}
dir = file
if !fi.Mode().IsDir() {
// Copy the file to a temporary directory.
file, err = copyFile(file)
if err != nil {
logrus.Fatal(err)
}
dir = filepath.Dir(file)
}
// Create a new container spec with the following options. // Create a new container spec with the following options.
opts := container.SpecOpts{ opts := container.SpecOpts{
Rootless: true, Rootless: true,
@ -82,12 +87,11 @@ func main() {
{ {
Destination: "/home/user/scripts/", Destination: "/home/user/scripts/",
Type: "bind", Type: "bind",
Source: filepath.Dir(file), Source: dir,
Options: []string{"bind", "ro"}, Options: []string{"bind", "ro"},
}, },
}, },
} }
fmt.Printf("opts %#v\n", opts)
spec := container.Spec(opts) spec := container.Spec(opts)
// Initialize the container object. // Initialize the container object.