diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index aaaf716..53006f6 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -25,33 +25,33 @@ }, { "ImportPath": "github.com/appc/spec/aci", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/appc/spec/actool", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/appc/spec/discovery", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/appc/spec/pkg/acirenderer", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/appc/spec/pkg/tarheader", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/appc/spec/schema", - "Comment": "v0.5.0", - "Rev": "cffea391f209199b873af3f8a71a98ac658f073e" + "Comment": "v0.5.0-10-g3fa4247", + "Rev": "3fa4247af87697784d812b8b68efd809fcbee33e" }, { "ImportPath": "github.com/camlistore/lock", diff --git a/Godeps/_workspace/src/github.com/appc/spec/schema/pod.go b/Godeps/_workspace/src/github.com/appc/spec/schema/pod.go index e97be0d..8b54836 100644 --- a/Godeps/_workspace/src/github.com/appc/spec/schema/pod.go +++ b/Godeps/_workspace/src/github.com/appc/spec/schema/pod.go @@ -13,7 +13,6 @@ const PodManifestKind = types.ACKind("PodManifest") type PodManifest struct { ACVersion types.SemVer `json:"acVersion"` ACKind types.ACKind `json:"acKind"` - UUID types.UUID `json:"uuid"` Apps AppList `json:"apps"` Volumes []types.Volume `json:"volumes"` Isolators []types.Isolator `json:"isolators"` diff --git a/Godeps/_workspace/src/github.com/appc/spec/schema/version.go b/Godeps/_workspace/src/github.com/appc/spec/schema/version.go index 4260595..be3a571 100644 --- a/Godeps/_workspace/src/github.com/appc/spec/schema/version.go +++ b/Godeps/_workspace/src/github.com/appc/spec/schema/version.go @@ -8,7 +8,7 @@ const ( // version represents the canonical version of the appc spec and tooling. // For now, the schema and tooling is coupled with the spec itself, so // this must be kept in sync with the VERSION file in the root of the repo. - version string = "0.5.0" + version string = "0.5.0+git" ) var ( diff --git a/rkt/metadata_service.go b/rkt/metadata_service.go index b68df72..497e8ba 100644 --- a/rkt/metadata_service.go +++ b/rkt/metadata_service.go @@ -46,6 +46,7 @@ var ( ) type mdsContainer struct { + uuid types.UUID manifest schema.PodManifest apps map[string]*schema.ImageManifest ip string @@ -105,6 +106,13 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) { return } + uuid, err := types.NewUUID(mux.Vars(r)["uuid"]) + if err != nil { + w.WriteHeader(http.StatusNotFound) + fmt.Fprintf(w, "UUID is missing or malformed: %v", err) + return + } + containerIP := queryValue(r.URL, "ip") if containerIP == "" { w.WriteHeader(http.StatusBadRequest) @@ -124,7 +132,7 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) { } containerByIP[containerIP] = c - containerByUID[c.manifest.UUID] = c + containerByUID[*uuid] = c w.WriteHeader(http.StatusOK) } @@ -132,21 +140,21 @@ func handleRegisterContainer(w http.ResponseWriter, r *http.Request) { func handleUnregisterContainer(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - uid, err := types.NewUUID(mux.Vars(r)["uid"]) + uuid, err := types.NewUUID(mux.Vars(r)["uuid"]) if err != nil { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "UUID is missing or malformed: %v", err) return } - c, ok := containerByUID[*uid] + c, ok := containerByUID[*uuid] if !ok { w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "Container with given UUID not found") return } - delete(containerByUID, *uid) + delete(containerByUID, *uuid) delete(containerByIP, c.ip) w.WriteHeader(http.StatusOK) @@ -165,14 +173,14 @@ func handleRegisterApp(w http.ResponseWriter, r *http.Request) { return } - uid, err := types.NewUUID(mux.Vars(r)["uid"]) + uuid, err := types.NewUUID(mux.Vars(r)["uuid"]) if err != nil { w.WriteHeader(http.StatusNotFound) fmt.Fprintf(w, "UUID is missing or mulformed: %v", err) return } - c, ok := containerByUID[*uid] + c, ok := containerByUID[*uuid] if !ok { w.WriteHeader(http.StatusNotFound) fmt.Fprint(w, "Container with given UUID not found") @@ -264,14 +272,14 @@ func handlePodManifest(w http.ResponseWriter, r *http.Request, c *mdsContainer) } } -func handleContainerUID(w http.ResponseWriter, r *http.Request, c *mdsContainer) { +func handleContainerUUID(w http.ResponseWriter, r *http.Request, c *mdsContainer) { defer r.Body.Close() - uid := c.manifest.UUID.String() + uuid := c.uuid.String() w.Header().Add("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) - w.Write([]byte(uid)) + w.Write([]byte(uuid)) } func mergeAppAnnotations(im *schema.ImageManifest, cm *schema.PodManifest) types.Annotations { @@ -375,7 +383,7 @@ func handleContainerSign(w http.ResponseWriter, r *http.Request) { // HMAC(UID:content) h := hmac.New(sha512.New, hmacKey[:]) - h.Write(c.manifest.UUID[:]) + h.Write(c.uuid[:]) h.Write([]byte(content)) // Send back HMAC as the signature @@ -449,27 +457,27 @@ func logReq(h func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc { func makeHandlers() http.Handler { r := mux.NewRouter() - r.HandleFunc("/pods/", logReq(handleRegisterContainer)).Methods("POST") - r.HandleFunc("/pods/{uid}", logReq(handleUnregisterContainer)).Methods("DELETE") - r.HandleFunc("/pods/{uid}/{app:.*}", logReq(handleRegisterApp)).Methods("PUT") + r.HandleFunc("/pods/{uuid}", logReq(handleRegisterContainer)).Methods("PUT") + r.HandleFunc("/pods/{uuid}", logReq(handleUnregisterContainer)).Methods("DELETE") + r.HandleFunc("/pods/{uuid}/{app:.*}", logReq(handleRegisterApp)).Methods("PUT") acRtr := r.Headers("Metadata-Flavor", "AppContainer"). PathPrefix("/acMetadata/v1").Subrouter() mr := acRtr.Methods("GET").Subrouter() - mr.HandleFunc("/container/annotations/", logReq(containerGet(handleContainerAnnotations))) - mr.HandleFunc("/container/annotations/{name}", logReq(containerGet(handleContainerAnnotation))) - mr.HandleFunc("/container/manifest", logReq(containerGet(handlePodManifest))) - mr.HandleFunc("/container/uid", logReq(containerGet(handleContainerUID))) + mr.HandleFunc("/pod/annotations/", logReq(containerGet(handleContainerAnnotations))) + mr.HandleFunc("/pod/annotations/{name}", logReq(containerGet(handleContainerAnnotation))) + mr.HandleFunc("/pod/manifest", logReq(containerGet(handlePodManifest))) + mr.HandleFunc("/pod/uuid", logReq(containerGet(handleContainerUUID))) mr.HandleFunc("/apps/{app:.*}/annotations/", logReq(appGet(handleAppAnnotations))) mr.HandleFunc("/apps/{app:.*}/annotations/{name}", logReq(appGet(handleAppAnnotation))) mr.HandleFunc("/apps/{app:.*}/image/manifest", logReq(appGet(handleImageManifest))) mr.HandleFunc("/apps/{app:.*}/image/id", logReq(appGet(handleAppID))) - acRtr.HandleFunc("/container/hmac/sign", logReq(handleContainerSign)).Methods("POST") - acRtr.HandleFunc("/container/hmac/verify", logReq(handleContainerVerify)).Methods("POST") + acRtr.HandleFunc("/pod/hmac/sign", logReq(handleContainerSign)).Methods("POST") + acRtr.HandleFunc("/pod/hmac/verify", logReq(handleContainerVerify)).Methods("POST") return r } diff --git a/rkt/prepare.go b/rkt/prepare.go index 7f96a89..2c80626 100644 --- a/rkt/prepare.go +++ b/rkt/prepare.go @@ -115,6 +115,7 @@ func runPrepare(args []string) (exit int) { Store: ds, Debug: globalFlags.Debug, Stage1Image: *s1img, + UUID: c.uuid, Images: imgs, }, ExecAppends: appArgs, diff --git a/rkt/run.go b/rkt/run.go index dc433de..b5c5565 100644 --- a/rkt/run.go +++ b/rkt/run.go @@ -234,6 +234,7 @@ func runRun(args []string) (exit int) { cfg := stage0.CommonConfig{ Store: ds, Stage1Image: *s1img, + UUID: c.uuid, Images: imgs, Debug: globalFlags.Debug, } diff --git a/rkt/run_prepared.go b/rkt/run_prepared.go index fdc13cc..dd13a55 100644 --- a/rkt/run_prepared.go +++ b/rkt/run_prepared.go @@ -123,6 +123,7 @@ func runRunPrepared(args []string) (exit int) { CommonConfig: stage0.CommonConfig{ Store: ds, Stage1Image: *s1img, + UUID: c.uuid, Images: imgs, Debug: globalFlags.Debug, }, diff --git a/stage0/run.go b/stage0/run.go index 64633be..bf770e2 100644 --- a/stage0/run.go +++ b/stage0/run.go @@ -70,6 +70,7 @@ type RunConfig struct { type CommonConfig struct { Store *cas.Store // store containing all of the configured application images Stage1Image types.Hash // stage1 image containing usable /init and /enter entrypoints + UUID *types.UUID // UUID of the pod Images []types.Hash // application images PodsDir string // root directory for rocket pods Debug bool @@ -300,6 +301,7 @@ func Run(cfg RunConfig, dir string) { if cfg.Interactive { args = append(args, "--interactive") } + args = append(args, cfg.UUID.String()) // make sure the lock fd stays open across exec if err := sys.CloseOnExec(cfg.LockFd, false); err != nil { diff --git a/stage1/init/container.go b/stage1/init/container.go index 296caf8..9357e89 100644 --- a/stage1/init/container.go +++ b/stage1/init/container.go @@ -36,6 +36,7 @@ import ( // Container encapsulates a PodManifest and ImageManifests type Container struct { Root string // root directory where the container will be located + UUID types.UUID Manifest *schema.PodManifest Apps map[string]*schema.ImageManifest MetadataServiceURL string @@ -44,9 +45,10 @@ type Container struct { // LoadContainer loads a Pod Manifest (as prepared by stage0) and // its associated Application Manifests, under $root/stage1/opt/stage1/$apphash -func LoadContainer(root string) (*Container, error) { +func LoadContainer(root string, uuid *types.UUID) (*Container, error) { c := &Container{ Root: root, + UUID: *uuid, Apps: make(map[string]*schema.ImageManifest), } @@ -330,7 +332,7 @@ func (c *Container) appToNspawnArgs(ra *schema.RuntimeApp, am *schema.ImageManif // argument list ready to be executed func (c *Container) ContainerToNspawnArgs() ([]string, error) { args := []string{ - "--uuid=" + c.Manifest.UUID.String(), + "--uuid=" + c.UUID.String(), "--directory=" + common.Stage1RootfsPath(c.Root), } diff --git a/stage1/init/init.go b/stage1/init/init.go index 8c5cd36..5d5bf27 100644 --- a/stage1/init/init.go +++ b/stage1/init/init.go @@ -28,6 +28,8 @@ import ( "runtime" "syscall" + "github.com/coreos/rocket/Godeps/_workspace/src/github.com/appc/spec/schema/types" + "github.com/coreos/rocket/common" "github.com/coreos/rocket/networking" "github.com/coreos/rocket/pkg/sys" @@ -156,8 +158,14 @@ func withClearedCloExec(lfd int, f func() error) error { } func stage1() int { + uuid, err := types.NewUUID(flag.Arg(0)) + if err != nil { + fmt.Fprintln(os.Stderr, "UUID is missing or malformed") + return 1 + } + root := "." - c, err := LoadContainer(root) + c, err := LoadContainer(root, uuid) if err != nil { fmt.Fprintf(os.Stderr, "Failed to load container: %v\n", err) return 1 @@ -194,7 +202,7 @@ func stage1() int { // careful not to make another local err variable. // cmd.Run sets the one from parent scope var n *networking.Networking - n, err = networking.Setup(root, c.Manifest.UUID) + n, err = networking.Setup(root, c.UUID) if err != nil { fmt.Fprintf(os.Stderr, "Failed to setup network: %v\n", err) return 6 diff --git a/stage1/init/registration.go b/stage1/init/registration.go index 6d37e84..3cc08b1 100644 --- a/stage1/init/registration.go +++ b/stage1/init/registration.go @@ -26,18 +26,19 @@ import ( ) func registerContainer(c *Container, ip net.IP) error { + uuid := c.UUID.String() + cmf, err := os.Open(common.PodManifestPath(c.Root)) if err != nil { return fmt.Errorf("failed opening runtime manifest: %v", err) } defer cmf.Close() - pth := fmt.Sprintf("/pods/?ip=%v", ip.To4().String()) - if err := httpRequest("POST", pth, cmf); err != nil { + pth := fmt.Sprintf("/pods/%v?ip=%v", uuid, ip.To4().String()) + if err := httpRequest("PUT", pth, cmf); err != nil { return fmt.Errorf("failed to register container with metadata svc: %v", err) } - uid := c.Manifest.UUID.String() for _, app := range c.Manifest.Apps { ampath := common.ImageManifestPath(c.Root, app.Image.ID) amf, err := os.Open(ampath) @@ -46,7 +47,7 @@ func registerContainer(c *Container, ip net.IP) error { } defer amf.Close() - if err := registerApp(uid, app.Name.String(), amf); err != nil { + if err := registerApp(uuid, app.Name.String(), amf); err != nil { fmt.Errorf("failed to register app with metadata svc: %v", err) } } @@ -55,12 +56,12 @@ func registerContainer(c *Container, ip net.IP) error { } func unregisterContainer(c *Container) error { - pth := path.Join("/containers", c.Manifest.UUID.String()) + pth := path.Join("/pods", c.UUID.String()) return httpRequest("DELETE", pth, nil) } func registerApp(uuid, app string, r io.Reader) error { - pth := path.Join("/containers", uuid, app) + pth := path.Join("/pods", uuid, app) return httpRequest("PUT", pth, r) }