| ... | ... |
@@ -67,7 +67,16 @@ func getBoolParam(value string) (bool, error) {
|
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| 70 |
- b, err := json.Marshal(srv.registry.GetAuthConfig(false)) |
|
| 70 |
+ // FIXME: Handle multiple login at once |
|
| 71 |
+ // FIXME: return specific error code if config file missing? |
|
| 72 |
+ authConfig, err := auth.LoadConfig(srv.runtime.root) |
|
| 73 |
+ if err != nil {
|
|
| 74 |
+ if err != auth.ErrConfigFileMissing {
|
|
| 75 |
+ return err |
|
| 76 |
+ } |
|
| 77 |
+ authConfig = &auth.AuthConfig{}
|
|
| 78 |
+ } |
|
| 79 |
+ b, err := json.Marshal(&auth.AuthConfig{Username: authConfig.Username, Email: authConfig.Email})
|
|
| 71 | 80 |
if err != nil {
|
| 72 | 81 |
return err |
| 73 | 82 |
} |
| ... | ... |
@@ -76,11 +85,19 @@ func getAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reques |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| 79 |
+ // FIXME: Handle multiple login at once |
|
| 79 | 80 |
config := &auth.AuthConfig{}
|
| 80 | 81 |
if err := json.NewDecoder(r.Body).Decode(config); err != nil {
|
| 81 | 82 |
return err |
| 82 | 83 |
} |
| 83 |
- authConfig := srv.registry.GetAuthConfig(true) |
|
| 84 |
+ |
|
| 85 |
+ authConfig, err := auth.LoadConfig(srv.runtime.root) |
|
| 86 |
+ if err != nil {
|
|
| 87 |
+ if err != auth.ErrConfigFileMissing {
|
|
| 88 |
+ return err |
|
| 89 |
+ } |
|
| 90 |
+ authConfig = &auth.AuthConfig{}
|
|
| 91 |
+ } |
|
| 84 | 92 |
if config.Username == authConfig.Username {
|
| 85 | 93 |
config.Password = authConfig.Password |
| 86 | 94 |
} |
| ... | ... |
@@ -90,7 +107,6 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque |
| 90 | 90 |
if err != nil {
|
| 91 | 91 |
return err |
| 92 | 92 |
} |
| 93 |
- srv.registry.ResetClient(newAuthConfig) |
|
| 94 | 93 |
|
| 95 | 94 |
if status != "" {
|
| 96 | 95 |
b, err := json.Marshal(&ApiAuth{Status: status})
|
| ... | ... |
@@ -26,8 +26,7 @@ func TestGetAuth(t *testing.T) {
|
| 26 | 26 |
defer nuke(runtime) |
| 27 | 27 |
|
| 28 | 28 |
srv := &Server{
|
| 29 |
- runtime: runtime, |
|
| 30 |
- registry: registry.NewRegistry(runtime.root), |
|
| 29 |
+ runtime: runtime, |
|
| 31 | 30 |
} |
| 32 | 31 |
|
| 33 | 32 |
r := httptest.NewRecorder() |
| ... | ... |
@@ -56,7 +55,7 @@ func TestGetAuth(t *testing.T) {
|
| 56 | 56 |
t.Fatalf("%d OK or 0 expected, received %d\n", http.StatusOK, r.Code)
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 |
- newAuthConfig := srv.registry.GetAuthConfig(false) |
|
| 59 |
+ newAuthConfig := registry.NewRegistry(runtime.root).GetAuthConfig(false) |
|
| 60 | 60 |
if newAuthConfig.Username != authConfig.Username || |
| 61 | 61 |
newAuthConfig.Email != authConfig.Email {
|
| 62 | 62 |
t.Fatalf("The auth configuration hasn't been set correctly")
|
| ... | ... |
@@ -247,8 +246,7 @@ func TestGetImagesSearch(t *testing.T) {
|
| 247 | 247 |
defer nuke(runtime) |
| 248 | 248 |
|
| 249 | 249 |
srv := &Server{
|
| 250 |
- runtime: runtime, |
|
| 251 |
- registry: registry.NewRegistry(runtime.root), |
|
| 250 |
+ runtime: runtime, |
|
| 252 | 251 |
} |
| 253 | 252 |
|
| 254 | 253 |
r := httptest.NewRecorder() |
| ... | ... |
@@ -504,15 +502,16 @@ func TestPostAuth(t *testing.T) {
|
| 504 | 504 |
defer nuke(runtime) |
| 505 | 505 |
|
| 506 | 506 |
srv := &Server{
|
| 507 |
- runtime: runtime, |
|
| 508 |
- registry: registry.NewRegistry(runtime.root), |
|
| 507 |
+ runtime: runtime, |
|
| 509 | 508 |
} |
| 510 | 509 |
|
| 511 |
- authConfigOrig := &auth.AuthConfig{
|
|
| 510 |
+ config := &auth.AuthConfig{
|
|
| 512 | 511 |
Username: "utest", |
| 513 | 512 |
Email: "utest@yopmail.com", |
| 514 | 513 |
} |
| 515 |
- srv.registry.ResetClient(authConfigOrig) |
|
| 514 |
+ |
|
| 515 |
+ authStr := auth.EncodeAuth(config) |
|
| 516 |
+ auth.SaveConfig(runtime.root, authStr, config.Email) |
|
| 516 | 517 |
|
| 517 | 518 |
r := httptest.NewRecorder() |
| 518 | 519 |
if err := getAuth(srv, API_VERSION, r, nil, nil); err != nil {
|
| ... | ... |
@@ -524,7 +523,7 @@ func TestPostAuth(t *testing.T) {
|
| 524 | 524 |
t.Fatal(err) |
| 525 | 525 |
} |
| 526 | 526 |
|
| 527 |
- if authConfig.Username != authConfigOrig.Username || authConfig.Email != authConfigOrig.Email {
|
|
| 527 |
+ if authConfig.Username != config.Username || authConfig.Email != config.Email {
|
|
| 528 | 528 |
t.Errorf("The retrieve auth mismatch with the one set.")
|
| 529 | 529 |
} |
| 530 | 530 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ package auth |
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/base64" |
| 5 | 5 |
"encoding/json" |
| 6 |
+ "errors" |
|
| 6 | 7 |
"fmt" |
| 7 | 8 |
"io/ioutil" |
| 8 | 9 |
"net/http" |
| ... | ... |
@@ -17,6 +18,12 @@ const CONFIGFILE = ".dockercfg" |
| 17 | 17 |
// the registry server we want to login against |
| 18 | 18 |
const INDEX_SERVER = "https://index.docker.io/v1" |
| 19 | 19 |
|
| 20 |
+//const INDEX_SERVER = "http://indexstaging-docker.dotcloud.com/" |
|
| 21 |
+ |
|
| 22 |
+var ( |
|
| 23 |
+ ErrConfigFileMissing error = errors.New("The Auth config file is missing")
|
|
| 24 |
+) |
|
| 25 |
+ |
|
| 20 | 26 |
type AuthConfig struct {
|
| 21 | 27 |
Username string `json:"username"` |
| 22 | 28 |
Password string `json:"password"` |
| ... | ... |
@@ -75,7 +82,7 @@ func DecodeAuth(authStr string) (*AuthConfig, error) {
|
| 75 | 75 |
func LoadConfig(rootPath string) (*AuthConfig, error) {
|
| 76 | 76 |
confFile := path.Join(rootPath, CONFIGFILE) |
| 77 | 77 |
if _, err := os.Stat(confFile); err != nil {
|
| 78 |
- return &AuthConfig{}, fmt.Errorf("The Auth config file is missing")
|
|
| 78 |
+ return nil, ErrConfigFileMissing |
|
| 79 | 79 |
} |
| 80 | 80 |
b, err := ioutil.ReadFile(confFile) |
| 81 | 81 |
if err != nil {
|
| ... | ... |
@@ -97,7 +104,7 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
|
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 | 99 |
// save the auth config |
| 100 |
-func saveConfig(rootPath, authStr string, email string) error {
|
|
| 100 |
+func SaveConfig(rootPath, authStr string, email string) error {
|
|
| 101 | 101 |
confFile := path.Join(rootPath, CONFIGFILE) |
| 102 | 102 |
if len(email) == 0 {
|
| 103 | 103 |
os.Remove(confFile) |
| ... | ... |
@@ -161,7 +168,9 @@ func Login(authConfig *AuthConfig) (string, error) {
|
| 161 | 161 |
status = "Login Succeeded\n" |
| 162 | 162 |
storeConfig = true |
| 163 | 163 |
} else if resp.StatusCode == 401 {
|
| 164 |
- saveConfig(authConfig.rootPath, "", "") |
|
| 164 |
+ if err := SaveConfig(authConfig.rootPath, "", ""); err != nil {
|
|
| 165 |
+ return "", err |
|
| 166 |
+ } |
|
| 165 | 167 |
return "", fmt.Errorf("Wrong login/password, please try again")
|
| 166 | 168 |
} else {
|
| 167 | 169 |
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body,
|
| ... | ... |
@@ -175,7 +184,9 @@ func Login(authConfig *AuthConfig) (string, error) {
|
| 175 | 175 |
} |
| 176 | 176 |
if storeConfig {
|
| 177 | 177 |
authStr := EncodeAuth(authConfig) |
| 178 |
- saveConfig(authConfig.rootPath, authStr, authConfig.Email) |
|
| 178 |
+ if err := SaveConfig(authConfig.rootPath, authStr, authConfig.Email); err != nil {
|
|
| 179 |
+ return "", err |
|
| 180 |
+ } |
|
| 179 | 181 |
} |
| 180 | 182 |
return status, nil |
| 181 | 183 |
} |
| ... | ... |
@@ -73,37 +73,37 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
| 73 | 73 |
} |
| 74 | 74 |
} |
| 75 | 75 |
help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.host, cli.port)
|
| 76 |
- for cmd, description := range map[string]string{
|
|
| 77 |
- "attach": "Attach to a running container", |
|
| 78 |
- "build": "Build a container from a Dockerfile", |
|
| 79 |
- "commit": "Create a new image from a container's changes", |
|
| 80 |
- "diff": "Inspect changes on a container's filesystem", |
|
| 81 |
- "export": "Stream the contents of a container as a tar archive", |
|
| 82 |
- "history": "Show the history of an image", |
|
| 83 |
- "images": "List images", |
|
| 84 |
- "import": "Create a new filesystem image from the contents of a tarball", |
|
| 85 |
- "info": "Display system-wide information", |
|
| 86 |
- "insert": "Insert a file in an image", |
|
| 87 |
- "inspect": "Return low-level information on a container", |
|
| 88 |
- "kill": "Kill a running container", |
|
| 89 |
- "login": "Register or Login to the docker registry server", |
|
| 90 |
- "logs": "Fetch the logs of a container", |
|
| 91 |
- "port": "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT", |
|
| 92 |
- "ps": "List containers", |
|
| 93 |
- "pull": "Pull an image or a repository from the docker registry server", |
|
| 94 |
- "push": "Push an image or a repository to the docker registry server", |
|
| 95 |
- "restart": "Restart a running container", |
|
| 96 |
- "rm": "Remove a container", |
|
| 97 |
- "rmi": "Remove an image", |
|
| 98 |
- "run": "Run a command in a new container", |
|
| 99 |
- "search": "Search for an image in the docker index", |
|
| 100 |
- "start": "Start a stopped container", |
|
| 101 |
- "stop": "Stop a running container", |
|
| 102 |
- "tag": "Tag an image into a repository", |
|
| 103 |
- "version": "Show the docker version information", |
|
| 104 |
- "wait": "Block until a container stops, then print its exit code", |
|
| 76 |
+ for _, command := range [][2]string{
|
|
| 77 |
+ {"attach", "Attach to a running container"},
|
|
| 78 |
+ {"build", "Build a container from a Dockerfile"},
|
|
| 79 |
+ {"commit", "Create a new image from a container's changes"},
|
|
| 80 |
+ {"diff", "Inspect changes on a container's filesystem"},
|
|
| 81 |
+ {"export", "Stream the contents of a container as a tar archive"},
|
|
| 82 |
+ {"history", "Show the history of an image"},
|
|
| 83 |
+ {"images", "List images"},
|
|
| 84 |
+ {"import", "Create a new filesystem image from the contents of a tarball"},
|
|
| 85 |
+ {"info", "Display system-wide information"},
|
|
| 86 |
+ {"insert", "Insert a file in an image"},
|
|
| 87 |
+ {"inspect", "Return low-level information on a container"},
|
|
| 88 |
+ {"kill", "Kill a running container"},
|
|
| 89 |
+ {"login", "Register or Login to the docker registry server"},
|
|
| 90 |
+ {"logs", "Fetch the logs of a container"},
|
|
| 91 |
+ {"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
|
|
| 92 |
+ {"ps", "List containers"},
|
|
| 93 |
+ {"pull", "Pull an image or a repository from the docker registry server"},
|
|
| 94 |
+ {"push", "Push an image or a repository to the docker registry server"},
|
|
| 95 |
+ {"restart", "Restart a running container"},
|
|
| 96 |
+ {"rm", "Remove a container"},
|
|
| 97 |
+ {"rmi", "Remove an image"},
|
|
| 98 |
+ {"run", "Run a command in a new container"},
|
|
| 99 |
+ {"search", "Search for an image in the docker index"},
|
|
| 100 |
+ {"start", "Start a stopped container"},
|
|
| 101 |
+ {"stop", "Stop a running container"},
|
|
| 102 |
+ {"tag", "Tag an image into a repository"},
|
|
| 103 |
+ {"version", "Show the docker version information"},
|
|
| 104 |
+ {"wait", "Block until a container stops}, then print its exit code"},
|
|
| 105 | 105 |
} {
|
| 106 |
- help += fmt.Sprintf(" %-10.10s%s\n", cmd, description)
|
|
| 106 |
+ help += fmt.Sprintf(" %-10.10s%s\n", command[0], command[1])
|
|
| 107 | 107 |
} |
| 108 | 108 |
fmt.Println(help) |
| 109 | 109 |
return nil |
| ... | ... |
@@ -367,12 +367,10 @@ func (cli *DockerCli) CmdWait(args ...string) error {
|
| 367 | 367 |
// 'docker version': show version information |
| 368 | 368 |
func (cli *DockerCli) CmdVersion(args ...string) error {
|
| 369 | 369 |
cmd := Subcmd("version", "", "Show the docker version information.")
|
| 370 |
- fmt.Println(len(args)) |
|
| 371 | 370 |
if err := cmd.Parse(args); err != nil {
|
| 372 | 371 |
return nil |
| 373 | 372 |
} |
| 374 | 373 |
|
| 375 |
- fmt.Println(cmd.NArg()) |
|
| 376 | 374 |
if cmd.NArg() > 0 {
|
| 377 | 375 |
cmd.Usage() |
| 378 | 376 |
return nil |
| ... | ... |
@@ -330,6 +330,9 @@ func (r *Registry) PushImageJsonIndex(remote string, imgList []*ImgData, validat |
| 330 | 330 |
if validate {
|
| 331 | 331 |
suffix = "images" |
| 332 | 332 |
} |
| 333 |
+ |
|
| 334 |
+ utils.Debugf("Image list pushed to index:\n%s\n", imgListJson)
|
|
| 335 |
+ |
|
| 333 | 336 |
req, err := http.NewRequest("PUT", auth.IndexServerAddress()+"/repositories/"+remote+"/"+suffix, bytes.NewReader(imgListJson))
|
| 334 | 337 |
if err != nil {
|
| 335 | 338 |
return nil, err |
| ... | ... |
@@ -2,7 +2,6 @@ package docker |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "github.com/dotcloud/docker/registry" |
|
| 6 | 5 |
"github.com/dotcloud/docker/utils" |
| 7 | 6 |
"io" |
| 8 | 7 |
"io/ioutil" |
| ... | ... |
@@ -63,8 +62,7 @@ func init() {
|
| 63 | 63 |
|
| 64 | 64 |
// Create the "Server" |
| 65 | 65 |
srv := &Server{
|
| 66 |
- runtime: runtime, |
|
| 67 |
- registry: registry.NewRegistry(runtime.root), |
|
| 66 |
+ runtime: runtime, |
|
| 68 | 67 |
} |
| 69 | 68 |
// Retrieve the Image |
| 70 | 69 |
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, utils.NewStreamFormatter(false)); err != nil {
|
| ... | ... |
@@ -49,7 +49,8 @@ func (srv *Server) ContainerExport(name string, out io.Writer) error {
|
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
|
| 52 |
- results, err := srv.registry.SearchRepositories(term) |
|
| 52 |
+ |
|
| 53 |
+ results, err := registry.NewRegistry(srv.runtime.root).SearchRepositories(term) |
|
| 53 | 54 |
if err != nil {
|
| 54 | 55 |
return nil, err |
| 55 | 56 |
} |
| ... | ... |
@@ -291,8 +292,8 @@ func (srv *Server) ContainerTag(name, repo, tag string, force bool) error {
|
| 291 | 291 |
return nil |
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 |
-func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []string, sf *utils.StreamFormatter) error {
|
|
| 295 |
- history, err := srv.registry.GetRemoteHistory(imgId, registry, token) |
|
| 294 |
+func (srv *Server) pullImage(r *registry.Registry, out io.Writer, imgId, endpoint string, token []string, sf *utils.StreamFormatter) error {
|
|
| 295 |
+ history, err := r.GetRemoteHistory(imgId, endpoint, token) |
|
| 296 | 296 |
if err != nil {
|
| 297 | 297 |
return err |
| 298 | 298 |
} |
| ... | ... |
@@ -302,7 +303,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri |
| 302 | 302 |
for _, id := range history {
|
| 303 | 303 |
if !srv.runtime.graph.Exists(id) {
|
| 304 | 304 |
out.Write(sf.FormatStatus("Pulling %s metadata", id))
|
| 305 |
- imgJson, err := srv.registry.GetRemoteImageJson(id, registry, token) |
|
| 305 |
+ imgJson, err := r.GetRemoteImageJson(id, endpoint, token) |
|
| 306 | 306 |
if err != nil {
|
| 307 | 307 |
// FIXME: Keep goging in case of error? |
| 308 | 308 |
return err |
| ... | ... |
@@ -314,7 +315,7 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri |
| 314 | 314 |
|
| 315 | 315 |
// Get the layer |
| 316 | 316 |
out.Write(sf.FormatStatus("Pulling %s fs layer", id))
|
| 317 |
- layer, contentLength, err := srv.registry.GetRemoteImageLayer(img.Id, registry, token) |
|
| 317 |
+ layer, contentLength, err := r.GetRemoteImageLayer(img.Id, endpoint, token) |
|
| 318 | 318 |
if err != nil {
|
| 319 | 319 |
return err |
| 320 | 320 |
} |
| ... | ... |
@@ -326,9 +327,9 @@ func (srv *Server) pullImage(out io.Writer, imgId, registry string, token []stri |
| 326 | 326 |
return nil |
| 327 | 327 |
} |
| 328 | 328 |
|
| 329 |
-func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *utils.StreamFormatter) error {
|
|
| 329 |
+func (srv *Server) pullRepository(r *registry.Registry, out io.Writer, remote, askedTag string, sf *utils.StreamFormatter) error {
|
|
| 330 | 330 |
out.Write(sf.FormatStatus("Pulling repository %s from %s", remote, auth.IndexServerAddress()))
|
| 331 |
- repoData, err := srv.registry.GetRepositoryData(remote) |
|
| 331 |
+ repoData, err := r.GetRepositoryData(remote) |
|
| 332 | 332 |
if err != nil {
|
| 333 | 333 |
return err |
| 334 | 334 |
} |
| ... | ... |
@@ -340,7 +341,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *ut |
| 340 | 340 |
} |
| 341 | 341 |
|
| 342 | 342 |
utils.Debugf("Retrieving the tag list")
|
| 343 |
- tagsList, err := srv.registry.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens) |
|
| 343 |
+ tagsList, err := r.GetRemoteTags(repoData.Endpoints, remote, repoData.Tokens) |
|
| 344 | 344 |
if err != nil {
|
| 345 | 345 |
return err |
| 346 | 346 |
} |
| ... | ... |
@@ -367,7 +368,7 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *ut |
| 367 | 367 |
out.Write(sf.FormatStatus("Pulling image %s (%s) from %s", img.Id, img.Tag, remote))
|
| 368 | 368 |
success := false |
| 369 | 369 |
for _, ep := range repoData.Endpoints {
|
| 370 |
- if err := srv.pullImage(out, img.Id, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
|
|
| 370 |
+ if err := srv.pullImage(r, out, img.Id, "https://"+ep+"/v1", repoData.Tokens, sf); err != nil {
|
|
| 371 | 371 |
out.Write(sf.FormatStatus("Error while retrieving image for tag: %s (%s); checking next endpoint", askedTag, err))
|
| 372 | 372 |
continue |
| 373 | 373 |
} |
| ... | ... |
@@ -393,16 +394,17 @@ func (srv *Server) pullRepository(out io.Writer, remote, askedTag string, sf *ut |
| 393 | 393 |
return nil |
| 394 | 394 |
} |
| 395 | 395 |
|
| 396 |
-func (srv *Server) ImagePull(name, tag, registry string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
| 396 |
+func (srv *Server) ImagePull(name, tag, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
| 397 |
+ r := registry.NewRegistry(srv.runtime.root) |
|
| 397 | 398 |
out = utils.NewWriteFlusher(out) |
| 398 |
- if registry != "" {
|
|
| 399 |
- if err := srv.pullImage(out, name, registry, nil, sf); err != nil {
|
|
| 399 |
+ if endpoint != "" {
|
|
| 400 |
+ if err := srv.pullImage(r, out, name, endpoint, nil, sf); err != nil {
|
|
| 400 | 401 |
return err |
| 401 | 402 |
} |
| 402 | 403 |
return nil |
| 403 | 404 |
} |
| 404 | 405 |
|
| 405 |
- if err := srv.pullRepository(out, name, tag, sf); err != nil {
|
|
| 406 |
+ if err := srv.pullRepository(r, out, name, tag, sf); err != nil {
|
|
| 406 | 407 |
return err |
| 407 | 408 |
} |
| 408 | 409 |
|
| ... | ... |
@@ -475,7 +477,7 @@ func (srv *Server) getImageList(localRepo map[string]string) ([]*registry.ImgDat |
| 475 | 475 |
return imgList, nil |
| 476 | 476 |
} |
| 477 | 477 |
|
| 478 |
-func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[string]string, sf *utils.StreamFormatter) error {
|
|
| 478 |
+func (srv *Server) pushRepository(r *registry.Registry, out io.Writer, name string, localRepo map[string]string, sf *utils.StreamFormatter) error {
|
|
| 479 | 479 |
out = utils.NewWriteFlusher(out) |
| 480 | 480 |
out.Write(sf.FormatStatus("Processing checksums"))
|
| 481 | 481 |
imgList, err := srv.getImageList(localRepo) |
| ... | ... |
@@ -484,12 +486,11 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri |
| 484 | 484 |
} |
| 485 | 485 |
out.Write(sf.FormatStatus("Sending image list"))
|
| 486 | 486 |
|
| 487 |
- repoData, err := srv.registry.PushImageJsonIndex(name, imgList, false) |
|
| 487 |
+ repoData, err := r.PushImageJsonIndex(name, imgList, false) |
|
| 488 | 488 |
if err != nil {
|
| 489 | 489 |
return err |
| 490 | 490 |
} |
| 491 | 491 |
|
| 492 |
- // FIXME: Send only needed images |
|
| 493 | 492 |
for _, ep := range repoData.Endpoints {
|
| 494 | 493 |
out.Write(sf.FormatStatus("Pushing repository %s to %s (%d tags)", name, ep, len(localRepo)))
|
| 495 | 494 |
// For each image within the repo, push them |
| ... | ... |
@@ -498,24 +499,24 @@ func (srv *Server) pushRepository(out io.Writer, name string, localRepo map[stri |
| 498 | 498 |
out.Write(sf.FormatStatus("Image %s already on registry, skipping", name))
|
| 499 | 499 |
continue |
| 500 | 500 |
} |
| 501 |
- if err := srv.pushImage(out, name, elem.Id, ep, repoData.Tokens, sf); err != nil {
|
|
| 501 |
+ if err := srv.pushImage(r, out, name, elem.Id, ep, repoData.Tokens, sf); err != nil {
|
|
| 502 | 502 |
// FIXME: Continue on error? |
| 503 | 503 |
return err |
| 504 | 504 |
} |
| 505 | 505 |
out.Write(sf.FormatStatus("Pushing tags for rev [%s] on {%s}", elem.Id, ep+"/users/"+name+"/"+elem.Tag))
|
| 506 |
- if err := srv.registry.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
| 506 |
+ if err := r.PushRegistryTag(name, elem.Id, elem.Tag, ep, repoData.Tokens); err != nil {
|
|
| 507 | 507 |
return err |
| 508 | 508 |
} |
| 509 | 509 |
} |
| 510 | 510 |
} |
| 511 | 511 |
|
| 512 |
- if _, err := srv.registry.PushImageJsonIndex(name, imgList, true); err != nil {
|
|
| 512 |
+ if _, err := r.PushImageJsonIndex(name, imgList, true); err != nil {
|
|
| 513 | 513 |
return err |
| 514 | 514 |
} |
| 515 | 515 |
return nil |
| 516 | 516 |
} |
| 517 | 517 |
|
| 518 |
-func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []string, sf *utils.StreamFormatter) error {
|
|
| 518 |
+func (srv *Server) pushImage(r *registry.Registry, out io.Writer, remote, imgId, ep string, token []string, sf *utils.StreamFormatter) error {
|
|
| 519 | 519 |
out = utils.NewWriteFlusher(out) |
| 520 | 520 |
jsonRaw, err := ioutil.ReadFile(path.Join(srv.runtime.graph.Root, imgId, "json")) |
| 521 | 521 |
if err != nil {
|
| ... | ... |
@@ -534,7 +535,7 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st |
| 534 | 534 |
} |
| 535 | 535 |
|
| 536 | 536 |
// Send the json |
| 537 |
- if err := srv.registry.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
| 537 |
+ if err := r.PushImageJsonRegistry(imgData, jsonRaw, ep, token); err != nil {
|
|
| 538 | 538 |
if err == registry.ErrAlreadyExists {
|
| 539 | 539 |
out.Write(sf.FormatStatus("Image %s already uploaded ; skipping", imgData.Id))
|
| 540 | 540 |
return nil |
| ... | ... |
@@ -569,20 +570,22 @@ func (srv *Server) pushImage(out io.Writer, remote, imgId, ep string, token []st |
| 569 | 569 |
} |
| 570 | 570 |
|
| 571 | 571 |
// Send the layer |
| 572 |
- if err := srv.registry.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "%v/%v (%v)"), sf), ep, token); err != nil {
|
|
| 572 |
+ if err := r.PushImageLayerRegistry(imgData.Id, utils.ProgressReader(layerData, int(layerData.Size), out, sf.FormatProgress("", "%v/%v (%v)"), sf), ep, token); err != nil {
|
|
| 573 | 573 |
return err |
| 574 | 574 |
} |
| 575 | 575 |
return nil |
| 576 | 576 |
} |
| 577 | 577 |
|
| 578 |
-func (srv *Server) ImagePush(name, registry string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
| 578 |
+func (srv *Server) ImagePush(name, endpoint string, out io.Writer, sf *utils.StreamFormatter) error {
|
|
| 579 | 579 |
out = utils.NewWriteFlusher(out) |
| 580 | 580 |
img, err := srv.runtime.graph.Get(name) |
| 581 |
+ r := registry.NewRegistry(srv.runtime.root) |
|
| 582 |
+ |
|
| 581 | 583 |
if err != nil {
|
| 582 | 584 |
out.Write(sf.FormatStatus("The push refers to a repository [%s] (len: %d)", name, len(srv.runtime.repositories.Repositories[name])))
|
| 583 | 585 |
// If it fails, try to get the repository |
| 584 | 586 |
if localRepo, exists := srv.runtime.repositories.Repositories[name]; exists {
|
| 585 |
- if err := srv.pushRepository(out, name, localRepo, sf); err != nil {
|
|
| 587 |
+ if err := srv.pushRepository(r, out, name, localRepo, sf); err != nil {
|
|
| 586 | 588 |
return err |
| 587 | 589 |
} |
| 588 | 590 |
return nil |
| ... | ... |
@@ -591,7 +594,7 @@ func (srv *Server) ImagePush(name, registry string, out io.Writer, sf *utils.Str |
| 591 | 591 |
return err |
| 592 | 592 |
} |
| 593 | 593 |
out.Write(sf.FormatStatus("The push refers to an image: [%s]", name))
|
| 594 |
- if err := srv.pushImage(out, name, img.Id, registry, nil, sf); err != nil {
|
|
| 594 |
+ if err := srv.pushImage(r, out, name, img.Id, endpoint, nil, sf); err != nil {
|
|
| 595 | 595 |
return err |
| 596 | 596 |
} |
| 597 | 597 |
return nil |
| ... | ... |
@@ -871,14 +874,12 @@ func NewServer(autoRestart bool) (*Server, error) {
|
| 871 | 871 |
return nil, err |
| 872 | 872 |
} |
| 873 | 873 |
srv := &Server{
|
| 874 |
- runtime: runtime, |
|
| 875 |
- registry: registry.NewRegistry(runtime.root), |
|
| 874 |
+ runtime: runtime, |
|
| 876 | 875 |
} |
| 877 | 876 |
runtime.srv = srv |
| 878 | 877 |
return srv, nil |
| 879 | 878 |
} |
| 880 | 879 |
|
| 881 | 880 |
type Server struct {
|
| 882 |
- runtime *Runtime |
|
| 883 |
- registry *registry.Registry |
|
| 881 |
+ runtime *Runtime |
|
| 884 | 882 |
} |
| ... | ... |
@@ -105,7 +105,7 @@ func (r *progressReader) Close() error {
|
| 105 | 105 |
func ProgressReader(r io.ReadCloser, size int, output io.Writer, template []byte, sf *StreamFormatter) *progressReader {
|
| 106 | 106 |
tpl := string(template) |
| 107 | 107 |
if tpl == "" {
|
| 108 |
- tpl = "%v/%v (%v)" |
|
| 108 |
+ tpl = string(sf.FormatProgress("", "%v/%v (%v)"))
|
|
| 109 | 109 |
} |
| 110 | 110 |
return &progressReader{r, NewWriteFlusher(output), size, 0, 0, tpl, sf}
|
| 111 | 111 |
} |