mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
linted names
This commit is contained in:
parent
86ada2fa5d
commit
fd224ee590
26 changed files with 451 additions and 451 deletions
72
api.go
72
api.go
|
@ -13,7 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const API_VERSION = 1.1
|
const APIVERSION = 1.1
|
||||||
|
|
||||||
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
||||||
conn, _, err := w.(http.Hijacker).Hijack()
|
conn, _, err := w.(http.Hijacker).Hijack()
|
||||||
|
@ -52,7 +52,7 @@ func httpError(w http.ResponseWriter, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeJson(w http.ResponseWriter, b []byte) {
|
func writeJSON(w http.ResponseWriter, b []byte) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reques
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +111,11 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque
|
||||||
}
|
}
|
||||||
|
|
||||||
if status != "" {
|
if status != "" {
|
||||||
b, err := json.Marshal(&ApiAuth{Status: status})
|
b, err := json.Marshal(&APIAuth{Status: status})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
@ -128,7 +128,7 @@ func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Req
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func getContainersExport(srv *Server, version float64, w http.ResponseWriter, r
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getImagesJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ func getImagesJson(srv *Server, version float64, w http.ResponseWriter, r *http.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Reques
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ func getImagesHistory(srv *Server, version float64, w http.ResponseWriter, r *ht
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,11 +227,11 @@ func getContainersChanges(srv *Server, version float64, w http.ResponseWriter, r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func getContainersJSON(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
if err := parseForm(r); err != nil {
|
if err := parseForm(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ func getContainersJson(srv *Server, version float64, w http.ResponseWriter, r *h
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,12 +294,12 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(&ApiId{id})
|
b, err := json.Marshal(&APIID{id})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ func getImagesSearch(srv *Server, version float64, w http.ResponseWriter, r *htt
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,18 +372,18 @@ func postImagesInsert(srv *Server, version float64, w http.ResponseWriter, r *ht
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
sf := utils.NewStreamFormatter(version > 1.0)
|
sf := utils.NewStreamFormatter(version > 1.0)
|
||||||
imgId, err := srv.ImageInsert(name, url, path, w, sf)
|
imgID, err := srv.ImageInsert(name, url, path, w, sf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if sf.Used() {
|
if sf.Used() {
|
||||||
w.Write(sf.FormatError(err))
|
w.Write(sf.FormatError(err))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(&ApiId{Id: imgId})
|
b, err := json.Marshal(&APIID{ID: imgID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,8 +421,8 @@ func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out := &ApiRun{
|
out := &APIRun{
|
||||||
Id: id,
|
ID: id,
|
||||||
}
|
}
|
||||||
if config.Memory > 0 && !srv.runtime.capabilities.MemoryLimit {
|
if config.Memory > 0 && !srv.runtime.capabilities.MemoryLimit {
|
||||||
log.Println("WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.")
|
log.Println("WARNING: Your kernel does not support memory limit capabilities. Limitation discarded.")
|
||||||
|
@ -437,7 +437,7 @@ func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,11 +534,11 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(&ApiWait{StatusCode: status})
|
b, err := json.Marshal(&APIWait{StatusCode: status})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,7 +625,7 @@ func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,17 +643,17 @@ func getImagesByName(srv *Server, version float64, w http.ResponseWriter, r *htt
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
apiConfig := &ApiImageConfig{}
|
apiConfig := &APIImageConfig{}
|
||||||
if err := json.NewDecoder(r.Body).Decode(apiConfig); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(apiConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
image, err := srv.ImageGetCached(apiConfig.Id, apiConfig.Config)
|
image, err := srv.ImageGetCached(apiConfig.ID, apiConfig.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -661,12 +661,12 @@ func postImagesGetCache(srv *Server, version float64, w http.ResponseWriter, r *
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
apiId := &ApiId{Id: image.Id}
|
apiID := &APIID{ID: image.ID}
|
||||||
b, err := json.Marshal(apiId)
|
b, err := json.Marshal(apiID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
writeJson(w, b)
|
writeJSON(w, b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,13 +712,13 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
||||||
"/auth": getAuth,
|
"/auth": getAuth,
|
||||||
"/version": getVersion,
|
"/version": getVersion,
|
||||||
"/info": getInfo,
|
"/info": getInfo,
|
||||||
"/images/json": getImagesJson,
|
"/images/json": getImagesJSON,
|
||||||
"/images/viz": getImagesViz,
|
"/images/viz": getImagesViz,
|
||||||
"/images/search": getImagesSearch,
|
"/images/search": getImagesSearch,
|
||||||
"/images/{name:.*}/history": getImagesHistory,
|
"/images/{name:.*}/history": getImagesHistory,
|
||||||
"/images/{name:.*}/json": getImagesByName,
|
"/images/{name:.*}/json": getImagesByName,
|
||||||
"/containers/ps": getContainersJson,
|
"/containers/ps": getContainersJSON,
|
||||||
"/containers/json": getContainersJson,
|
"/containers/json": getContainersJSON,
|
||||||
"/containers/{name:.*}/export": getContainersExport,
|
"/containers/{name:.*}/export": getContainersExport,
|
||||||
"/containers/{name:.*}/changes": getContainersChanges,
|
"/containers/{name:.*}/changes": getContainersChanges,
|
||||||
"/containers/{name:.*}/json": getContainersByName,
|
"/containers/{name:.*}/json": getContainersByName,
|
||||||
|
@ -767,9 +767,9 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
||||||
}
|
}
|
||||||
version, err := strconv.ParseFloat(mux.Vars(r)["version"], 64)
|
version, err := strconv.ParseFloat(mux.Vars(r)["version"], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
version = API_VERSION
|
version = APIVERSION
|
||||||
}
|
}
|
||||||
if version == 0 || version > API_VERSION {
|
if version == 0 || version > APIVERSION {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
type ApiHistory struct {
|
type APIHistory struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
Created int64
|
Created int64
|
||||||
CreatedBy string `json:",omitempty"`
|
CreatedBy string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiImages struct {
|
type APIImages struct {
|
||||||
Repository string `json:",omitempty"`
|
Repository string `json:",omitempty"`
|
||||||
Tag string `json:",omitempty"`
|
Tag string `json:",omitempty"`
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
Created int64
|
Created int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiInfo struct {
|
type APIInfo struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
Containers int
|
Containers int
|
||||||
Images int
|
Images int
|
||||||
|
@ -23,8 +23,8 @@ type ApiInfo struct {
|
||||||
SwapLimit bool `json:",omitempty"`
|
SwapLimit bool `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiContainers struct {
|
type APIContainers struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
Image string
|
Image string
|
||||||
Command string
|
Command string
|
||||||
Created int64
|
Created int64
|
||||||
|
@ -32,39 +32,39 @@ type ApiContainers struct {
|
||||||
Ports string
|
Ports string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiSearch struct {
|
type APISearch struct {
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiId struct {
|
type APIID struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiRun struct {
|
type APIRun struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
Warnings []string `json:",omitempty"`
|
Warnings []string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiPort struct {
|
type APIPort struct {
|
||||||
Port string
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiVersion struct {
|
type APIVersion struct {
|
||||||
Version string
|
Version string
|
||||||
GitCommit string `json:",omitempty"`
|
GitCommit string `json:",omitempty"`
|
||||||
GoVersion string `json:",omitempty"`
|
GoVersion string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiWait struct {
|
type APIWait struct {
|
||||||
StatusCode int
|
StatusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiAuth struct {
|
type APIAuth struct {
|
||||||
Status string
|
Status string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiImageConfig struct {
|
type APIImageConfig struct {
|
||||||
Id string
|
ID string `json:"Id"`
|
||||||
*Config
|
*Config
|
||||||
}
|
}
|
||||||
|
|
146
api_test.go
146
api_test.go
|
@ -37,17 +37,17 @@ func TestGetAuth(t *testing.T) {
|
||||||
Email: "utest@yopmail.com",
|
Email: "utest@yopmail.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
authConfigJson, err := json.Marshal(authConfig)
|
authConfigJSON, err := json.Marshal(authConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/auth", bytes.NewReader(authConfigJson))
|
req, err := http.NewRequest("POST", "/auth", bytes.NewReader(authConfigJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := postAuth(srv, API_VERSION, r, req, nil); err != nil {
|
if err := postAuth(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,11 +73,11 @@ func TestGetVersion(t *testing.T) {
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
|
|
||||||
if err := getVersion(srv, API_VERSION, r, nil, nil); err != nil {
|
if err := getVersion(srv, APIVERSION, r, nil, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
v := &ApiVersion{}
|
v := &APIVersion{}
|
||||||
if err = json.Unmarshal(r.Body.Bytes(), v); err != nil {
|
if err = json.Unmarshal(r.Body.Bytes(), v); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -97,11 +97,11 @@ func TestGetInfo(t *testing.T) {
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
|
|
||||||
if err := getInfo(srv, API_VERSION, r, nil, nil); err != nil {
|
if err := getInfo(srv, APIVERSION, r, nil, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
infos := &ApiInfo{}
|
infos := &APIInfo{}
|
||||||
err = json.Unmarshal(r.Body.Bytes(), infos)
|
err = json.Unmarshal(r.Body.Bytes(), infos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -111,7 +111,7 @@ func TestGetInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetImagesJson(t *testing.T) {
|
func TestGetImagesJSON(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -128,11 +128,11 @@ func TestGetImagesJson(t *testing.T) {
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
|
|
||||||
if err := getImagesJson(srv, API_VERSION, r, req, nil); err != nil {
|
if err := getImagesJSON(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
images := []ApiImages{}
|
images := []APIImages{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), &images); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), &images); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -153,11 +153,11 @@ func TestGetImagesJson(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := getImagesJson(srv, API_VERSION, r2, req2, nil); err != nil {
|
if err := getImagesJSON(srv, APIVERSION, r2, req2, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
images2 := []ApiImages{}
|
images2 := []APIImages{}
|
||||||
if err := json.Unmarshal(r2.Body.Bytes(), &images2); err != nil {
|
if err := json.Unmarshal(r2.Body.Bytes(), &images2); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -166,8 +166,8 @@ func TestGetImagesJson(t *testing.T) {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images2))
|
t.Errorf("Excepted 1 image, %d found", len(images2))
|
||||||
}
|
}
|
||||||
|
|
||||||
if images2[0].Id != GetTestImage(runtime).Id {
|
if images2[0].ID != GetTestImage(runtime).ID {
|
||||||
t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).Id, images2[0].Id)
|
t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ID, images2[0].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
r3 := httptest.NewRecorder()
|
r3 := httptest.NewRecorder()
|
||||||
|
@ -178,11 +178,11 @@ func TestGetImagesJson(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := getImagesJson(srv, API_VERSION, r3, req3, nil); err != nil {
|
if err := getImagesJSON(srv, APIVERSION, r3, req3, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
images3 := []ApiImages{}
|
images3 := []APIImages{}
|
||||||
if err := json.Unmarshal(r3.Body.Bytes(), &images3); err != nil {
|
if err := json.Unmarshal(r3.Body.Bytes(), &images3); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func TestGetImagesJson(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = getImagesJson(srv, API_VERSION, r4, req4, nil)
|
err = getImagesJSON(srv, APIVERSION, r4, req4, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Error expected, received none")
|
t.Fatalf("Error expected, received none")
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ func TestGetImagesViz(t *testing.T) {
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getImagesViz(srv, API_VERSION, r, nil, nil); err != nil {
|
if err := getImagesViz(srv, APIVERSION, r, nil, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,11 +256,11 @@ func TestGetImagesSearch(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := getImagesSearch(srv, API_VERSION, r, req, nil); err != nil {
|
if err := getImagesSearch(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
results := []ApiSearch{}
|
results := []APISearch{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), &results); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -280,11 +280,11 @@ func TestGetImagesHistory(t *testing.T) {
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
|
|
||||||
if err := getImagesHistory(srv, API_VERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
if err := getImagesHistory(srv, APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
history := []ApiHistory{}
|
history := []APIHistory{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), &history); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), &history); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ func TestGetImagesByName(t *testing.T) {
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getImagesByName(srv, API_VERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
if err := getImagesByName(srv, APIVERSION, r, nil, map[string]string{"name": unitTestImageName}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,12 +311,12 @@ func TestGetImagesByName(t *testing.T) {
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if img.Id != GetTestImage(runtime).Id || img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
if img.ID != GetTestImage(runtime).ID || img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
||||||
t.Errorf("Error inspecting image")
|
t.Errorf("Error inspecting image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainersJson(t *testing.T) {
|
func TestGetContainersJSON(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -326,7 +326,7 @@ func TestGetContainersJson(t *testing.T) {
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "test"},
|
Cmd: []string{"echo", "test"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -340,18 +340,18 @@ func TestGetContainersJson(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getContainersJson(srv, API_VERSION, r, req, nil); err != nil {
|
if err := getContainersJSON(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
containers := []ApiContainers{}
|
containers := []APIContainers{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), &containers); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), &containers); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(containers) != 1 {
|
if len(containers) != 1 {
|
||||||
t.Fatalf("Excepted %d container, %d found", 1, len(containers))
|
t.Fatalf("Excepted %d container, %d found", 1, len(containers))
|
||||||
}
|
}
|
||||||
if containers[0].Id != container.Id {
|
if containers[0].ID != container.ID {
|
||||||
t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.Id, containers[0].Id)
|
t.Fatalf("Container ID mismatch. Expected: %s, received: %s\n", container.ID, containers[0].ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ func TestGetContainersExport(t *testing.T) {
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := builder.Create(
|
container, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"touch", "/test"},
|
Cmd: []string{"touch", "/test"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -383,7 +383,7 @@ func TestGetContainersExport(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err = getContainersExport(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err = getContainersExport(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ func TestGetContainersChanges(t *testing.T) {
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := builder.Create(
|
container, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/rm", "/etc/passwd"},
|
Cmd: []string{"/bin/rm", "/etc/passwd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -438,7 +438,7 @@ func TestGetContainersChanges(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getContainersChanges(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err := getContainersChanges(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
changes := []Change{}
|
changes := []Change{}
|
||||||
|
@ -472,7 +472,7 @@ func TestGetContainersByName(t *testing.T) {
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := builder.Create(
|
container, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "test"},
|
Cmd: []string{"echo", "test"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -482,15 +482,15 @@ func TestGetContainersByName(t *testing.T) {
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getContainersByName(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err := getContainersByName(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
outContainer := &Container{}
|
outContainer := &Container{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), outContainer); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), outContainer); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if outContainer.Id != container.Id {
|
if outContainer.ID != container.ID {
|
||||||
t.Fatalf("Wrong containers retrieved. Expected %s, recieved %s", container.Id, outContainer.Id)
|
t.Fatalf("Wrong containers retrieved. Expected %s, recieved %s", container.ID, outContainer.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ func TestPostAuth(t *testing.T) {
|
||||||
auth.SaveConfig(runtime.root, authStr, config.Email)
|
auth.SaveConfig(runtime.root, authStr, config.Email)
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil {
|
if err := getAuth(srv, APIVERSION, r, nil, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ func TestPostCommit(t *testing.T) {
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := builder.Create(
|
container, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"touch", "/test"},
|
Cmd: []string{"touch", "/test"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -555,24 +555,24 @@ func TestPostCommit(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/commit?repo=testrepo&testtag=tag&container="+container.Id, bytes.NewReader([]byte{}))
|
req, err := http.NewRequest("POST", "/commit?repo=testrepo&testtag=tag&container="+container.ID, bytes.NewReader([]byte{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postCommit(srv, API_VERSION, r, req, nil); err != nil {
|
if err := postCommit(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusCreated {
|
if r.Code != http.StatusCreated {
|
||||||
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiId := &ApiId{}
|
apiID := &APIID{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), apiId); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), apiID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, err := runtime.graph.Get(apiId.Id); err != nil {
|
if _, err := runtime.graph.Get(apiID.ID); err != nil {
|
||||||
t.Fatalf("The image has not been commited")
|
t.Fatalf("The image has not been commited")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -715,7 +715,7 @@ func TestPostImagesInsert(t *testing.T) {
|
||||||
// t.Fatalf("The test file has not been found")
|
// t.Fatalf("The test file has not been found")
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if err := srv.runtime.graph.Delete(img.Id); err != nil {
|
// if err := srv.runtime.graph.Delete(img.ID); err != nil {
|
||||||
// t.Fatal(err)
|
// t.Fatal(err)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
@ -824,8 +824,8 @@ func TestPostContainersCreate(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
configJson, err := json.Marshal(&Config{
|
configJSON, err := json.Marshal(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Memory: 33554432,
|
Memory: 33554432,
|
||||||
Cmd: []string{"touch", "/test"},
|
Cmd: []string{"touch", "/test"},
|
||||||
})
|
})
|
||||||
|
@ -833,25 +833,25 @@ func TestPostContainersCreate(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/containers/create", bytes.NewReader(configJson))
|
req, err := http.NewRequest("POST", "/containers/create", bytes.NewReader(configJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersCreate(srv, API_VERSION, r, req, nil); err != nil {
|
if err := postContainersCreate(srv, APIVERSION, r, req, nil); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusCreated {
|
if r.Code != http.StatusCreated {
|
||||||
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiRun := &ApiRun{}
|
apiRun := &APIRun{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), apiRun); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), apiRun); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
container := srv.runtime.Get(apiRun.Id)
|
container := srv.runtime.Get(apiRun.ID)
|
||||||
if container == nil {
|
if container == nil {
|
||||||
t.Fatalf("Container not created")
|
t.Fatalf("Container not created")
|
||||||
}
|
}
|
||||||
|
@ -880,7 +880,7 @@ func TestPostContainersKill(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -902,7 +902,7 @@ func TestPostContainersKill(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersKill(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersKill(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusNoContent {
|
if r.Code != http.StatusNoContent {
|
||||||
|
@ -924,7 +924,7 @@ func TestPostContainersRestart(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -945,12 +945,12 @@ func TestPostContainersRestart(t *testing.T) {
|
||||||
t.Errorf("Container should be running")
|
t.Errorf("Container should be running")
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/restart?t=1", bytes.NewReader([]byte{}))
|
req, err := http.NewRequest("POST", "/containers/"+container.ID+"/restart?t=1", bytes.NewReader([]byte{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersRestart(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersRestart(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusNoContent {
|
if r.Code != http.StatusNoContent {
|
||||||
|
@ -980,7 +980,7 @@ func TestPostContainersStart(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -991,7 +991,7 @@ func TestPostContainersStart(t *testing.T) {
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersStart(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersStart(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusNoContent {
|
if r.Code != http.StatusNoContent {
|
||||||
|
@ -1006,7 +1006,7 @@ func TestPostContainersStart(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
r = httptest.NewRecorder()
|
r = httptest.NewRecorder()
|
||||||
if err = postContainersStart(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err == nil {
|
if err = postContainersStart(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err == nil {
|
||||||
t.Fatalf("A running containter should be able to be started")
|
t.Fatalf("A running containter should be able to be started")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1026,7 +1026,7 @@ func TestPostContainersStop(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -1048,12 +1048,12 @@ func TestPostContainersStop(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: as it is a POST request, it requires a body.
|
// Note: as it is a POST request, it requires a body.
|
||||||
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/stop?t=1", bytes.NewReader([]byte{}))
|
req, err := http.NewRequest("POST", "/containers/"+container.ID+"/stop?t=1", bytes.NewReader([]byte{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersStop(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersStop(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusNoContent {
|
if r.Code != http.StatusNoContent {
|
||||||
|
@ -1075,7 +1075,7 @@ func TestPostContainersWait(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/sleep", "1"},
|
Cmd: []string{"/bin/sleep", "1"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -1091,10 +1091,10 @@ func TestPostContainersWait(t *testing.T) {
|
||||||
|
|
||||||
setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
setTimeout(t, "Wait timed out", 3*time.Second, func() {
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := postContainersWait(srv, API_VERSION, r, nil, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersWait(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
apiWait := &ApiWait{}
|
apiWait := &APIWait{}
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), apiWait); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), apiWait); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1119,7 +1119,7 @@ func TestPostContainersAttach(t *testing.T) {
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -1148,12 +1148,12 @@ func TestPostContainersAttach(t *testing.T) {
|
||||||
out: stdoutPipe,
|
out: stdoutPipe,
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", "/containers/"+container.Id+"/attach?stream=1&stdin=1&stdout=1&stderr=1", bytes.NewReader([]byte{}))
|
req, err := http.NewRequest("POST", "/containers/"+container.ID+"/attach?stream=1&stdin=1&stdout=1&stderr=1", bytes.NewReader([]byte{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := postContainersAttach(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil {
|
if err := postContainersAttach(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -1206,7 +1206,7 @@ func TestDeleteContainers(t *testing.T) {
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"touch", "/test"},
|
Cmd: []string{"touch", "/test"},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1218,19 +1218,19 @@ func TestDeleteContainers(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", "/containers/"+container.Id, nil)
|
req, err := http.NewRequest("DELETE", "/containers/"+container.ID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
if err := deleteContainers(srv, API_VERSION, r, req, map[string]string{"name": container.Id}); err != nil {
|
if err := deleteContainers(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if r.Code != http.StatusNoContent {
|
if r.Code != http.StatusNoContent {
|
||||||
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
t.Fatalf("%d NO CONTENT expected, received %d\n", http.StatusNoContent, r.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c := runtime.Get(container.Id); c != nil {
|
if c := runtime.Get(container.ID); c != nil {
|
||||||
t.Fatalf("The container as not been deleted")
|
t.Fatalf("The container as not been deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ import (
|
||||||
const CONFIGFILE = ".dockercfg"
|
const CONFIGFILE = ".dockercfg"
|
||||||
|
|
||||||
// the registry server we want to login against
|
// the registry server we want to login against
|
||||||
const INDEX_SERVER = "https://index.docker.io/v1"
|
const INDEXSERVER = "https://index.docker.io/v1"
|
||||||
|
|
||||||
//const INDEX_SERVER = "http://indexstaging-docker.dotcloud.com/"
|
//const INDEXSERVER = "http://indexstaging-docker.dotcloud.com/"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrConfigFileMissing = errors.New("The Auth config file is missing")
|
ErrConfigFileMissing = errors.New("The Auth config file is missing")
|
||||||
|
@ -44,7 +44,7 @@ func IndexServerAddress() string {
|
||||||
if os.Getenv("DOCKER_INDEX_URL") != "" {
|
if os.Getenv("DOCKER_INDEX_URL") != "" {
|
||||||
return os.Getenv("DOCKER_INDEX_URL") + "/v1"
|
return os.Getenv("DOCKER_INDEX_URL") + "/v1"
|
||||||
}
|
}
|
||||||
return INDEX_SERVER
|
return INDEXSERVER
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a base64 encoded auth string to store in config
|
// create a base64 encoded auth string to store in config
|
||||||
|
|
10
builder.go
10
builder.go
|
@ -40,7 +40,7 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate id
|
// Generate id
|
||||||
id := GenerateId()
|
id := GenerateID()
|
||||||
// Generate default hostname
|
// Generate default hostname
|
||||||
// FIXME: the lxc template no longer needs to set a default hostname
|
// FIXME: the lxc template no longer needs to set a default hostname
|
||||||
if config.Hostname == "" {
|
if config.Hostname == "" {
|
||||||
|
@ -49,17 +49,17 @@ func (builder *Builder) Create(config *Config) (*Container, error) {
|
||||||
|
|
||||||
container := &Container{
|
container := &Container{
|
||||||
// FIXME: we should generate the ID here instead of receiving it as an argument
|
// FIXME: we should generate the ID here instead of receiving it as an argument
|
||||||
Id: id,
|
ID: id,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
Path: config.Cmd[0],
|
Path: config.Cmd[0],
|
||||||
Args: config.Cmd[1:], //FIXME: de-duplicate from config
|
Args: config.Cmd[1:], //FIXME: de-duplicate from config
|
||||||
Config: config,
|
Config: config,
|
||||||
Image: img.Id, // Always use the resolved image id
|
Image: img.ID, // Always use the resolved image id
|
||||||
NetworkSettings: &NetworkSettings{},
|
NetworkSettings: &NetworkSettings{},
|
||||||
// FIXME: do we need to store this in the container?
|
// FIXME: do we need to store this in the container?
|
||||||
SysInitPath: sysInitPath,
|
SysInitPath: sysInitPath,
|
||||||
}
|
}
|
||||||
container.root = builder.runtime.containerRoot(container.Id)
|
container.root = builder.runtime.containerRoot(container.ID)
|
||||||
// Step 1: create the container directory.
|
// Step 1: create the container directory.
|
||||||
// This doubles as a barrier to avoid race conditions.
|
// This doubles as a barrier to avoid race conditions.
|
||||||
if err := os.Mkdir(container.root, 0700); err != nil {
|
if err := os.Mkdir(container.root, 0700); err != nil {
|
||||||
|
@ -110,7 +110,7 @@ func (builder *Builder) Commit(container *Container, repository, tag, comment, a
|
||||||
}
|
}
|
||||||
// Register the image if needed
|
// Register the image if needed
|
||||||
if repository != "" {
|
if repository != "" {
|
||||||
if err := builder.repositories.Set(repository, tag, img.Id, true); err != nil {
|
if err := builder.repositories.Set(repository, tag, img.ID, true); err != nil {
|
||||||
return img, err
|
return img, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,11 +63,11 @@ func (b *builderClient) CmdFrom(name string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
img := &ApiId{}
|
img := &APIID{}
|
||||||
if err := json.Unmarshal(obj, img); err != nil {
|
if err := json.Unmarshal(obj, img); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.image = img.Id
|
b.image = img.ID
|
||||||
utils.Debugf("Using image %s", b.image)
|
utils.Debugf("Using image %s", b.image)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -91,19 +91,19 @@ func (b *builderClient) CmdRun(args string) error {
|
||||||
b.config.Cmd = nil
|
b.config.Cmd = nil
|
||||||
MergeConfig(b.config, config)
|
MergeConfig(b.config, config)
|
||||||
|
|
||||||
body, statusCode, err := b.cli.call("POST", "/images/getCache", &ApiImageConfig{Id: b.image, Config: b.config})
|
body, statusCode, err := b.cli.call("POST", "/images/getCache", &APIImageConfig{ID: b.image, Config: b.config})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if statusCode != 404 {
|
if statusCode != 404 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if statusCode != 404 {
|
if statusCode != 404 {
|
||||||
apiId := &ApiId{}
|
apiID := &APIID{}
|
||||||
if err := json.Unmarshal(body, apiId); err != nil {
|
if err := json.Unmarshal(body, apiID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
utils.Debugf("Use cached version")
|
utils.Debugf("Use cached version")
|
||||||
b.image = apiId.Id
|
b.image = apiID.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cid, err := b.run()
|
cid, err := b.run()
|
||||||
|
@ -163,7 +163,7 @@ func (b *builderClient) CmdInsert(args string) error {
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// apiId := &ApiId{}
|
// apiId := &APIId{}
|
||||||
// if err := json.Unmarshal(body, apiId); err != nil {
|
// if err := json.Unmarshal(body, apiId); err != nil {
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
|
@ -182,7 +182,7 @@ func (b *builderClient) run() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
apiRun := &ApiRun{}
|
apiRun := &APIRun{}
|
||||||
if err := json.Unmarshal(body, apiRun); err != nil {
|
if err := json.Unmarshal(body, apiRun); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -191,18 +191,18 @@ func (b *builderClient) run() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
_, _, err = b.cli.call("POST", "/containers/"+apiRun.Id+"/start", nil)
|
_, _, err = b.cli.call("POST", "/containers/"+apiRun.ID+"/start", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
b.tmpContainers[apiRun.Id] = struct{}{}
|
b.tmpContainers[apiRun.ID] = struct{}{}
|
||||||
|
|
||||||
// Wait for it to finish
|
// Wait for it to finish
|
||||||
body, _, err = b.cli.call("POST", "/containers/"+apiRun.Id+"/wait", nil)
|
body, _, err = b.cli.call("POST", "/containers/"+apiRun.ID+"/wait", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
apiWait := &ApiWait{}
|
apiWait := &APIWait{}
|
||||||
if err := json.Unmarshal(body, apiWait); err != nil {
|
if err := json.Unmarshal(body, apiWait); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ func (b *builderClient) run() (string, error) {
|
||||||
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, apiWait.StatusCode)
|
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, apiWait.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiRun.Id, nil
|
return apiRun.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *builderClient) commit(id string) error {
|
func (b *builderClient) commit(id string) error {
|
||||||
|
@ -239,12 +239,12 @@ func (b *builderClient) commit(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
apiId := &ApiId{}
|
apiID := &APIID{}
|
||||||
if err := json.Unmarshal(body, apiId); err != nil {
|
if err := json.Unmarshal(body, apiID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.tmpImages[apiId.Id] = struct{}{}
|
b.tmpImages[apiID.ID] = struct{}{}
|
||||||
b.image = apiId.Id
|
b.image = apiID.ID
|
||||||
b.needCommit = false
|
b.needCommit = false
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
14
buildfile.go
14
buildfile.go
|
@ -73,7 +73,7 @@ func (b *buildFile) CmdFrom(name string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.image = image.Id
|
b.image = image.ID
|
||||||
b.config = &Config{}
|
b.config = &Config{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func (b *buildFile) CmdRun(args string) error {
|
||||||
return err
|
return err
|
||||||
} else if cache != nil {
|
} else if cache != nil {
|
||||||
utils.Debugf("[BUILDER] Use cached version")
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
b.image = cache.Id
|
b.image = cache.ID
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
utils.Debugf("[BUILDER] Cache miss")
|
utils.Debugf("[BUILDER] Cache miss")
|
||||||
|
@ -238,7 +238,7 @@ func (b *buildFile) run() (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
b.tmpContainers[c.Id] = struct{}{}
|
b.tmpContainers[c.ID] = struct{}{}
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
if err := c.Start(); err != nil {
|
if err := c.Start(); err != nil {
|
||||||
|
@ -250,7 +250,7 @@ func (b *buildFile) run() (string, error) {
|
||||||
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret)
|
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Id, nil
|
return c.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit the container <id> with the autorun command <autoCmd>
|
// Commit the container <id> with the autorun command <autoCmd>
|
||||||
|
@ -266,7 +266,7 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
||||||
return err
|
return err
|
||||||
} else if cache != nil {
|
} else if cache != nil {
|
||||||
utils.Debugf("[BUILDER] Use cached version")
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
b.image = cache.Id
|
b.image = cache.ID
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
utils.Debugf("[BUILDER] Cache miss")
|
utils.Debugf("[BUILDER] Cache miss")
|
||||||
|
@ -292,8 +292,8 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.tmpImages[image.Id] = struct{}{}
|
b.tmpImages[image.ID] = struct{}{}
|
||||||
b.image = image.Id
|
b.image = image.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestBuild(t *testing.T) {
|
||||||
|
|
||||||
buildfile := NewBuildFile(srv, &utils.NopWriter{})
|
buildfile := NewBuildFile(srv, &utils.NopWriter{})
|
||||||
|
|
||||||
imgId, err := buildfile.Build(strings.NewReader(Dockerfile), nil)
|
imgID, err := buildfile.Build(strings.NewReader(Dockerfile), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func TestBuild(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
container, err := builder.Create(
|
container, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: imgId,
|
Image: imgID,
|
||||||
Cmd: []string{"cat", "/tmp/passwd"},
|
Cmd: []string{"cat", "/tmp/passwd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,7 @@ func TestBuild(t *testing.T) {
|
||||||
|
|
||||||
container2, err := builder.Create(
|
container2, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: imgId,
|
Image: imgID,
|
||||||
Cmd: []string{"ls", "-d", "/var/run/sshd"},
|
Cmd: []string{"ls", "-d", "/var/run/sshd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
62
commands.go
62
commands.go
|
@ -31,7 +31,7 @@ import (
|
||||||
const VERSION = "0.4.0"
|
const VERSION = "0.4.0"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GIT_COMMIT string
|
GITCOMMIT string
|
||||||
)
|
)
|
||||||
|
|
||||||
func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) {
|
func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) {
|
||||||
|
@ -330,7 +330,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var out2 ApiAuth
|
var out2 APIAuth
|
||||||
err = json.Unmarshal(body, &out2)
|
err = json.Unmarshal(body, &out2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -357,7 +357,7 @@ func (cli *DockerCli) CmdWait(args ...string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s", err)
|
fmt.Printf("%s", err)
|
||||||
} else {
|
} else {
|
||||||
var out ApiWait
|
var out APIWait
|
||||||
err = json.Unmarshal(body, &out)
|
err = json.Unmarshal(body, &out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -385,7 +385,7 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var out ApiVersion
|
var out APIVersion
|
||||||
err = json.Unmarshal(body, &out)
|
err = json.Unmarshal(body, &out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
|
utils.Debugf("Error unmarshal: body: %s, err: %s\n", body, err)
|
||||||
|
@ -418,7 +418,7 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var out ApiInfo
|
var out APIInfo
|
||||||
if err := json.Unmarshal(body, &out); err != nil {
|
if err := json.Unmarshal(body, &out); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -603,7 +603,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var outs []ApiHistory
|
var outs []APIHistory
|
||||||
err = json.Unmarshal(body, &outs)
|
err = json.Unmarshal(body, &outs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -612,7 +612,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
||||||
fmt.Fprintln(w, "ID\tCREATED\tCREATED BY")
|
fmt.Fprintln(w, "ID\tCREATED\tCREATED BY")
|
||||||
|
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.Id, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
|
fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
return nil
|
return nil
|
||||||
|
@ -785,7 +785,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var outs []ApiImages
|
var outs []APIImages
|
||||||
err = json.Unmarshal(body, &outs)
|
err = json.Unmarshal(body, &outs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -807,16 +807,16 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
fmt.Fprintf(w, "%s\t%s\t", out.Repository, out.Tag)
|
fmt.Fprintf(w, "%s\t%s\t", out.Repository, out.Tag)
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
fmt.Fprintf(w, "%s\t", out.Id)
|
fmt.Fprintf(w, "%s\t", out.ID)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s\t", utils.TruncateId(out.Id))
|
fmt.Fprintf(w, "%s\t", utils.TruncateID(out.ID))
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "%s ago\n", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
|
fmt.Fprintf(w, "%s ago\n", utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))))
|
||||||
} else {
|
} else {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
fmt.Fprintln(w, out.Id)
|
fmt.Fprintln(w, out.ID)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, utils.TruncateId(out.Id))
|
fmt.Fprintln(w, utils.TruncateID(out.ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -863,7 +863,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var outs []ApiContainers
|
var outs []APIContainers
|
||||||
err = json.Unmarshal(body, &outs)
|
err = json.Unmarshal(body, &outs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -876,15 +876,15 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
||||||
for _, out := range outs {
|
for _, out := range outs {
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", out.Id, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", out.ID, out.Image, out.Command, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", utils.TruncateId(out.Id), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\n", utils.TruncateID(out.ID), out.Image, utils.Trunc(out.Command, 20), utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.Status, out.Ports)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if *noTrunc {
|
if *noTrunc {
|
||||||
fmt.Fprintln(w, out.Id)
|
fmt.Fprintln(w, out.ID)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, utils.TruncateId(out.Id))
|
fmt.Fprintln(w, utils.TruncateID(out.ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -927,13 +927,13 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
apiId := &ApiId{}
|
apiID := &APIID{}
|
||||||
err = json.Unmarshal(body, apiId)
|
err = json.Unmarshal(body, apiID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(apiId.Id)
|
fmt.Println(apiID.ID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1070,7 +1070,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
outs := []ApiSearch{}
|
outs := []APISearch{}
|
||||||
err = json.Unmarshal(body, &outs)
|
err = json.Unmarshal(body, &outs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1202,7 +1202,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
out := &ApiRun{}
|
out := &APIRun{}
|
||||||
err = json.Unmarshal(body, out)
|
err = json.Unmarshal(body, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1223,18 +1223,18 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
_, _, err = cli.call("POST", "/containers/"+out.Id+"/start", nil)
|
_, _, err = cli.call("POST", "/containers/"+out.ID+"/start", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if connections > 0 {
|
if connections > 0 {
|
||||||
chErrors := make(chan error, connections)
|
chErrors := make(chan error, connections)
|
||||||
cli.monitorTtySize(out.Id)
|
cli.monitorTtySize(out.ID)
|
||||||
|
|
||||||
if splitStderr && config.AttachStderr {
|
if splitStderr && config.AttachStderr {
|
||||||
go func() {
|
go func() {
|
||||||
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
chErrors <- cli.hijack("POST", "/containers/"+out.ID+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1252,7 +1252,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
||||||
v.Set("stderr", "1")
|
v.Set("stderr", "1")
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
chErrors <- cli.hijack("POST", "/containers/"+out.Id+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
chErrors <- cli.hijack("POST", "/containers/"+out.ID+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
||||||
}()
|
}()
|
||||||
for connections > 0 {
|
for connections > 0 {
|
||||||
err := <-chErrors
|
err := <-chErrors
|
||||||
|
@ -1263,7 +1263,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !config.AttachStdout && !config.AttachStderr {
|
if !config.AttachStdout && !config.AttachStderr {
|
||||||
fmt.Println(out.Id)
|
fmt.Println(out.ID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1312,7 +1312,7 @@ func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int,
|
||||||
params = bytes.NewBuffer(buf)
|
params = bytes.NewBuffer(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), params)
|
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, APIVERSION, path), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
|
@ -1344,7 +1344,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
||||||
if (method == "POST" || method == "PUT") && in == nil {
|
if (method == "POST" || method == "PUT") && in == nil {
|
||||||
in = bytes.NewReader([]byte{})
|
in = bytes.NewReader([]byte{})
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, API_VERSION, path), in)
|
req, err := http.NewRequest(method, fmt.Sprintf("http://%s:%d/v%g%s", cli.host, cli.port, APIVERSION, path), in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1371,7 +1371,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
||||||
if resp.Header.Get("Content-Type") == "application/json" {
|
if resp.Header.Get("Content-Type") == "application/json" {
|
||||||
dec := json.NewDecoder(resp.Body)
|
dec := json.NewDecoder(resp.Body)
|
||||||
for {
|
for {
|
||||||
var m utils.JsonMessage
|
var m utils.JSONMessage
|
||||||
if err := dec.Decode(&m); err == io.EOF {
|
if err := dec.Decode(&m); err == io.EOF {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -1394,7 +1394,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer) e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error {
|
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in *os.File, out io.Writer) error {
|
||||||
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", API_VERSION, path), nil)
|
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
60
container.go
60
container.go
|
@ -23,7 +23,7 @@ import (
|
||||||
type Container struct {
|
type Container struct {
|
||||||
root string
|
root string
|
||||||
|
|
||||||
Id string
|
ID string
|
||||||
|
|
||||||
Created time.Time
|
Created time.Time
|
||||||
|
|
||||||
|
@ -167,8 +167,8 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *flag.FlagSet
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetworkSettings struct {
|
type NetworkSettings struct {
|
||||||
IpAddress string
|
IPAddress string
|
||||||
IpPrefixLen int
|
IPPrefixLen int
|
||||||
Gateway string
|
Gateway string
|
||||||
Bridge string
|
Bridge string
|
||||||
PortMapping map[string]string
|
PortMapping map[string]string
|
||||||
|
@ -409,7 +409,7 @@ func (container *Container) Start() error {
|
||||||
defer container.State.unlock()
|
defer container.State.unlock()
|
||||||
|
|
||||||
if container.State.Running {
|
if container.State.Running {
|
||||||
return fmt.Errorf("The container %s is already running.", container.Id)
|
return fmt.Errorf("The container %s is already running.", container.ID)
|
||||||
}
|
}
|
||||||
if err := container.EnsureMounted(); err != nil {
|
if err := container.EnsureMounted(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -438,17 +438,17 @@ func (container *Container) Start() error {
|
||||||
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
container.Volumes[volPath] = c.Id
|
container.Volumes[volPath] = c.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
if container.Config.VolumesFrom != "" {
|
if container.Config.VolumesFrom != "" {
|
||||||
c := container.runtime.Get(container.Config.VolumesFrom)
|
c := container.runtime.Get(container.Config.VolumesFrom)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return fmt.Errorf("Container %s not found. Impossible to mount its volumes", container.Id)
|
return fmt.Errorf("Container %s not found. Impossible to mount its volumes", container.ID)
|
||||||
}
|
}
|
||||||
for volPath, id := range c.Volumes {
|
for volPath, id := range c.Volumes {
|
||||||
if _, exists := container.Volumes[volPath]; exists {
|
if _, exists := container.Volumes[volPath]; exists {
|
||||||
return fmt.Errorf("The requested volume %s overlap one of the volume of the container %s", volPath, c.Id)
|
return fmt.Errorf("The requested volume %s overlap one of the volume of the container %s", volPath, c.ID)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -462,7 +462,7 @@ func (container *Container) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
params := []string{
|
params := []string{
|
||||||
"-n", container.Id,
|
"-n", container.ID,
|
||||||
"-f", container.lxcConfigPath(),
|
"-f", container.lxcConfigPath(),
|
||||||
"--",
|
"--",
|
||||||
"/sbin/init",
|
"/sbin/init",
|
||||||
|
@ -582,8 +582,8 @@ func (container *Container) allocateNetwork() error {
|
||||||
}
|
}
|
||||||
container.network = iface
|
container.network = iface
|
||||||
container.NetworkSettings.Bridge = container.runtime.networkManager.bridgeIface
|
container.NetworkSettings.Bridge = container.runtime.networkManager.bridgeIface
|
||||||
container.NetworkSettings.IpAddress = iface.IPNet.IP.String()
|
container.NetworkSettings.IPAddress = iface.IPNet.IP.String()
|
||||||
container.NetworkSettings.IpPrefixLen, _ = iface.IPNet.Mask.Size()
|
container.NetworkSettings.IPPrefixLen, _ = iface.IPNet.Mask.Size()
|
||||||
container.NetworkSettings.Gateway = iface.Gateway.String()
|
container.NetworkSettings.Gateway = iface.Gateway.String()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ func (container *Container) releaseNetwork() {
|
||||||
// FIXME: replace this with a control socket within docker-init
|
// FIXME: replace this with a control socket within docker-init
|
||||||
func (container *Container) waitLxc() error {
|
func (container *Container) waitLxc() error {
|
||||||
for {
|
for {
|
||||||
output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput()
|
output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -615,12 +615,12 @@ func (container *Container) monitor() {
|
||||||
// If the command does not exists, try to wait via lxc
|
// If the command does not exists, try to wait via lxc
|
||||||
if container.cmd == nil {
|
if container.cmd == nil {
|
||||||
if err := container.waitLxc(); err != nil {
|
if err := container.waitLxc(); err != nil {
|
||||||
utils.Debugf("%s: Process: %s", container.Id, err)
|
utils.Debugf("%s: Process: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := container.cmd.Wait(); err != nil {
|
if err := container.cmd.Wait(); err != nil {
|
||||||
// Discard the error as any signals or non 0 returns will generate an error
|
// Discard the error as any signals or non 0 returns will generate an error
|
||||||
utils.Debugf("%s: Process: %s", container.Id, err)
|
utils.Debugf("%s: Process: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.Debugf("Process finished")
|
utils.Debugf("Process finished")
|
||||||
|
@ -634,24 +634,24 @@ func (container *Container) monitor() {
|
||||||
container.releaseNetwork()
|
container.releaseNetwork()
|
||||||
if container.Config.OpenStdin {
|
if container.Config.OpenStdin {
|
||||||
if err := container.stdin.Close(); err != nil {
|
if err := container.stdin.Close(); err != nil {
|
||||||
utils.Debugf("%s: Error close stdin: %s", container.Id, err)
|
utils.Debugf("%s: Error close stdin: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := container.stdout.CloseWriters(); err != nil {
|
if err := container.stdout.CloseWriters(); err != nil {
|
||||||
utils.Debugf("%s: Error close stdout: %s", container.Id, err)
|
utils.Debugf("%s: Error close stdout: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
if err := container.stderr.CloseWriters(); err != nil {
|
if err := container.stderr.CloseWriters(); err != nil {
|
||||||
utils.Debugf("%s: Error close stderr: %s", container.Id, err)
|
utils.Debugf("%s: Error close stderr: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if container.ptyMaster != nil {
|
if container.ptyMaster != nil {
|
||||||
if err := container.ptyMaster.Close(); err != nil {
|
if err := container.ptyMaster.Close(); err != nil {
|
||||||
utils.Debugf("%s: Error closing Pty master: %s", container.Id, err)
|
utils.Debugf("%s: Error closing Pty master: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.Unmount(); err != nil {
|
if err := container.Unmount(); err != nil {
|
||||||
log.Printf("%v: Failed to umount filesystem: %v", container.Id, err)
|
log.Printf("%v: Failed to umount filesystem: %v", container.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-create a brand new stdin pipe once the container exited
|
// Re-create a brand new stdin pipe once the container exited
|
||||||
|
@ -672,7 +672,7 @@ func (container *Container) monitor() {
|
||||||
// This is because State.setStopped() has already been called, and has caused Wait()
|
// This is because State.setStopped() has already been called, and has caused Wait()
|
||||||
// to return.
|
// to return.
|
||||||
// FIXME: why are we serializing running state to disk in the first place?
|
// FIXME: why are we serializing running state to disk in the first place?
|
||||||
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.Id, err)
|
//log.Printf("%s: Failed to dump configuration to the disk: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,17 +682,17 @@ func (container *Container) kill() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sending SIGKILL to the process via lxc
|
// Sending SIGKILL to the process via lxc
|
||||||
output, err := exec.Command("lxc-kill", "-n", container.Id, "9").CombinedOutput()
|
output, err := exec.Command("lxc-kill", "-n", container.ID, "9").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error killing container %s (%s, %s)", container.Id, output, err)
|
log.Printf("error killing container %s (%s, %s)", container.ID, output, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Wait for the process to die, in last resort, try to kill the process directly
|
// 2. Wait for the process to die, in last resort, try to kill the process directly
|
||||||
if err := container.WaitTimeout(10 * time.Second); err != nil {
|
if err := container.WaitTimeout(10 * time.Second); err != nil {
|
||||||
if container.cmd == nil {
|
if container.cmd == nil {
|
||||||
return fmt.Errorf("lxc-kill failed, impossible to kill the container %s", container.Id)
|
return fmt.Errorf("lxc-kill failed, impossible to kill the container %s", container.ID)
|
||||||
}
|
}
|
||||||
log.Printf("Container %s failed to exit within 10 seconds of lxc SIGKILL - trying direct SIGKILL", container.Id)
|
log.Printf("Container %s failed to exit within 10 seconds of lxc SIGKILL - trying direct SIGKILL", container.ID)
|
||||||
if err := container.cmd.Process.Kill(); err != nil {
|
if err := container.cmd.Process.Kill(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -720,7 +720,7 @@ func (container *Container) Stop(seconds int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Send a SIGTERM
|
// 1. Send a SIGTERM
|
||||||
if output, err := exec.Command("lxc-kill", "-n", container.Id, "15").CombinedOutput(); err != nil {
|
if output, err := exec.Command("lxc-kill", "-n", container.ID, "15").CombinedOutput(); err != nil {
|
||||||
log.Print(string(output))
|
log.Print(string(output))
|
||||||
log.Print("Failed to send SIGTERM to the process, force killing")
|
log.Print("Failed to send SIGTERM to the process, force killing")
|
||||||
if err := container.kill(); err != nil {
|
if err := container.kill(); err != nil {
|
||||||
|
@ -730,7 +730,7 @@ func (container *Container) Stop(seconds int) error {
|
||||||
|
|
||||||
// 2. Wait for the process to exit on its own
|
// 2. Wait for the process to exit on its own
|
||||||
if err := container.WaitTimeout(time.Duration(seconds) * time.Second); err != nil {
|
if err := container.WaitTimeout(time.Duration(seconds) * time.Second); err != nil {
|
||||||
log.Printf("Container %v failed to exit within %d seconds of SIGTERM - using the force", container.Id, seconds)
|
log.Printf("Container %v failed to exit within %d seconds of SIGTERM - using the force", container.ID, seconds)
|
||||||
if err := container.kill(); err != nil {
|
if err := container.kill(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -836,16 +836,16 @@ func (container *Container) Unmount() error {
|
||||||
return Unmount(container.RootfsPath())
|
return Unmount(container.RootfsPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShortId returns a shorthand version of the container's id for convenience.
|
// ShortID returns a shorthand version of the container's id for convenience.
|
||||||
// A collision with other container shorthands is very unlikely, but possible.
|
// A collision with other container shorthands is very unlikely, but possible.
|
||||||
// In case of a collision a lookup with Runtime.Get() will fail, and the caller
|
// In case of a collision a lookup with Runtime.Get() will fail, and the caller
|
||||||
// will need to use a langer prefix, or the full-length container Id.
|
// will need to use a langer prefix, or the full-length container Id.
|
||||||
func (container *Container) ShortId() string {
|
func (container *Container) ShortID() string {
|
||||||
return utils.TruncateId(container.Id)
|
return utils.TruncateID(container.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) logPath(name string) string {
|
func (container *Container) logPath(name string) string {
|
||||||
return path.Join(container.root, fmt.Sprintf("%s-%s.log", container.Id, name))
|
return path.Join(container.root, fmt.Sprintf("%s-%s.log", container.ID, name))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) ReadLog(name string) (io.Reader, error) {
|
func (container *Container) ReadLog(name string) (io.Reader, error) {
|
||||||
|
@ -885,7 +885,7 @@ func (container *Container) rwPath() string {
|
||||||
return path.Join(container.root, "rw")
|
return path.Join(container.root, "rw")
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateId(id string) error {
|
func validateID(id string) error {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("Invalid empty id")
|
return fmt.Errorf("Invalid empty id")
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIdFormat(t *testing.T) {
|
func TestIDFormat(t *testing.T) {
|
||||||
runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -22,19 +22,19 @@ func TestIdFormat(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container1, err := NewBuilder(runtime).Create(
|
container1, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/sh", "-c", "echo hello world"},
|
Cmd: []string{"/bin/sh", "-c", "echo hello world"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
match, err := regexp.Match("^[0-9a-f]{64}$", []byte(container1.Id))
|
match, err := regexp.Match("^[0-9a-f]{64}$", []byte(container1.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
t.Fatalf("Invalid container ID: %s", container1.Id)
|
t.Fatalf("Invalid container ID: %s", container1.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func TestMultipleAttachRestart(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/sh", "-c",
|
Cmd: []string{"/bin/sh", "-c",
|
||||||
"i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"},
|
"i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"},
|
||||||
},
|
},
|
||||||
|
@ -153,7 +153,7 @@ func TestDiff(t *testing.T) {
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container1, err := builder.Create(
|
container1, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/rm", "/etc/passwd"},
|
Cmd: []string{"/bin/rm", "/etc/passwd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -194,7 +194,7 @@ func TestDiff(t *testing.T) {
|
||||||
// Create a new container from the commited image
|
// Create a new container from the commited image
|
||||||
container2, err := builder.Create(
|
container2, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: img.Id,
|
Image: img.ID,
|
||||||
Cmd: []string{"cat", "/etc/passwd"},
|
Cmd: []string{"cat", "/etc/passwd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -221,7 +221,7 @@ func TestDiff(t *testing.T) {
|
||||||
// Create a new containere
|
// Create a new containere
|
||||||
container3, err := builder.Create(
|
container3, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"rm", "/bin/httpd"},
|
Cmd: []string{"rm", "/bin/httpd"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -260,7 +260,7 @@ func TestCommitAutoRun(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
container1, err := builder.Create(
|
container1, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -291,7 +291,7 @@ func TestCommitAutoRun(t *testing.T) {
|
||||||
// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
|
// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
|
||||||
container2, err := builder.Create(
|
container2, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: img.Id,
|
Image: img.ID,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -340,7 +340,7 @@ func TestCommitRun(t *testing.T) {
|
||||||
|
|
||||||
container1, err := builder.Create(
|
container1, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -372,7 +372,7 @@ func TestCommitRun(t *testing.T) {
|
||||||
|
|
||||||
container2, err := builder.Create(
|
container2, err := builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: img.Id,
|
Image: img.ID,
|
||||||
Cmd: []string{"cat", "/world"},
|
Cmd: []string{"cat", "/world"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -419,7 +419,7 @@ func TestStart(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Memory: 33554432,
|
Memory: 33554432,
|
||||||
CpuShares: 1000,
|
CpuShares: 1000,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
|
@ -463,7 +463,7 @@ func TestRun(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -491,7 +491,7 @@ func TestOutput(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(
|
container, err := NewBuilder(runtime).Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "-n", "foobar"},
|
Cmd: []string{"echo", "-n", "foobar"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -515,7 +515,7 @@ func TestKillDifferentUser(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"tail", "-f", "/etc/resolv.conf"},
|
Cmd: []string{"tail", "-f", "/etc/resolv.conf"},
|
||||||
User: "daemon",
|
User: "daemon",
|
||||||
},
|
},
|
||||||
|
@ -563,7 +563,7 @@ func TestKill(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat", "/dev/zero"},
|
Cmd: []string{"cat", "/dev/zero"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -611,7 +611,7 @@ func TestExitCode(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
|
|
||||||
trueContainer, err := builder.Create(&Config{
|
trueContainer, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/true", ""},
|
Cmd: []string{"/bin/true", ""},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -626,7 +626,7 @@ func TestExitCode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
falseContainer, err := builder.Create(&Config{
|
falseContainer, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/false", ""},
|
Cmd: []string{"/bin/false", ""},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -648,7 +648,7 @@ func TestRestart(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "-n", "foobar"},
|
Cmd: []string{"echo", "-n", "foobar"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -681,7 +681,7 @@ func TestRestartStdin(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat"},
|
Cmd: []string{"cat"},
|
||||||
|
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
|
@ -763,7 +763,7 @@ func TestUser(t *testing.T) {
|
||||||
|
|
||||||
// Default user must be root
|
// Default user must be root
|
||||||
container, err := builder.Create(&Config{
|
container, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"id"},
|
Cmd: []string{"id"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -781,7 +781,7 @@ func TestUser(t *testing.T) {
|
||||||
|
|
||||||
// Set a username
|
// Set a username
|
||||||
container, err = builder.Create(&Config{
|
container, err = builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"id"},
|
Cmd: []string{"id"},
|
||||||
|
|
||||||
User: "root",
|
User: "root",
|
||||||
|
@ -801,7 +801,7 @@ func TestUser(t *testing.T) {
|
||||||
|
|
||||||
// Set a UID
|
// Set a UID
|
||||||
container, err = builder.Create(&Config{
|
container, err = builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"id"},
|
Cmd: []string{"id"},
|
||||||
|
|
||||||
User: "0",
|
User: "0",
|
||||||
|
@ -821,7 +821,7 @@ func TestUser(t *testing.T) {
|
||||||
|
|
||||||
// Set a different user by uid
|
// Set a different user by uid
|
||||||
container, err = builder.Create(&Config{
|
container, err = builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"id"},
|
Cmd: []string{"id"},
|
||||||
|
|
||||||
User: "1",
|
User: "1",
|
||||||
|
@ -843,7 +843,7 @@ func TestUser(t *testing.T) {
|
||||||
|
|
||||||
// Set a different user by username
|
// Set a different user by username
|
||||||
container, err = builder.Create(&Config{
|
container, err = builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"id"},
|
Cmd: []string{"id"},
|
||||||
|
|
||||||
User: "daemon",
|
User: "daemon",
|
||||||
|
@ -872,7 +872,7 @@ func TestMultipleContainers(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
|
|
||||||
container1, err := builder.Create(&Config{
|
container1, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat", "/dev/zero"},
|
Cmd: []string{"cat", "/dev/zero"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -882,7 +882,7 @@ func TestMultipleContainers(t *testing.T) {
|
||||||
defer runtime.Destroy(container1)
|
defer runtime.Destroy(container1)
|
||||||
|
|
||||||
container2, err := builder.Create(&Config{
|
container2, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat", "/dev/zero"},
|
Cmd: []string{"cat", "/dev/zero"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -928,7 +928,7 @@ func TestStdin(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat"},
|
Cmd: []string{"cat"},
|
||||||
|
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
|
@ -975,7 +975,7 @@ func TestTty(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"cat"},
|
Cmd: []string{"cat"},
|
||||||
|
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
|
@ -1022,7 +1022,7 @@ func TestEnv(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/usr/bin/env"},
|
Cmd: []string{"/usr/bin/env"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1100,7 +1100,7 @@ func TestLXCConfig(t *testing.T) {
|
||||||
cpuMax := 10000
|
cpuMax := 10000
|
||||||
cpu := cpuMin + rand.Intn(cpuMax-cpuMin)
|
cpu := cpuMin + rand.Intn(cpuMax-cpuMin)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/bin/true"},
|
Cmd: []string{"/bin/true"},
|
||||||
|
|
||||||
Hostname: "foobar",
|
Hostname: "foobar",
|
||||||
|
@ -1128,7 +1128,7 @@ func BenchmarkRunSequencial(b *testing.B) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "-n", "foo"},
|
Cmd: []string{"echo", "-n", "foo"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1163,7 +1163,7 @@ func BenchmarkRunParallel(b *testing.B) {
|
||||||
tasks = append(tasks, complete)
|
tasks = append(tasks, complete)
|
||||||
go func(i int, complete chan error) {
|
go func(i int, complete chan error) {
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"echo", "-n", "foo"},
|
Cmd: []string{"echo", "-n", "foo"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,13 +11,13 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DOCKER_PATH = path.Join(os.Getenv("DOCKERPATH"), "docker")
|
var DOCKERPATH = path.Join(os.Getenv("DOCKERPATH"), "docker")
|
||||||
|
|
||||||
// WARNING: this crashTest will 1) crash your host, 2) remove all containers
|
// WARNING: this crashTest will 1) crash your host, 2) remove all containers
|
||||||
func runDaemon() (*exec.Cmd, error) {
|
func runDaemon() (*exec.Cmd, error) {
|
||||||
os.Remove("/var/run/docker.pid")
|
os.Remove("/var/run/docker.pid")
|
||||||
exec.Command("rm", "-rf", "/var/lib/docker/containers").Run()
|
exec.Command("rm", "-rf", "/var/lib/docker/containers").Run()
|
||||||
cmd := exec.Command(DOCKER_PATH, "-d")
|
cmd := exec.Command(DOCKERPATH, "-d")
|
||||||
outPipe, err := cmd.StdoutPipe()
|
outPipe, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -77,7 +77,7 @@ func crashTest() error {
|
||||||
stop = false
|
stop = false
|
||||||
for i := 0; i < 100 && !stop; {
|
for i := 0; i < 100 && !stop; {
|
||||||
func() error {
|
func() error {
|
||||||
cmd := exec.Command(DOCKER_PATH, "run", "base", "echo", fmt.Sprintf("%d", totalTestCount))
|
cmd := exec.Command(DOCKERPATH, "run", "base", "echo", fmt.Sprintf("%d", totalTestCount))
|
||||||
i++
|
i++
|
||||||
totalTestCount++
|
totalTestCount++
|
||||||
outPipe, err := cmd.StdoutPipe()
|
outPipe, err := cmd.StdoutPipe()
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GIT_COMMIT string
|
GITCOMMIT string
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -59,7 +59,7 @@ func main() {
|
||||||
if *flDebug {
|
if *flDebug {
|
||||||
os.Setenv("DEBUG", "1")
|
os.Setenv("DEBUG", "1")
|
||||||
}
|
}
|
||||||
docker.GIT_COMMIT = GIT_COMMIT
|
docker.GITCOMMIT = GITCOMMIT
|
||||||
if *flDaemon {
|
if *flDaemon {
|
||||||
if flag.NArg() != 0 {
|
if flag.NArg() != 0 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
|
|
42
graph.go
42
graph.go
|
@ -86,14 +86,14 @@ func (graph *Graph) Get(name string) (*Image, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if img.Id != id {
|
if img.ID != id {
|
||||||
return nil, fmt.Errorf("Image stored at '%s' has wrong id '%s'", id, img.Id)
|
return nil, fmt.Errorf("Image stored at '%s' has wrong id '%s'", id, img.ID)
|
||||||
}
|
}
|
||||||
img.graph = graph
|
img.graph = graph
|
||||||
graph.lockSumMap.Lock()
|
graph.lockSumMap.Lock()
|
||||||
defer graph.lockSumMap.Unlock()
|
defer graph.lockSumMap.Unlock()
|
||||||
if _, exists := graph.checksumLock[img.Id]; !exists {
|
if _, exists := graph.checksumLock[img.ID]; !exists {
|
||||||
graph.checksumLock[img.Id] = &sync.Mutex{}
|
graph.checksumLock[img.ID] = &sync.Mutex{}
|
||||||
}
|
}
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func (graph *Graph) Get(name string) (*Image, error) {
|
||||||
// Create creates a new image and registers it in the graph.
|
// Create creates a new image and registers it in the graph.
|
||||||
func (graph *Graph) Create(layerData Archive, container *Container, comment, author string, config *Config) (*Image, error) {
|
func (graph *Graph) Create(layerData Archive, container *Container, comment, author string, config *Config) (*Image, error) {
|
||||||
img := &Image{
|
img := &Image{
|
||||||
Id: GenerateId(),
|
ID: GenerateID(),
|
||||||
Comment: comment,
|
Comment: comment,
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
DockerVersion: VERSION,
|
DockerVersion: VERSION,
|
||||||
|
@ -111,7 +111,7 @@ func (graph *Graph) Create(layerData Archive, container *Container, comment, aut
|
||||||
}
|
}
|
||||||
if container != nil {
|
if container != nil {
|
||||||
img.Parent = container.Image
|
img.Parent = container.Image
|
||||||
img.Container = container.Id
|
img.Container = container.ID
|
||||||
img.ContainerConfig = *container.Config
|
img.ContainerConfig = *container.Config
|
||||||
}
|
}
|
||||||
if err := graph.Register(layerData, layerData != nil, img); err != nil {
|
if err := graph.Register(layerData, layerData != nil, img); err != nil {
|
||||||
|
@ -124,12 +124,12 @@ func (graph *Graph) Create(layerData Archive, container *Container, comment, aut
|
||||||
// Register imports a pre-existing image into the graph.
|
// Register imports a pre-existing image into the graph.
|
||||||
// FIXME: pass img as first argument
|
// FIXME: pass img as first argument
|
||||||
func (graph *Graph) Register(layerData Archive, store bool, img *Image) error {
|
func (graph *Graph) Register(layerData Archive, store bool, img *Image) error {
|
||||||
if err := ValidateId(img.Id); err != nil {
|
if err := ValidateID(img.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// (This is a convenience to save time. Race conditions are taken care of by os.Rename)
|
// (This is a convenience to save time. Race conditions are taken care of by os.Rename)
|
||||||
if graph.Exists(img.Id) {
|
if graph.Exists(img.ID) {
|
||||||
return fmt.Errorf("Image %s already exists", img.Id)
|
return fmt.Errorf("Image %s already exists", img.ID)
|
||||||
}
|
}
|
||||||
tmp, err := graph.Mktemp("")
|
tmp, err := graph.Mktemp("")
|
||||||
defer os.RemoveAll(tmp)
|
defer os.RemoveAll(tmp)
|
||||||
|
@ -140,12 +140,12 @@ func (graph *Graph) Register(layerData Archive, store bool, img *Image) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Commit
|
// Commit
|
||||||
if err := os.Rename(tmp, graph.imageRoot(img.Id)); err != nil {
|
if err := os.Rename(tmp, graph.imageRoot(img.ID)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
img.graph = graph
|
img.graph = graph
|
||||||
graph.idIndex.Add(img.Id)
|
graph.idIndex.Add(img.ID)
|
||||||
graph.checksumLock[img.Id] = &sync.Mutex{}
|
graph.checksumLock[img.ID] = &sync.Mutex{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ func (graph *Graph) TempLayerArchive(id string, compression Compression, output
|
||||||
// Mktemp creates a temporary sub-directory inside the graph's filesystem.
|
// Mktemp creates a temporary sub-directory inside the graph's filesystem.
|
||||||
func (graph *Graph) Mktemp(id string) (string, error) {
|
func (graph *Graph) Mktemp(id string) (string, error) {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
id = GenerateId()
|
id = GenerateID()
|
||||||
}
|
}
|
||||||
tmp, err := graph.tmp()
|
tmp, err := graph.tmp()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -230,7 +230,7 @@ func (graph *Graph) Map() (map[string]*Image, error) {
|
||||||
}
|
}
|
||||||
images := make(map[string]*Image, len(all))
|
images := make(map[string]*Image, len(all))
|
||||||
for _, image := range all {
|
for _, image := range all {
|
||||||
images[image.Id] = image
|
images[image.ID] = image
|
||||||
}
|
}
|
||||||
return images, nil
|
return images, nil
|
||||||
}
|
}
|
||||||
|
@ -273,10 +273,10 @@ func (graph *Graph) ByParent() (map[string][]*Image, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if children, exists := byParent[parent.Id]; exists {
|
if children, exists := byParent[parent.ID]; exists {
|
||||||
byParent[parent.Id] = []*Image{image}
|
byParent[parent.ID] = []*Image{image}
|
||||||
} else {
|
} else {
|
||||||
byParent[parent.Id] = append(children, image)
|
byParent[parent.ID] = append(children, image)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return byParent, err
|
return byParent, err
|
||||||
|
@ -293,8 +293,8 @@ func (graph *Graph) Heads() (map[string]*Image, error) {
|
||||||
err = graph.WalkAll(func(image *Image) {
|
err = graph.WalkAll(func(image *Image) {
|
||||||
// If it's not in the byParent lookup table, then
|
// If it's not in the byParent lookup table, then
|
||||||
// it's not a parent -> so it's a head!
|
// it's not a parent -> so it's a head!
|
||||||
if _, exists := byParent[image.Id]; !exists {
|
if _, exists := byParent[image.ID]; !exists {
|
||||||
heads[image.Id] = image
|
heads[image.ID] = image
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return heads, err
|
return heads, err
|
||||||
|
@ -317,11 +317,11 @@ func (graph *Graph) getStoredChecksums() (map[string]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (graph *Graph) storeChecksums(checksums map[string]string) error {
|
func (graph *Graph) storeChecksums(checksums map[string]string) error {
|
||||||
checksumJson, err := json.Marshal(checksums)
|
checksumJSON, err := json.Marshal(checksums)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(path.Join(graph.Root, "checksums"), checksumJson, 0600); err != nil {
|
if err := ioutil.WriteFile(path.Join(graph.Root, "checksums"), checksumJSON, 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -34,14 +34,14 @@ func TestInterruptedRegister(t *testing.T) {
|
||||||
defer os.RemoveAll(graph.Root)
|
defer os.RemoveAll(graph.Root)
|
||||||
badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data
|
badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data
|
||||||
image := &Image{
|
image := &Image{
|
||||||
Id: GenerateId(),
|
ID: GenerateID(),
|
||||||
Comment: "testing",
|
Comment: "testing",
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
}
|
}
|
||||||
go graph.Register(badArchive, false, image)
|
go graph.Register(badArchive, false, image)
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
w.CloseWithError(errors.New("But I'm not a tarball!")) // (Nobody's perfect, darling)
|
w.CloseWithError(errors.New("But I'm not a tarball!")) // (Nobody's perfect, darling)
|
||||||
if _, err := graph.Get(image.Id); err == nil {
|
if _, err := graph.Get(image.ID); err == nil {
|
||||||
t.Fatal("Image should not exist after Register is interrupted")
|
t.Fatal("Image should not exist after Register is interrupted")
|
||||||
}
|
}
|
||||||
// Registering the same image again should succeed if the first register was interrupted
|
// Registering the same image again should succeed if the first register was interrupted
|
||||||
|
@ -67,7 +67,7 @@ func TestGraphCreate(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := ValidateId(image.Id); err != nil {
|
if err := ValidateID(image.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if image.Comment != "Testing" {
|
if image.Comment != "Testing" {
|
||||||
|
@ -91,7 +91,7 @@ func TestRegister(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
image := &Image{
|
image := &Image{
|
||||||
Id: GenerateId(),
|
ID: GenerateID(),
|
||||||
Comment: "testing",
|
Comment: "testing",
|
||||||
Created: time.Now(),
|
Created: time.Now(),
|
||||||
}
|
}
|
||||||
|
@ -104,11 +104,11 @@ func TestRegister(t *testing.T) {
|
||||||
} else if l := len(images); l != 1 {
|
} else if l := len(images); l != 1 {
|
||||||
t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l)
|
t.Fatalf("Wrong number of images. Should be %d, not %d", 1, l)
|
||||||
}
|
}
|
||||||
if resultImg, err := graph.Get(image.Id); err != nil {
|
if resultImg, err := graph.Get(image.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if resultImg.Id != image.Id {
|
if resultImg.ID != image.ID {
|
||||||
t.Fatalf("Wrong image ID. Should be '%s', not '%s'", image.Id, resultImg.Id)
|
t.Fatalf("Wrong image ID. Should be '%s', not '%s'", image.ID, resultImg.ID)
|
||||||
}
|
}
|
||||||
if resultImg.Comment != image.Comment {
|
if resultImg.Comment != image.Comment {
|
||||||
t.Fatalf("Wrong image comment. Should be '%s', not '%s'", image.Comment, resultImg.Comment)
|
t.Fatalf("Wrong image comment. Should be '%s', not '%s'", image.Comment, resultImg.Comment)
|
||||||
|
@ -156,7 +156,7 @@ func TestDeletePrefix(t *testing.T) {
|
||||||
graph := tempGraph(t)
|
graph := tempGraph(t)
|
||||||
defer os.RemoveAll(graph.Root)
|
defer os.RemoveAll(graph.Root)
|
||||||
img := createTestImage(graph, t)
|
img := createTestImage(graph, t)
|
||||||
if err := graph.Delete(utils.TruncateId(img.Id)); err != nil {
|
if err := graph.Delete(utils.TruncateID(img.ID)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 0)
|
assertNImages(graph, t, 0)
|
||||||
|
@ -187,7 +187,7 @@ func TestDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 1)
|
assertNImages(graph, t, 1)
|
||||||
if err := graph.Delete(img.Id); err != nil {
|
if err := graph.Delete(img.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 0)
|
assertNImages(graph, t, 0)
|
||||||
|
@ -201,7 +201,7 @@ func TestDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 2)
|
assertNImages(graph, t, 2)
|
||||||
if err := graph.Delete(img1.Id); err != nil {
|
if err := graph.Delete(img1.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 1)
|
assertNImages(graph, t, 1)
|
||||||
|
@ -216,7 +216,7 @@ func TestDelete(t *testing.T) {
|
||||||
if err := graph.Register(archive, false, img1); err != nil {
|
if err := graph.Register(archive, false, img1); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := graph.Delete(img1.Id); err != nil {
|
if err := graph.Delete(img1.ID); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assertNImages(graph, t, 1)
|
assertNImages(graph, t, 1)
|
||||||
|
|
32
image.go
32
image.go
|
@ -18,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Parent string `json:"parent,omitempty"`
|
Parent string `json:"parent,omitempty"`
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
|
@ -42,17 +42,17 @@ func LoadImage(root string) (*Image, error) {
|
||||||
if err := json.Unmarshal(jsonData, img); err != nil {
|
if err := json.Unmarshal(jsonData, img); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := ValidateId(img.Id); err != nil {
|
if err := ValidateID(img.ID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Check that the filesystem layer exists
|
// Check that the filesystem layer exists
|
||||||
if stat, err := os.Stat(layerPath(root)); err != nil {
|
if stat, err := os.Stat(layerPath(root)); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, fmt.Errorf("Couldn't load image %s: no filesystem layer", img.Id)
|
return nil, fmt.Errorf("Couldn't load image %s: no filesystem layer", img.ID)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !stat.IsDir() {
|
} else if !stat.IsDir() {
|
||||||
return nil, fmt.Errorf("Couldn't load image %s: %s is not a directory", img.Id, layerPath(root))
|
return nil, fmt.Errorf("Couldn't load image %s: %s is not a directory", img.ID, layerPath(root))
|
||||||
}
|
}
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func LoadImage(root string) (*Image, error) {
|
||||||
func StoreImage(img *Image, layerData Archive, root string, store bool) error {
|
func StoreImage(img *Image, layerData Archive, root string, store bool) error {
|
||||||
// Check that root doesn't already exist
|
// Check that root doesn't already exist
|
||||||
if _, err := os.Stat(root); err == nil {
|
if _, err := os.Stat(root); err == nil {
|
||||||
return fmt.Errorf("Image %s already exists", img.Id)
|
return fmt.Errorf("Image %s already exists", img.ID)
|
||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -180,11 +180,11 @@ func (image *Image) Changes(rw string) ([]Change, error) {
|
||||||
return Changes(layers, rw)
|
return Changes(layers, rw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (image *Image) ShortId() string {
|
func (image *Image) ShortID() string {
|
||||||
return utils.TruncateId(image.Id)
|
return utils.TruncateID(image.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateId(id string) error {
|
func ValidateID(id string) error {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return fmt.Errorf("Image id can't be empty")
|
return fmt.Errorf("Image id can't be empty")
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ func ValidateId(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateId() string {
|
func GenerateID() string {
|
||||||
id := make([]byte, 32)
|
id := make([]byte, 32)
|
||||||
_, err := io.ReadFull(rand.Reader, id)
|
_, err := io.ReadFull(rand.Reader, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -240,7 +240,7 @@ func (img *Image) layers() ([]string, error) {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return nil, fmt.Errorf("No layer found for image %s\n", img.Id)
|
return nil, fmt.Errorf("No layer found for image %s\n", img.ID)
|
||||||
}
|
}
|
||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ func (img *Image) root() (string, error) {
|
||||||
if img.graph == nil {
|
if img.graph == nil {
|
||||||
return "", fmt.Errorf("Can't lookup root of unregistered image")
|
return "", fmt.Errorf("Can't lookup root of unregistered image")
|
||||||
}
|
}
|
||||||
return img.graph.imageRoot(img.Id), nil
|
return img.graph.imageRoot(img.ID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the path of an image's layer
|
// Return the path of an image's layer
|
||||||
|
@ -288,8 +288,8 @@ func (img *Image) layer() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (img *Image) Checksum() (string, error) {
|
func (img *Image) Checksum() (string, error) {
|
||||||
img.graph.checksumLock[img.Id].Lock()
|
img.graph.checksumLock[img.ID].Lock()
|
||||||
defer img.graph.checksumLock[img.Id].Unlock()
|
defer img.graph.checksumLock[img.ID].Unlock()
|
||||||
|
|
||||||
root, err := img.root()
|
root, err := img.root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -300,7 +300,7 @@ func (img *Image) Checksum() (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if checksum, ok := checksums[img.Id]; ok {
|
if checksum, ok := checksums[img.ID]; ok {
|
||||||
return checksum, nil
|
return checksum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ func (img *Image) Checksum() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
checksums[img.Id] = hash
|
checksums[img.ID] = hash
|
||||||
|
|
||||||
// Dump the checksums to disc
|
// Dump the checksums to disc
|
||||||
if err := img.graph.storeChecksums(checksums); err != nil {
|
if err := img.graph.storeChecksums(checksums); err != nil {
|
||||||
|
@ -362,7 +362,7 @@ func (img *Image) Checksum() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build an Image object from raw json data
|
// Build an Image object from raw json data
|
||||||
func NewImgJson(src []byte) (*Image, error) {
|
func NewImgJSON(src []byte) (*Image, error) {
|
||||||
ret := &Image{}
|
ret := &Image{}
|
||||||
|
|
||||||
utils.Debugf("Json string: {%s}\n", src)
|
utils.Debugf("Json string: {%s}\n", src)
|
||||||
|
|
|
@ -19,7 +19,7 @@ lxc.network.flags = up
|
||||||
lxc.network.link = {{.NetworkSettings.Bridge}}
|
lxc.network.link = {{.NetworkSettings.Bridge}}
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
lxc.network.mtu = 1500
|
lxc.network.mtu = 1500
|
||||||
lxc.network.ipv4 = {{.NetworkSettings.IpAddress}}/{{.NetworkSettings.IpPrefixLen}}
|
lxc.network.ipv4 = {{.NetworkSettings.IPAddress}}/{{.NetworkSettings.IPPrefixLen}}
|
||||||
|
|
||||||
# root filesystem
|
# root filesystem
|
||||||
{{$ROOTFS := .RootfsPath}}
|
{{$ROOTFS := .RootfsPath}}
|
||||||
|
|
|
@ -52,7 +52,7 @@ func ipToInt(ip net.IP) int32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converts 32 bit integer into a 4 bytes IP address
|
// Converts 32 bit integer into a 4 bytes IP address
|
||||||
func intToIp(n int32) net.IP {
|
func intToIP(n int32) net.IP {
|
||||||
b := make([]byte, 4)
|
b := make([]byte, 4)
|
||||||
binary.BigEndian.PutUint32(b, uint32(n))
|
binary.BigEndian.PutUint32(b, uint32(n))
|
||||||
return net.IP(b)
|
return net.IP(b)
|
||||||
|
@ -396,7 +396,7 @@ func (alloc *IPAllocator) run() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := allocatedIP{ip: intToIp(newNum)}
|
ip := allocatedIP{ip: intToIP(newNum)}
|
||||||
if inUse {
|
if inUse {
|
||||||
ip.err = errors.New("No unallocated IP available")
|
ip.err = errors.New("No unallocated IP available")
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ func TestConversion(t *testing.T) {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
t.Fatal("converted to zero")
|
t.Fatal("converted to zero")
|
||||||
}
|
}
|
||||||
conv := intToIp(i)
|
conv := intToIP(i)
|
||||||
if !ip.Equal(conv) {
|
if !ip.Equal(conv) {
|
||||||
t.Error(conv.String())
|
t.Error(conv.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,8 +107,8 @@ func (r *Registry) getImagesInRepository(repository string, authConfig *auth.Aut
|
||||||
|
|
||||||
// Retrieve an image from the Registry.
|
// Retrieve an image from the Registry.
|
||||||
// Returns the Image object as well as the layer as an Archive (io.Reader)
|
// Returns the Image object as well as the layer as an Archive (io.Reader)
|
||||||
func (r *Registry) GetRemoteImageJson(imgId, registry string, token []string) ([]byte, error) {
|
func (r *Registry) GetRemoteImageJSON(imgId, registry string, token []string) ([]byte, error) {
|
||||||
// Get the Json
|
// Get the JSON
|
||||||
req, err := http.NewRequest("GET", registry+"/images/"+imgId+"/json", nil)
|
req, err := http.NewRequest("GET", registry+"/images/"+imgId+"/json", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to download json: %s", err)
|
return nil, fmt.Errorf("Failed to download json: %s", err)
|
||||||
|
@ -169,11 +169,11 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
rawJson, err := ioutil.ReadAll(res.Body)
|
rawJSON, err := ioutil.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(rawJson, &result); err != nil {
|
if err := json.Unmarshal(rawJSON, &result); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
@ -219,19 +219,19 @@ func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) {
|
||||||
return nil, fmt.Errorf("Index response didn't contain any endpoints")
|
return nil, fmt.Errorf("Index response didn't contain any endpoints")
|
||||||
}
|
}
|
||||||
|
|
||||||
checksumsJson, err := ioutil.ReadAll(res.Body)
|
checksumsJSON, err := ioutil.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
remoteChecksums := []*ImgData{}
|
remoteChecksums := []*ImgData{}
|
||||||
if err := json.Unmarshal(checksumsJson, &remoteChecksums); err != nil {
|
if err := json.Unmarshal(checksumsJSON, &remoteChecksums); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forge a better object from the retrieved data
|
// Forge a better object from the retrieved data
|
||||||
imgsData := make(map[string]*ImgData)
|
imgsData := make(map[string]*ImgData)
|
||||||
for _, elem := range remoteChecksums {
|
for _, elem := range remoteChecksums {
|
||||||
imgsData[elem.Id] = elem
|
imgsData[elem.ID] = elem
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RepositoryData{
|
return &RepositoryData{
|
||||||
|
@ -242,10 +242,10 @@ func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push a local image to the registry
|
// Push a local image to the registry
|
||||||
func (r *Registry) PushImageJsonRegistry(imgData *ImgData, jsonRaw []byte, registry string, token []string) error {
|
func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, registry string, token []string) error {
|
||||||
registry = "https://" + registry + "/v1"
|
registry = "https://" + registry + "/v1"
|
||||||
// FIXME: try json with UTF8
|
// FIXME: try json with UTF8
|
||||||
req, err := http.NewRequest("PUT", registry+"/images/"+imgData.Id+"/json", strings.NewReader(string(jsonRaw)))
|
req, err := http.NewRequest("PUT", registry+"/images/"+imgData.ID+"/json", strings.NewReader(string(jsonRaw)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ func (r *Registry) PushImageJsonRegistry(imgData *ImgData, jsonRaw []byte, regis
|
||||||
req.Header.Set("Authorization", "Token "+strings.Join(token, ","))
|
req.Header.Set("Authorization", "Token "+strings.Join(token, ","))
|
||||||
req.Header.Set("X-Docker-Checksum", imgData.Checksum)
|
req.Header.Set("X-Docker-Checksum", imgData.Checksum)
|
||||||
|
|
||||||
utils.Debugf("Setting checksum for %s: %s", imgData.Id, imgData.Checksum)
|
utils.Debugf("Setting checksum for %s: %s", imgData.ID, imgData.Checksum)
|
||||||
res, err := doWithCookies(r.client, req)
|
res, err := doWithCookies(r.client, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to upload metadata: %s", err)
|
return fmt.Errorf("Failed to upload metadata: %s", err)
|
||||||
|
@ -328,8 +328,8 @@ func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validate bool) (*RepositoryData, error) {
|
func (r *Registry) PushImageJSONIndex(remote string, imgList []*ImgData, validate bool) (*RepositoryData, error) {
|
||||||
imgListJson, err := json.Marshal(imgList)
|
imgListJSON, err := json.Marshal(imgList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -338,14 +338,14 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat
|
||||||
suffix = "images"
|
suffix = "images"
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.Debugf("Image list pushed to index:\n%s\n", imgListJson)
|
utils.Debugf("Image list pushed to index:\n%s\n", imgListJSON)
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson))
|
req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(r.authConfig.Username, r.authConfig.Password)
|
req.SetBasicAuth(r.authConfig.Username, r.authConfig.Password)
|
||||||
req.ContentLength = int64(len(imgListJson))
|
req.ContentLength = int64(len(imgListJSON))
|
||||||
req.Header.Set("X-Docker-Token", "true")
|
req.Header.Set("X-Docker-Token", "true")
|
||||||
|
|
||||||
res, err := r.client.Do(req)
|
res, err := r.client.Do(req)
|
||||||
|
@ -357,12 +357,12 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat
|
||||||
// Redirect if necessary
|
// Redirect if necessary
|
||||||
for res.StatusCode >= 300 && res.StatusCode < 400 {
|
for res.StatusCode >= 300 && res.StatusCode < 400 {
|
||||||
utils.Debugf("Redirected to %s\n", res.Header.Get("Location"))
|
utils.Debugf("Redirected to %s\n", res.Header.Get("Location"))
|
||||||
req, err = http.NewRequest("PUT", res.Header.Get("Location"), bytes.NewReader(imgListJson))
|
req, err = http.NewRequest("PUT", res.Header.Get("Location"), bytes.NewReader(imgListJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(r.authConfig.Username, r.authConfig.Password)
|
req.SetBasicAuth(r.authConfig.Username, r.authConfig.Password)
|
||||||
req.ContentLength = int64(len(imgListJson))
|
req.ContentLength = int64(len(imgListJSON))
|
||||||
req.Header.Set("X-Docker-Token", "true")
|
req.Header.Set("X-Docker-Token", "true")
|
||||||
|
|
||||||
res, err = r.client.Do(req)
|
res, err = r.client.Do(req)
|
||||||
|
@ -463,7 +463,7 @@ type RepositoryData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImgData struct {
|
type ImgData struct {
|
||||||
Id string `json:"id"`
|
ID string `json:"id"`
|
||||||
Checksum string `json:"checksum,omitempty"`
|
Checksum string `json:"checksum,omitempty"`
|
||||||
Tag string `json:",omitempty"`
|
Tag string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
30
runtime.go
30
runtime.go
|
@ -51,7 +51,7 @@ func (runtime *Runtime) List() []*Container {
|
||||||
func (runtime *Runtime) getContainerElement(id string) *list.Element {
|
func (runtime *Runtime) getContainerElement(id string) *list.Element {
|
||||||
for e := runtime.containers.Front(); e != nil; e = e.Next() {
|
for e := runtime.containers.Front(); e != nil; e = e.Next() {
|
||||||
container := e.Value.(*Container)
|
container := e.Value.(*Container)
|
||||||
if container.Id == id {
|
if container.ID == id {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ func (runtime *Runtime) Load(id string) (*Container, error) {
|
||||||
if err := container.FromDisk(); err != nil {
|
if err := container.FromDisk(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if container.Id != id {
|
if container.ID != id {
|
||||||
return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
|
return container, fmt.Errorf("Container %s is stored at %s", container.ID, id)
|
||||||
}
|
}
|
||||||
if container.State.Running {
|
if container.State.Running {
|
||||||
container.State.Ghost = true
|
container.State.Ghost = true
|
||||||
|
@ -95,12 +95,12 @@ func (runtime *Runtime) Load(id string) (*Container, error) {
|
||||||
return container, nil
|
return container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register makes a container object usable by the runtime as <container.Id>
|
// Register makes a container object usable by the runtime as <container.ID>
|
||||||
func (runtime *Runtime) Register(container *Container) error {
|
func (runtime *Runtime) Register(container *Container) error {
|
||||||
if container.runtime != nil || runtime.Exists(container.Id) {
|
if container.runtime != nil || runtime.Exists(container.ID) {
|
||||||
return fmt.Errorf("Container is already loaded")
|
return fmt.Errorf("Container is already loaded")
|
||||||
}
|
}
|
||||||
if err := validateId(container.Id); err != nil {
|
if err := validateID(container.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
}
|
}
|
||||||
// done
|
// done
|
||||||
runtime.containers.PushBack(container)
|
runtime.containers.PushBack(container)
|
||||||
runtime.idIndex.Add(container.Id)
|
runtime.idIndex.Add(container.ID)
|
||||||
|
|
||||||
// When we actually restart, Start() do the monitoring.
|
// When we actually restart, Start() do the monitoring.
|
||||||
// However, when we simply 'reattach', we have to restart a monitor
|
// However, when we simply 'reattach', we have to restart a monitor
|
||||||
|
@ -133,12 +133,12 @@ func (runtime *Runtime) Register(container *Container) error {
|
||||||
// if so, then we need to restart monitor and init a new lock
|
// if so, then we need to restart monitor and init a new lock
|
||||||
// If the container is supposed to be running, make sure of it
|
// If the container is supposed to be running, make sure of it
|
||||||
if container.State.Running {
|
if container.State.Running {
|
||||||
output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput()
|
output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !strings.Contains(string(output), "RUNNING") {
|
if !strings.Contains(string(output), "RUNNING") {
|
||||||
utils.Debugf("Container %s was supposed to be running be is not.", container.Id)
|
utils.Debugf("Container %s was supposed to be running be is not.", container.ID)
|
||||||
if runtime.autoRestart {
|
if runtime.autoRestart {
|
||||||
utils.Debugf("Restarting")
|
utils.Debugf("Restarting")
|
||||||
container.State.Ghost = false
|
container.State.Ghost = false
|
||||||
|
@ -182,9 +182,9 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
||||||
return fmt.Errorf("The given container is <nil>")
|
return fmt.Errorf("The given container is <nil>")
|
||||||
}
|
}
|
||||||
|
|
||||||
element := runtime.getContainerElement(container.Id)
|
element := runtime.getContainerElement(container.ID)
|
||||||
if element == nil {
|
if element == nil {
|
||||||
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id)
|
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := container.Stop(3); err != nil {
|
if err := container.Stop(3); err != nil {
|
||||||
|
@ -194,14 +194,14 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
||||||
return err
|
return err
|
||||||
} else if mounted {
|
} else if mounted {
|
||||||
if err := container.Unmount(); err != nil {
|
if err := container.Unmount(); err != nil {
|
||||||
return fmt.Errorf("Unable to unmount container %v: %v", container.Id, err)
|
return fmt.Errorf("Unable to unmount container %v: %v", container.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deregister the container before removing its directory, to avoid race conditions
|
// Deregister the container before removing its directory, to avoid race conditions
|
||||||
runtime.idIndex.Delete(container.Id)
|
runtime.idIndex.Delete(container.ID)
|
||||||
runtime.containers.Remove(element)
|
runtime.containers.Remove(element)
|
||||||
if err := os.RemoveAll(container.root); err != nil {
|
if err := os.RemoveAll(container.root); err != nil {
|
||||||
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.Id, err)
|
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ func (runtime *Runtime) restore() error {
|
||||||
utils.Debugf("Failed to load container %v: %v", id, err)
|
utils.Debugf("Failed to load container %v: %v", id, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
utils.Debugf("Loaded container %v", container.Id)
|
utils.Debugf("Loaded container %v", container.ID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ func TestRuntimeCreate(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
|
|
||||||
container, err := builder.Create(&Config{
|
container, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -140,29 +140,29 @@ func TestRuntimeCreate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the container List() returns is the right one
|
// Make sure the container List() returns is the right one
|
||||||
if runtime.List()[0].Id != container.Id {
|
if runtime.List()[0].ID != container.ID {
|
||||||
t.Errorf("Unexpected container %v returned by List", runtime.List()[0])
|
t.Errorf("Unexpected container %v returned by List", runtime.List()[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we can get the container with Get()
|
// Make sure we can get the container with Get()
|
||||||
if runtime.Get(container.Id) == nil {
|
if runtime.Get(container.ID) == nil {
|
||||||
t.Errorf("Unable to get newly created container")
|
t.Errorf("Unable to get newly created container")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure it is the right container
|
// Make sure it is the right container
|
||||||
if runtime.Get(container.Id) != container {
|
if runtime.Get(container.ID) != container {
|
||||||
t.Errorf("Get() returned the wrong container")
|
t.Errorf("Get() returned the wrong container")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure Exists returns it as existing
|
// Make sure Exists returns it as existing
|
||||||
if !runtime.Exists(container.Id) {
|
if !runtime.Exists(container.ID) {
|
||||||
t.Errorf("Exists() returned false for a newly created container")
|
t.Errorf("Exists() returned false for a newly created container")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure crete with bad parameters returns an error
|
// Make sure crete with bad parameters returns an error
|
||||||
_, err = builder.Create(
|
_, err = builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -171,7 +171,7 @@ func TestRuntimeCreate(t *testing.T) {
|
||||||
|
|
||||||
_, err = builder.Create(
|
_, err = builder.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{},
|
Cmd: []string{},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -187,7 +187,7 @@ func TestDestroy(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -210,7 +210,7 @@ func TestDestroy(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure runtime.Get() refuses to return the unexisting container
|
// Make sure runtime.Get() refuses to return the unexisting container
|
||||||
if runtime.Get(container.Id) != nil {
|
if runtime.Get(container.ID) != nil {
|
||||||
t.Errorf("Unable to get newly created container")
|
t.Errorf("Unable to get newly created container")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ func TestGet(t *testing.T) {
|
||||||
builder := NewBuilder(runtime)
|
builder := NewBuilder(runtime)
|
||||||
|
|
||||||
container1, err := builder.Create(&Config{
|
container1, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -247,7 +247,7 @@ func TestGet(t *testing.T) {
|
||||||
defer runtime.Destroy(container1)
|
defer runtime.Destroy(container1)
|
||||||
|
|
||||||
container2, err := builder.Create(&Config{
|
container2, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -257,7 +257,7 @@ func TestGet(t *testing.T) {
|
||||||
defer runtime.Destroy(container2)
|
defer runtime.Destroy(container2)
|
||||||
|
|
||||||
container3, err := builder.Create(&Config{
|
container3, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -266,16 +266,16 @@ func TestGet(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer runtime.Destroy(container3)
|
defer runtime.Destroy(container3)
|
||||||
|
|
||||||
if runtime.Get(container1.Id) != container1 {
|
if runtime.Get(container1.ID) != container1 {
|
||||||
t.Errorf("Get(test1) returned %v while expecting %v", runtime.Get(container1.Id), container1)
|
t.Errorf("Get(test1) returned %v while expecting %v", runtime.Get(container1.ID), container1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.Get(container2.Id) != container2 {
|
if runtime.Get(container2.ID) != container2 {
|
||||||
t.Errorf("Get(test2) returned %v while expecting %v", runtime.Get(container2.Id), container2)
|
t.Errorf("Get(test2) returned %v while expecting %v", runtime.Get(container2.ID), container2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.Get(container3.Id) != container3 {
|
if runtime.Get(container3.ID) != container3 {
|
||||||
t.Errorf("Get(test3) returned %v while expecting %v", runtime.Get(container3.Id), container3)
|
t.Errorf("Get(test3) returned %v while expecting %v", runtime.Get(container3.ID), container3)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ func TestGet(t *testing.T) {
|
||||||
func findAvailalblePort(runtime *Runtime, port int) (*Container, error) {
|
func findAvailalblePort(runtime *Runtime, port int) (*Container, error) {
|
||||||
strPort := strconv.Itoa(port)
|
strPort := strconv.Itoa(port)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p " + strPort},
|
Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p " + strPort},
|
||||||
PortSpecs: []string{strPort},
|
PortSpecs: []string{strPort},
|
||||||
},
|
},
|
||||||
|
@ -379,7 +379,7 @@ func TestRestore(t *testing.T) {
|
||||||
|
|
||||||
// Create a container with one instance of docker
|
// Create a container with one instance of docker
|
||||||
container1, err := builder.Create(&Config{
|
container1, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime1).Id,
|
Image: GetTestImage(runtime1).ID,
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -390,7 +390,7 @@ func TestRestore(t *testing.T) {
|
||||||
|
|
||||||
// Create a second container meant to be killed
|
// Create a second container meant to be killed
|
||||||
container2, err := builder.Create(&Config{
|
container2, err := builder.Create(&Config{
|
||||||
Image: GetTestImage(runtime1).Id,
|
Image: GetTestImage(runtime1).ID,
|
||||||
Cmd: []string{"/bin/cat"},
|
Cmd: []string{"/bin/cat"},
|
||||||
OpenStdin: true,
|
OpenStdin: true,
|
||||||
},
|
},
|
||||||
|
@ -406,7 +406,7 @@ func TestRestore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !container2.State.Running {
|
if !container2.State.Running {
|
||||||
t.Fatalf("Container %v should appear as running but isn't", container2.Id)
|
t.Fatalf("Container %v should appear as running but isn't", container2.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
|
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
|
||||||
|
@ -426,7 +426,7 @@ func TestRestore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !container2.State.Running {
|
if !container2.State.Running {
|
||||||
t.Fatalf("Container %v should appear as running but isn't", container2.Id)
|
t.Fatalf("Container %v should appear as running but isn't", container2.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here are are simulating a docker restart - that is, reloading all containers
|
// Here are are simulating a docker restart - that is, reloading all containers
|
||||||
|
@ -442,14 +442,14 @@ func TestRestore(t *testing.T) {
|
||||||
runningCount := 0
|
runningCount := 0
|
||||||
for _, c := range runtime2.List() {
|
for _, c := range runtime2.List() {
|
||||||
if c.State.Running {
|
if c.State.Running {
|
||||||
t.Errorf("Running container found: %v (%v)", c.Id, c.Path)
|
t.Errorf("Running container found: %v (%v)", c.ID, c.Path)
|
||||||
runningCount++
|
runningCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runningCount != 0 {
|
if runningCount != 0 {
|
||||||
t.Fatalf("Expected 0 container alive, %d found", runningCount)
|
t.Fatalf("Expected 0 container alive, %d found", runningCount)
|
||||||
}
|
}
|
||||||
container3 := runtime2.Get(container1.Id)
|
container3 := runtime2.Get(container1.ID)
|
||||||
if container3 == nil {
|
if container3 == nil {
|
||||||
t.Fatal("Unable to Get container")
|
t.Fatal("Unable to Get container")
|
||||||
}
|
}
|
||||||
|
|
116
server.go
116
server.go
|
@ -16,10 +16,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (srv *Server) DockerVersion() ApiVersion {
|
func (srv *Server) DockerVersion() APIVersion {
|
||||||
return ApiVersion{
|
return APIVersion{
|
||||||
Version: VERSION,
|
Version: VERSION,
|
||||||
GitCommit: GIT_COMMIT,
|
GitCommit: GITCOMMIT,
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,16 +52,16 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
||||||
return fmt.Errorf("No such container: %s", name)
|
return fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
func (srv *Server) ImagesSearch(term string) ([]APISearch, error) {
|
||||||
|
|
||||||
results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term)
|
results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var outs []ApiSearch
|
var outs []APISearch
|
||||||
for _, repo := range results.Results {
|
for _, repo := range results.Results {
|
||||||
var out ApiSearch
|
var out APISearch
|
||||||
out.Description = repo["description"]
|
out.Description = repo["description"]
|
||||||
if len(out.Description) > 45 {
|
if len(out.Description) > 45 {
|
||||||
out.Description = utils.Trunc(out.Description, 42) + "..."
|
out.Description = utils.Trunc(out.Description, 42) + "..."
|
||||||
|
@ -85,7 +85,7 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
||||||
}
|
}
|
||||||
defer file.Body.Close()
|
defer file.Body.Close()
|
||||||
|
|
||||||
config, _, err := ParseRun([]string{img.Id, "echo", "insert", url, path}, srv.runtime.capabilities)
|
config, _, err := ParseRun([]string{img.ID, "echo", "insert", url, path}, srv.runtime.capabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,8 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus(img.Id))
|
out.Write(sf.FormatStatus(img.ID))
|
||||||
return img.ShortId(), nil
|
return img.ShortID(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImagesViz(out io.Writer) error {
|
func (srv *Server) ImagesViz(out io.Writer) error {
|
||||||
|
@ -125,9 +125,9 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
||||||
return fmt.Errorf("Error while getting parent image: %v", err)
|
return fmt.Errorf("Error while getting parent image: %v", err)
|
||||||
}
|
}
|
||||||
if parentImage != nil {
|
if parentImage != nil {
|
||||||
out.Write([]byte(" \"" + parentImage.ShortId() + "\" -> \"" + image.ShortId() + "\"\n"))
|
out.Write([]byte(" \"" + parentImage.ShortID() + "\" -> \"" + image.ShortID() + "\"\n"))
|
||||||
} else {
|
} else {
|
||||||
out.Write([]byte(" base -> \"" + image.ShortId() + "\" [style=invis]\n"))
|
out.Write([]byte(" base -> \"" + image.ShortID() + "\" [style=invis]\n"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
||||||
|
|
||||||
for name, repository := range srv.runtime.repositories.Repositories {
|
for name, repository := range srv.runtime.repositories.Repositories {
|
||||||
for tag, id := range repository {
|
for tag, id := range repository {
|
||||||
reporefs[utils.TruncateId(id)] = append(reporefs[utils.TruncateId(id)], fmt.Sprintf("%s:%s", name, tag))
|
reporefs[utils.TruncateID(id)] = append(reporefs[utils.TruncateID(id)], fmt.Sprintf("%s:%s", name, tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
|
||||||
var (
|
var (
|
||||||
allImages map[string]*Image
|
allImages map[string]*Image
|
||||||
err error
|
err error
|
||||||
|
@ -159,13 +159,13 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
outs := []ApiImages{} //produce [] when empty instead of 'null'
|
outs := []APIImages{} //produce [] when empty instead of 'null'
|
||||||
for name, repository := range srv.runtime.repositories.Repositories {
|
for name, repository := range srv.runtime.repositories.Repositories {
|
||||||
if filter != "" && name != filter {
|
if filter != "" && name != filter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for tag, id := range repository {
|
for tag, id := range repository {
|
||||||
var out ApiImages
|
var out APIImages
|
||||||
image, err := srv.runtime.graph.Get(id)
|
image, err := srv.runtime.graph.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
||||||
|
@ -174,7 +174,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
||||||
delete(allImages, id)
|
delete(allImages, id)
|
||||||
out.Repository = name
|
out.Repository = name
|
||||||
out.Tag = tag
|
out.Tag = tag
|
||||||
out.Id = image.Id
|
out.ID = image.ID
|
||||||
out.Created = image.Created.Unix()
|
out.Created = image.Created.Unix()
|
||||||
outs = append(outs, out)
|
outs = append(outs, out)
|
||||||
}
|
}
|
||||||
|
@ -182,8 +182,8 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
||||||
// Display images which aren't part of a
|
// Display images which aren't part of a
|
||||||
if filter == "" {
|
if filter == "" {
|
||||||
for _, image := range allImages {
|
for _, image := range allImages {
|
||||||
var out ApiImages
|
var out APIImages
|
||||||
out.Id = image.Id
|
out.ID = image.ID
|
||||||
out.Created = image.Created.Unix()
|
out.Created = image.Created.Unix()
|
||||||
outs = append(outs, out)
|
outs = append(outs, out)
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func (srv *Server) Images(all bool, filter string) ([]ApiImages, error) {
|
||||||
return outs, nil
|
return outs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) DockerInfo() *ApiInfo {
|
func (srv *Server) DockerInfo() *APIInfo {
|
||||||
images, _ := srv.runtime.graph.All()
|
images, _ := srv.runtime.graph.All()
|
||||||
var imgcount int
|
var imgcount int
|
||||||
if images == nil {
|
if images == nil {
|
||||||
|
@ -199,7 +199,7 @@ func (srv *Server) DockerInfo() *ApiInfo {
|
||||||
} else {
|
} else {
|
||||||
imgcount = len(images)
|
imgcount = len(images)
|
||||||
}
|
}
|
||||||
return &ApiInfo{
|
return &APIInfo{
|
||||||
Containers: len(srv.runtime.List()),
|
Containers: len(srv.runtime.List()),
|
||||||
Images: imgcount,
|
Images: imgcount,
|
||||||
MemoryLimit: srv.runtime.capabilities.MemoryLimit,
|
MemoryLimit: srv.runtime.capabilities.MemoryLimit,
|
||||||
|
@ -210,16 +210,16 @@ func (srv *Server) DockerInfo() *ApiInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ImageHistory(name string) ([]ApiHistory, error) {
|
func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
||||||
image, err := srv.runtime.repositories.LookupImage(name)
|
image, err := srv.runtime.repositories.LookupImage(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
outs := []ApiHistory{} //produce [] when empty instead of 'null'
|
outs := []APIHistory{} //produce [] when empty instead of 'null'
|
||||||
err = image.WalkHistory(func(img *Image) error {
|
err = image.WalkHistory(func(img *Image) error {
|
||||||
var out ApiHistory
|
var out APIHistory
|
||||||
out.Id = srv.runtime.repositories.ImageName(img.ShortId())
|
out.ID = srv.runtime.repositories.ImageName(img.ShortID())
|
||||||
out.Created = img.Created.Unix()
|
out.Created = img.Created.Unix()
|
||||||
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
|
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
|
||||||
outs = append(outs, out)
|
outs = append(outs, out)
|
||||||
|
@ -236,17 +236,17 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
||||||
return nil, fmt.Errorf("No such container: %s", name)
|
return nil, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) Containers(all bool, n int, since, before string) []ApiContainers {
|
func (srv *Server) Containers(all bool, n int, since, before string) []APIContainers {
|
||||||
var foundBefore bool
|
var foundBefore bool
|
||||||
var displayed int
|
var displayed int
|
||||||
retContainers := []ApiContainers{}
|
retContainers := []APIContainers{}
|
||||||
|
|
||||||
for _, container := range srv.runtime.List() {
|
for _, container := range srv.runtime.List() {
|
||||||
if !container.State.Running && !all && n == -1 && since == "" && before == "" {
|
if !container.State.Running && !all && n == -1 && since == "" && before == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if before != "" {
|
if before != "" {
|
||||||
if container.ShortId() == before {
|
if container.ShortID() == before {
|
||||||
foundBefore = true
|
foundBefore = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -257,13 +257,13 @@ func (srv *Server) Containers(all bool, n int, since, before string) []ApiContai
|
||||||
if displayed == n {
|
if displayed == n {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if container.ShortId() == since {
|
if container.ShortID() == since {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
displayed++
|
displayed++
|
||||||
|
|
||||||
c := ApiContainers{
|
c := APIContainers{
|
||||||
Id: container.Id,
|
ID: container.ID,
|
||||||
}
|
}
|
||||||
c.Image = srv.runtime.repositories.ImageName(container.Image)
|
c.Image = srv.runtime.repositories.ImageName(container.Image)
|
||||||
c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
c.Command = fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
||||||
|
@ -284,7 +284,7 @@ func (srv *Server) ContainerCommit(name, repo, tag, author, comment string, conf
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return img.ShortId(), err
|
return img.ShortID(), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
||||||
|
@ -305,19 +305,19 @@ func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoin
|
||||||
for _, id := range history {
|
for _, id := range history {
|
||||||
if !srv.runtime.graph.Exists(id) {
|
if !srv.runtime.graph.Exists(id) {
|
||||||
out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
||||||
imgJson, err := r.GetRemoteImageJson(id, endpoint, token)
|
imgJSON, err := r.GetRemoteImageJSON(id, endpoint, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// FIXME: Keep goging in case of error?
|
// FIXME: Keep goging in case of error?
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
img, err := NewImgJson(imgJson)
|
img, err := NewImgJSON(imgJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to parse json: %s", err)
|
return fmt.Errorf("Failed to parse json: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the layer
|
// Get the layer
|
||||||
out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
||||||
layer, contentLength, err := r.GetRemoteImageLayer(img.Id, endpoint, token)
|
layer, contentLength, err := r.GetRemoteImageLayer(img.ID, endpoint, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -365,13 +365,13 @@ func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, a
|
||||||
|
|
||||||
for _, img := range repoData.ImgList {
|
for _, img := range repoData.ImgList {
|
||||||
if askedTag != "" && img.Tag != askedTag {
|
if askedTag != "" && img.Tag != askedTag {
|
||||||
utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.Id)
|
utils.Debugf("(%s) does not match %s (id: %s), skipping", img.Tag, askedTag, img.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.Id, img.Tag, remote))
|
out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.ID, img.Tag, remote))
|
||||||
success := false
|
success := false
|
||||||
for _, ep := range repoData.Endpoints {
|
for _, ep := range repoData.Endpoints {
|
||||||
if err := srv.pullImage(r, out, img.Id, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
|
if err := srv.pullImage(r, out, img.ID, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
|
||||||
out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -461,16 +461,16 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
img.WalkHistory(func(img *Image) error {
|
img.WalkHistory(func(img *Image) error {
|
||||||
if _, exists := imageSet[img.Id]; exists {
|
if _, exists := imageSet[img.ID]; exists {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
imageSet[img.Id] = struct{}{}
|
imageSet[img.ID] = struct{}{}
|
||||||
checksum, err := srv.getChecksum(img.Id)
|
checksum, err := srv.getChecksum(img.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
imgList = append([]*registry.ImgData{{
|
imgList = append([]*registry.ImgData{{
|
||||||
Id: img.Id,
|
ID: img.ID,
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
Tag: tag,
|
Tag: tag,
|
||||||
}}, imgList...)
|
}}, imgList...)
|
||||||
|
@ -489,7 +489,7 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name stri
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus("Sending image list"))
|
out.Write(sf.FormatStatus("Sending image list"))
|
||||||
|
|
||||||
repoData, err := r.PushImageJsonIndex(name, imgList, false)
|
repoData, err := r.PushImageJSONIndex(name, imgList, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -498,22 +498,22 @@ func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name stri
|
||||||
out.Write(sf.FormatStatus("Pushing repository %s to %s (%d tags)", name, ep, len(localRepo)))
|
out.Write(sf.FormatStatus("Pushing repository %s to %s (%d tags)", name, ep, len(localRepo)))
|
||||||
// For each image within the repo, push them
|
// For each image within the repo, push them
|
||||||
for _, elem := range imgList {
|
for _, elem := range imgList {
|
||||||
if _, exists := repoData.ImgList[elem.Id]; exists {
|
if _, exists := repoData.ImgList[elem.ID]; exists {
|
||||||
out.Write(sf.FormatStatus("Image %s already on registry, skipping", name))
|
out.Write(sf.FormatStatus("Image %s already on registry, skipping", name))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := srv.pushImage(r, out, name, elem.Id, ep, repoData.Tokens, sf); err != nil {
|
if err := srv.pushImage(r, out, name, elem.ID, ep, repoData.Tokens, sf); err != nil {
|
||||||
// FIXME: Continue on error?
|
// FIXME: Continue on error?
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.Id, ep+"/users/"+name+"/"+elem.Tag))
|
out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.ID, ep+"/users/"+name+"/"+elem.Tag))
|
||||||
if err := r.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
if err := r.PushRegistryTag(name, elem.ID, elem.Tag, ep, repoData.Tokens); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := r.PushImageJsonIndex(name, imgList, true); err != nil {
|
if _, err := r.PushImageJSONIndex(name, imgList, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -533,14 +533,14 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
imgData := ®istry.ImgData{
|
imgData := ®istry.ImgData{
|
||||||
Id: imgId,
|
ID: imgId,
|
||||||
Checksum: checksum,
|
Checksum: checksum,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the json
|
// Send the json
|
||||||
if err := r.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
if err := r.PushImageJSONRegistry(imgData, jsonRaw, ep, token); err != nil {
|
||||||
if err == registry.ErrAlreadyExists {
|
if err == registry.ErrAlreadyExists {
|
||||||
out.Write(sf.FormatStatus("Image %s already uploaded ; skipping", imgData.Id))
|
out.Write(sf.FormatStatus("Image %s already uploaded ; skipping", imgData.ID))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -573,7 +573,7 @@ func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the layer
|
// Send the layer
|
||||||
if err := r.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "%v/%v (%v)"), sf), ep, token); err != nil {
|
if err := r.PushImageLayerRegistry(imgData.ID, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "%v/%v (%v)"), sf), ep, token); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -597,7 +597,7 @@ func (srv *Server) ImagePush(name, endpoint string, out io.Writer, sf *utils.Str
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus("The push refers to an image: [%s]", name))
|
out.Write(sf.FormatStatus("The push refers to an image: [%s]", name))
|
||||||
if err := srv.pushImage(r, out, name, img.Id, endpoint, nil, sf); err != nil {
|
if err := srv.pushImage(r, out, name, img.ID, endpoint, nil, sf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -634,11 +634,11 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write
|
||||||
}
|
}
|
||||||
// Optionally register the image at REPO/TAG
|
// Optionally register the image at REPO/TAG
|
||||||
if repo != "" {
|
if repo != "" {
|
||||||
if err := srv.runtime.repositories.Set(repo, tag, img.Id, true); err != nil {
|
if err := srv.runtime.repositories.Set(repo, tag, img.ID, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.Write(sf.FormatStatus(img.ShortId()))
|
out.Write(sf.FormatStatus(img.ShortID()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ func (srv *Server) ContainerCreate(config *Config) (string, error) {
|
||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return container.ShortId(), nil
|
return container.ShortID(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerRestart(name string, t int) error {
|
func (srv *Server) ContainerRestart(name string, t int) error {
|
||||||
|
@ -696,7 +696,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error {
|
||||||
for volumeId := range volumes {
|
for volumeId := range volumes {
|
||||||
// If the requested volu
|
// If the requested volu
|
||||||
if c, exists := usedVolumes[volumeId]; exists {
|
if c, exists := usedVolumes[volumeId]; exists {
|
||||||
log.Printf("The volume %s is used by the container %s. Impossible to remove it. Skipping.\n", volumeId, c.Id)
|
log.Printf("The volume %s is used by the container %s. Impossible to remove it. Skipping.\n", volumeId, c.ID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := srv.runtime.volumes.Delete(volumeId); err != nil {
|
if err := srv.runtime.volumes.Delete(volumeId); err != nil {
|
||||||
|
@ -715,7 +715,7 @@ func (srv *Server) ImageDelete(name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("No such image: %s", name)
|
return fmt.Errorf("No such image: %s", name)
|
||||||
}
|
}
|
||||||
if err := srv.runtime.graph.Delete(img.Id); err != nil {
|
if err := srv.runtime.graph.Delete(img.ID); err != nil {
|
||||||
return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
|
return fmt.Errorf("Error deleting image %s: %s", name, err.Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -735,7 +735,7 @@ func (srv *Server) ImageGetCached(imgId string, config *Config) (*Image, error)
|
||||||
if _, exists := imageMap[img.Parent]; !exists {
|
if _, exists := imageMap[img.Parent]; !exists {
|
||||||
imageMap[img.Parent] = make(map[string]struct{})
|
imageMap[img.Parent] = make(map[string]struct{})
|
||||||
}
|
}
|
||||||
imageMap[img.Parent][img.Id] = struct{}{}
|
imageMap[img.Parent][img.ID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop on the children of the given image and check the config
|
// Loop on the children of the given image and check the config
|
||||||
|
|
|
@ -13,7 +13,7 @@ func TestCreateRm(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "echo test"}, nil)
|
config, _, err := ParseRun([]string{GetTestImage(runtime).ID, "echo test"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "/bin/cat"}, nil)
|
config, _, err := ParseRun([]string{GetTestImage(runtime).ID, "/bin/cat"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
26
tags.go
26
tags.go
|
@ -11,7 +11,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_TAG = "latest"
|
const DEFAULTTAG = "latest"
|
||||||
|
|
||||||
type TagStore struct {
|
type TagStore struct {
|
||||||
path string
|
path string
|
||||||
|
@ -72,7 +72,7 @@ func (store *TagStore) LookupImage(name string) (*Image, error) {
|
||||||
// (so we can pass all errors here)
|
// (so we can pass all errors here)
|
||||||
repoAndTag := strings.SplitN(name, ":", 2)
|
repoAndTag := strings.SplitN(name, ":", 2)
|
||||||
if len(repoAndTag) == 1 {
|
if len(repoAndTag) == 1 {
|
||||||
repoAndTag = append(repoAndTag, DEFAULT_TAG)
|
repoAndTag = append(repoAndTag, DEFAULTTAG)
|
||||||
}
|
}
|
||||||
if i, err := store.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
|
if i, err := store.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -87,27 +87,27 @@ func (store *TagStore) LookupImage(name string) (*Image, error) {
|
||||||
|
|
||||||
// Return a reverse-lookup table of all the names which refer to each image
|
// Return a reverse-lookup table of all the names which refer to each image
|
||||||
// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
// Eg. {"43b5f19b10584": {"base:latest", "base:v1"}}
|
||||||
func (store *TagStore) ById() map[string][]string {
|
func (store *TagStore) ByID() map[string][]string {
|
||||||
byId := make(map[string][]string)
|
byID := make(map[string][]string)
|
||||||
for repoName, repository := range store.Repositories {
|
for repoName, repository := range store.Repositories {
|
||||||
for tag, id := range repository {
|
for tag, id := range repository {
|
||||||
name := repoName + ":" + tag
|
name := repoName + ":" + tag
|
||||||
if _, exists := byId[id]; !exists {
|
if _, exists := byID[id]; !exists {
|
||||||
byId[id] = []string{name}
|
byID[id] = []string{name}
|
||||||
} else {
|
} else {
|
||||||
byId[id] = append(byId[id], name)
|
byID[id] = append(byID[id], name)
|
||||||
sort.Strings(byId[id])
|
sort.Strings(byID[id])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return byId
|
return byID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *TagStore) ImageName(id string) string {
|
func (store *TagStore) ImageName(id string) string {
|
||||||
if names, exists := store.ById()[id]; exists && len(names) > 0 {
|
if names, exists := store.ByID()[id]; exists && len(names) > 0 {
|
||||||
return names[0]
|
return names[0]
|
||||||
}
|
}
|
||||||
return utils.TruncateId(id)
|
return utils.TruncateID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
||||||
|
@ -116,7 +116,7 @@ func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = DEFAULT_TAG
|
tag = DEFAULTTAG
|
||||||
}
|
}
|
||||||
if err := validateRepoName(repoName); err != nil {
|
if err := validateRepoName(repoName); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -137,7 +137,7 @@ func (store *TagStore) Set(repoName, tag, imageName string, force bool) error {
|
||||||
}
|
}
|
||||||
store.Repositories[repoName] = repo
|
store.Repositories[repoName] = repo
|
||||||
}
|
}
|
||||||
repo[tag] = img.Id
|
repo[tag] = img.ID
|
||||||
return store.Save()
|
return store.Save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -349,11 +349,11 @@ func (idx *TruncIndex) Get(s string) (string, error) {
|
||||||
return string(idx.bytes[before:after]), err
|
return string(idx.bytes[before:after]), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TruncateId returns a shorthand version of a string identifier for convenience.
|
// TruncateID returns a shorthand version of a string identifier for convenience.
|
||||||
// A collision with other shorthands is very unlikely, but possible.
|
// A collision with other shorthands is very unlikely, but possible.
|
||||||
// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller
|
// In case of a collision a lookup with TruncIndex.Get() will fail, and the caller
|
||||||
// will need to use a langer prefix, or the full-length Id.
|
// will need to use a langer prefix, or the full-length Id.
|
||||||
func TruncateId(id string) string {
|
func TruncateID(id string) string {
|
||||||
shortLen := 12
|
shortLen := 12
|
||||||
if len(id) < shortLen {
|
if len(id) < shortLen {
|
||||||
shortLen = len(id)
|
shortLen = len(id)
|
||||||
|
@ -566,7 +566,7 @@ func NewWriteFlusher(w io.Writer) *WriteFlusher {
|
||||||
return &WriteFlusher{w: w, flusher: flusher}
|
return &WriteFlusher{w: w, flusher: flusher}
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonMessage struct {
|
type JSONMessage struct {
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
Progress string `json:"progress,omitempty"`
|
Progress string `json:"progress,omitempty"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
|
@ -585,7 +585,7 @@ func (sf *StreamFormatter) FormatStatus(format string, a ...interface{}) []byte
|
||||||
sf.used = true
|
sf.used = true
|
||||||
str := fmt.Sprintf(format, a...)
|
str := fmt.Sprintf(format, a...)
|
||||||
if sf.json {
|
if sf.json {
|
||||||
b, err := json.Marshal(&JsonMessage{Status:str});
|
b, err := json.Marshal(&JSONMessage{Status:str});
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sf.FormatError(err)
|
return sf.FormatError(err)
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ func (sf *StreamFormatter) FormatStatus(format string, a ...interface{}) []byte
|
||||||
func (sf *StreamFormatter) FormatError(err error) []byte {
|
func (sf *StreamFormatter) FormatError(err error) []byte {
|
||||||
sf.used = true
|
sf.used = true
|
||||||
if sf.json {
|
if sf.json {
|
||||||
if b, err := json.Marshal(&JsonMessage{Error:err.Error()}); err == nil {
|
if b, err := json.Marshal(&JSONMessage{Error:err.Error()}); err == nil {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
return []byte("{\"error\":\"format error\"}")
|
return []byte("{\"error\":\"format error\"}")
|
||||||
|
@ -608,7 +608,7 @@ func (sf *StreamFormatter) FormatError(err error) []byte {
|
||||||
func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
|
func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
|
||||||
sf.used = true
|
sf.used = true
|
||||||
if sf.json {
|
if sf.json {
|
||||||
b, err := json.Marshal(&JsonMessage{Progress:str})
|
b, err := json.Marshal(&JSONMessage{Progress:str})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue