Merge pull request #411 from eyakubovich/net-user-invoke

net: add --private-net to run cmd
This commit is contained in:
Eugene Yakubovich
2015-01-22 15:49:57 -08:00
3 changed files with 13 additions and 6 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "Building init (stage1)..."
go build -o $GOBIN/init ${REPO_PATH}/stage1/init
echo "Copying network plugins to stage1"
# symlink plugin binaries into stage1 rootfs
mkdir -p stage1/rootfs/net-plugins/bin
for d in networking/plugins/*; do
plugin=$(basename $d)
+4 -1
View File
@@ -34,6 +34,7 @@ var (
flagStage1Init string
flagStage1Rootfs string
flagVolumes volumeMap
flagPrivateNet bool
cmdRun = &Command{
Name: "run",
Summary: "Run image(s) in an application container in rocket",
@@ -49,6 +50,7 @@ func init() {
cmdRun.Flags.StringVar(&flagStage1Init, "stage1-init", "", "path to stage1 binary override")
cmdRun.Flags.StringVar(&flagStage1Rootfs, "stage1-rootfs", "", "path to stage1 rootfs tarball override")
cmdRun.Flags.Var(&flagVolumes, "volume", "volumes to mount into the shared container environment")
cmdRun.Flags.BoolVar(&flagPrivateNet, "private-net", false, "give container a private network")
flagVolumes = volumeMap{}
}
@@ -136,13 +138,14 @@ func runRun(args []string) (exit int) {
Stage1Rootfs: flagStage1Rootfs,
Images: imgs,
Volumes: flagVolumes,
PrivateNet: flagPrivateNet,
}
cdir, err := stage0.Setup(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "run: error setting up stage0: %v\n", err)
return 1
}
stage0.Run(cdir, cfg.Debug) // execs, never returns
stage0.Run(cfg, cdir) // execs, never returns
return 1
}
+8 -4
View File
@@ -64,8 +64,9 @@ type Config struct {
Stage1Rootfs string // compressed bundle containing a rootfs for stage1
Debug bool
// TODO(jonboulle): These images are partially-populated hashes, this should be clarified.
Images []types.Hash // application images
Volumes map[string]string // map of volumes that rocket can provide to applications
Images []types.Hash // application images
Volumes map[string]string // map of volumes that rocket can provide to applications
PrivateNet bool // container should have its own network stack
}
func init() {
@@ -195,7 +196,7 @@ func Setup(cfg Config) (string, error) {
// Run actually runs the container by exec()ing the stage1 init inside
// the container filesystem.
func Run(dir string, debug bool) {
func Run(cfg Config, dir string) {
log.Printf("Pivoting to filesystem %s", dir)
if err := os.Chdir(dir); err != nil {
log.Fatalf("failed changing to dir: %v", err)
@@ -203,9 +204,12 @@ func Run(dir string, debug bool) {
log.Printf("Execing %s", initPath)
args := []string{initPath}
if debug {
if cfg.Debug {
args = append(args, "--debug")
}
if cfg.PrivateNet {
args = append(args, "--private-net")
}
if err := syscall.Exec(initPath, args, os.Environ()); err != nil {
log.Fatalf("error execing init: %v", err)
}