Преглед на файлове

Merge branch 'master' into attach-stdin

Solomon Hykes преди 12 години
родител
ревизия
14d9f51bbe
променени са 8 файла, в които са добавени 95 реда и са изтрити 37 реда
  1. 36 12
      CONTRIBUTING.md
  2. 1 1
      Makefile
  3. 2 2
      auth/auth.go
  4. 3 1
      docker/docker.go
  5. 37 12
      docs/sources/contributing/contributing.rst
  6. 2 2
      docs/sources/contributing/devenvironment.rst
  7. 13 6
      registry.go
  8. 1 1
      utils.go

+ 36 - 12
CONTRIBUTING.md

@@ -49,21 +49,45 @@ help prioritize the most common problems and requests.
 
 Fork the repo and make changes on your fork in a feature branch:
 
-- If it's a bugfix branch, name it XXX-something where XXX is the number of the issue
-- If it's a feature branch, create an enhancement issue to announce your intentions, and name it XXX-something where XXX is the number of the issue.
+- If it's a bugfix branch, name it XXX-something where XXX is the number of the
+  issue
+- If it's a feature branch, create an enhancement issue to announce your
+  intentions, and name it XXX-something where XXX is the number of the issue.
 
-Submit unit tests for your changes.  Golang has a great testing suite built
-in: use it! Take a look at existing tests for inspiration. Run the full test
-suite against your change and the master.
+Submit unit tests for your changes.  Go has a great test framework built in; use
+it! Take a look at existing tests for inspiration. Run the full test suite on
+your branch before submitting a pull request.
 
-Submit any relevant updates or additions to documentation.
+Make sure you include relevant updates or additions to documentation when
+creating or modifying features.
 
-Add clean code:
+Write clean code. Universally formatted code promotes ease of writing, reading,
+and maintenance. Always run `go fmt` before committing your changes. Most
+editors have plugins that do this automatically, and there's also a git
+pre-commit hook:
 
-- Universally formatted code promotes ease of writing, reading, and maintenance.  We suggest using gofmt before committing your changes. There's a git pre-commit hook made for doing so.
-- curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
+```
+curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
+```
 
 Pull requests descriptions should be as clear as possible and include a
-referenced to all the issues that they address.
-
-Add your name to the AUTHORS file.
+reference to all the issues that they address.
+
+Code review comments may be added to your pull request. Discuss, then make the
+suggested modifications and push additional commits to your feature branch. Be
+sure to post a comment after pushing. The new commits will show up in the pull
+request automatically, but the reviewers will not be notified unless you
+comment.
+
+Before the pull request is merged, make sure that you squash your commits into
+logical units of work using `git rebase -i` and `git push -f`. After every
+commit the test suite should be passing. Include documentation changes in the
+same commit so that a revert would remove all traces of the feature or fix.
+
+Commits that fix or close an issue should include a reference like `Closes #XXX`
+or `Fixes #XXX`, which will automatically close the issue when merged.
+
+Add your name to the AUTHORS file, but make sure the list is sorted and your
+name and email address match your git configuration. The AUTHORS file is
+regenerated occasionally from the git commit history, so a mismatch may result
+in your changes being overwritten.

+ 1 - 1
Makefile

@@ -43,4 +43,4 @@ test: all
 	@(cd $(DOCKER_DIR); sudo -E go test $(GO_OPTIONS))
 
 fmt:
-	@find . -name "*.go" -exec gofmt -l -w {} \;
+	@gofmt -s -l -w .

+ 2 - 2
auth/auth.go

@@ -1,7 +1,6 @@
 package auth
 
 import (
-	"bytes"
 	"encoding/base64"
 	"encoding/json"
 	"errors"
@@ -112,7 +111,8 @@ func Login(authConfig *AuthConfig) (string, error) {
 		return "", errors.New(errMsg)
 	}
 
-	b := bytes.NewReader(jsonBody)
+	// using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status.
+	b := strings.NewReader(string(jsonBody))
 	req1, err := http.Post(REGISTRY_SERVER+"/v1/users", "application/json; charset=utf-8", b)
 	if err != nil {
 		errMsg = fmt.Sprintf("Server Error: %s", err)

+ 3 - 1
docker/docker.go

@@ -21,7 +21,9 @@ func main() {
 	flDaemon := flag.Bool("d", false, "Daemon mode")
 	flDebug := flag.Bool("D", false, "Debug mode")
 	flag.Parse()
-	rcli.DEBUG_FLAG = *flDebug
+	if *flDebug {
+		os.Setenv("DEBUG", "1")
+	}
 	if *flDaemon {
 		if flag.NArg() != 0 {
 			flag.Usage()

+ 37 - 12
docs/sources/contributing/contributing.rst

@@ -56,21 +56,46 @@ Conventions
 
 Fork the repo and make changes on your fork in a feature branch:
 
-- If it's a bugfix branch, name it XXX-something where XXX is the number of the issue
-- If it's a feature branch, create an enhancement issue to announce your intentions, and name it XXX-something where XXX is the number of the issue.
+- If it's a bugfix branch, name it XXX-something where XXX is the number of the
+  issue
+- If it's a feature branch, create an enhancement issue to announce your
+  intentions, and name it XXX-something where XXX is the number of the issue.
 
-Submit unit tests for your changes.  Golang has a great testing suite built
-in: use it! Take a look at existing tests for inspiration. Run the full test
-suite against your change and the master.
+Submit unit tests for your changes.  Go has a great test framework built in; use
+it! Take a look at existing tests for inspiration. Run the full test suite on
+your branch before submitting a pull request.
 
-Submit any relevant updates or additions to documentation.
+Make sure you include relevant updates or additions to documentation when
+creating or modifying features.
 
-Add clean code:
+Write clean code. Universally formatted code promotes ease of writing, reading,
+and maintenance. Always run ``go fmt`` before committing your changes. Most
+editors have plugins that do this automatically, and there's also a git
+pre-commit hook:
 
-- Universally formatted code promotes ease of writing, reading, and maintenance.  We suggest using gofmt before committing your changes. There's a git pre-commit hook made for doing so.
-- curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
+.. code-block:: bash
+
+    curl -o .git/hooks/pre-commit https://raw.github.com/edsrzf/gofmt-git-hook/master/fmt-check && chmod +x .git/hooks/pre-commit
 
-Pull requests descriptions should be as clear as possible and include a
-referenced to all the issues that they address.
 
-Add your name to the AUTHORS file.
+Pull requests descriptions should be as clear as possible and include a
+reference to all the issues that they address.
+
+Code review comments may be added to your pull request. Discuss, then make the
+suggested modifications and push additional commits to your feature branch. Be
+sure to post a comment after pushing. The new commits will show up in the pull
+request automatically, but the reviewers will not be notified unless you
+comment.
+
+Before the pull request is merged, make sure that you squash your commits into
+logical units of work using ``git rebase -i`` and ``git push -f``. After every
+commit the test suite should be passing. Include documentation changes in the
+same commit so that a revert would remove all traces of the feature or fix.
+
+Commits that fix or close an issue should include a reference like ``Closes #XXX``
+or ``Fixes #XXX``, which will automatically close the issue when merged.
+
+Add your name to the AUTHORS file, but make sure the list is sorted and your
+name and email address match your git configuration. The AUTHORS file is
+regenerated occasionally from the git commit history, so a mismatch may result
+in your changes being overwritten.

+ 2 - 2
docs/sources/contributing/devenvironment.rst

@@ -7,7 +7,7 @@ Setting up a dev environment
 
 Instructions that have been verified to work on Ubuntu 12.10,
 
-.. code:: bash
+.. code-block:: bash
 
     sudo apt-get -y install lxc wget bsdtar curl golang git
 
@@ -24,7 +24,7 @@ Instructions that have been verified to work on Ubuntu 12.10,
 
 Then run the docker daemon,
 
-.. code:: bash
+.. code-block:: bash
 
     sudo $GOPATH/bin/docker -d
 

+ 13 - 6
registry.go

@@ -184,10 +184,10 @@ func (graph *Graph) PullRepository(stdout io.Writer, remote, askedTag string, re
 	if err != nil {
 		return err
 	}
+	defer res.Body.Close()
 	if res.StatusCode != 200 {
 		return fmt.Errorf("HTTP code: %d", res.StatusCode)
 	}
-	defer res.Body.Close()
 	rawJson, err := ioutil.ReadAll(res.Body)
 	if err != nil {
 		return err
@@ -238,6 +238,7 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth
 		if err != nil {
 			return fmt.Errorf("Failed to upload metadata: %s", err)
 		}
+		defer res.Body.Close()
 		if res.StatusCode != 200 {
 			switch res.StatusCode {
 			case 204:
@@ -257,9 +258,13 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth
 		req2, err := http.NewRequest("PUT", REGISTRY_ENDPOINT+"/images/"+img.Id+"/layer", nil)
 		req2.SetBasicAuth(authConfig.Username, authConfig.Password)
 		res2, err := client.Do(req2)
-		if err != nil || res2.StatusCode != 307 {
+		if err != nil {
 			return fmt.Errorf("Registry returned error: %s", err)
 		}
+		res2.Body.Close()
+		if res2.StatusCode != 307 {
+			return fmt.Errorf("Registry returned unexpected HTTP status code %d, expected 307", res2.StatusCode)
+		}
 		url, err := res2.Location()
 		if err != nil || url == nil {
 			return fmt.Errorf("Failed to retrieve layer upload location: %s", err)
@@ -289,6 +294,7 @@ func (graph *Graph) PushImage(stdout io.Writer, imgOrig *Image, authConfig *auth
 		if err != nil {
 			return fmt.Errorf("Failed to upload layer: %s", err)
 		}
+		res3.Body.Close()
 		if res3.StatusCode != 200 {
 			return fmt.Errorf("Received HTTP code %d while uploading layer", res3.StatusCode)
 		}
@@ -318,12 +324,13 @@ func (graph *Graph) pushTag(remote, revision, tag string, authConfig *auth.AuthC
 	req.Header.Add("Content-type", "application/json")
 	req.SetBasicAuth(authConfig.Username, authConfig.Password)
 	res, err := client.Do(req)
-	if err != nil || (res.StatusCode != 200 && res.StatusCode != 201) {
-		if res != nil {
-			return fmt.Errorf("Internal server error: %d trying to push tag %s on %s", res.StatusCode, tag, remote)
-		}
+	if err != nil {
 		return err
 	}
+	res.Body.Close()
+	if res.StatusCode != 200 && res.StatusCode != 201 {
+		return fmt.Errorf("Internal server error: %d trying to push tag %s on %s", res.StatusCode, tag, remote)
+	}
 	Debugf("Result of push tag: %d\n", res.StatusCode)
 	switch res.StatusCode {
 	default:

+ 1 - 1
utils.go

@@ -45,7 +45,7 @@ func Download(url string, stderr io.Writer) (*http.Response, error) {
 // Debug function, if the debug flag is set, then display. Do nothing otherwise
 // If Docker is in damon mode, also send the debug info on the socket
 func Debugf(format string, a ...interface{}) {
-	if rcli.DEBUG_FLAG {
+	if os.Getenv("DEBUG") != "" {
 
 		// Retrieve the stack infos
 		_, file, line, ok := runtime.Caller(1)