[ARVADOS] updated: e89f1989b5ec963e5cf2930e117d0933c6d70d55

Git user git at public.curoverse.com
Wed Sep 21 09:36:04 EDT 2016


Summary of changes:
 services/arv-git-httpd/auth_handler.go     |  4 ++--
 services/arv-git-httpd/git_handler.go      |  4 ++--
 services/arv-git-httpd/gitolite_test.go    |  2 +-
 services/arv-git-httpd/integration_test.go |  2 +-
 services/arv-git-httpd/main.go             | 30 +++++++++++++++++++-----------
 services/arv-git-httpd/usage.go            |  2 +-
 6 files changed, 26 insertions(+), 18 deletions(-)

  discards  7ae8a85e20ae45d3a3a4721e86bed5249902400c (commit)
  discards  de1b66094d5a477a444246ba03a5f51e0b7f6da0 (commit)
       via  e89f1989b5ec963e5cf2930e117d0933c6d70d55 (commit)
       via  8b16345b6f71f638f34ebaed653a3b5ddbf216b4 (commit)
       via  10eaeae80362923facd3041fcafe8859d07ba4c5 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (7ae8a85e20ae45d3a3a4721e86bed5249902400c)
            \
             N -- N -- N (e89f1989b5ec963e5cf2930e117d0933c6d70d55)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit e89f1989b5ec963e5cf2930e117d0933c6d70d55
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Sep 20 21:28:00 2016 -0400

    9950: Add systemd unit file arv-git-httpd.service.

diff --git a/services/arv-git-httpd/arv-git-httpd.service b/services/arv-git-httpd/arv-git-httpd.service
new file mode 100644
index 0000000..1182a0e
--- /dev/null
+++ b/services/arv-git-httpd/arv-git-httpd.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Arvados git server
+Documentation=https://doc.arvados.org/
+After=network.target
+
+[Service]
+Type=notify
+ExecStart=/usr/bin/arv-git-httpd
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/services/arv-git-httpd/main.go b/services/arv-git-httpd/main.go
index ce18b71..ccee20e 100644
--- a/services/arv-git-httpd/main.go
+++ b/services/arv-git-httpd/main.go
@@ -9,6 +9,7 @@ import (
 
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
 	"git.curoverse.com/arvados.git/sdk/go/config"
+	"github.com/coreos/go-systemd/daemon"
 )
 
 // Server configuration
@@ -77,6 +78,9 @@ func main() {
 	if err := srv.Start(); err != nil {
 		log.Fatal(err)
 	}
+	if _, err := daemon.SdNotify("READY=1"); err != nil {
+		log.Printf("Error notifying init daemon: %v", err)
+	}
 	log.Println("Listening at", srv.Addr)
 	log.Println("Repository root", theConfig.RepoRoot)
 	if err := srv.Wait(); err != nil {

commit 8b16345b6f71f638f34ebaed653a3b5ddbf216b4
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Sep 21 09:35:27 2016 -0400

    9950: Rename Root config to RepoRoot.

diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go
index 6ba0f38..3186501 100644
--- a/services/arv-git-httpd/auth_handler.go
+++ b/services/arv-git-httpd/auth_handler.go
@@ -137,7 +137,7 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 		"/" + repoName + "/.git",
 	}
 	for _, dir := range tryDirs {
-		if fileInfo, err := os.Stat(theConfig.Root + dir); err != nil {
+		if fileInfo, err := os.Stat(theConfig.RepoRoot + dir); err != nil {
 			if !os.IsNotExist(err) {
 				statusCode, statusText = http.StatusInternalServerError, err.Error()
 				return
@@ -149,7 +149,7 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 	}
 	if rewrittenPath == "" {
 		log.Println("WARNING:", repoUUID,
-			"git directory not found in", theConfig.Root, tryDirs)
+			"git directory not found in", theConfig.RepoRoot, tryDirs)
 		// We say "content not found" to disambiguate from the
 		// earlier "API says that repo does not exist" error.
 		statusCode, statusText = http.StatusNotFound, "content not found"
diff --git a/services/arv-git-httpd/git_handler.go b/services/arv-git-httpd/git_handler.go
index f4baa72..f0b98fa 100644
--- a/services/arv-git-httpd/git_handler.go
+++ b/services/arv-git-httpd/git_handler.go
@@ -19,9 +19,9 @@ func newGitHandler() http.Handler {
 	return &gitHandler{
 		Handler: cgi.Handler{
 			Path: theConfig.GitCommand,
-			Dir:  theConfig.Root,
+			Dir:  theConfig.RepoRoot,
 			Env: []string{
-				"GIT_PROJECT_ROOT=" + theConfig.Root,
+				"GIT_PROJECT_ROOT=" + theConfig.RepoRoot,
 				"GIT_HTTP_EXPORT_ALL=",
 				"SERVER_ADDR=" + theConfig.Listen,
 			},
diff --git a/services/arv-git-httpd/gitolite_test.go b/services/arv-git-httpd/gitolite_test.go
index 96d9d24..d21a814 100644
--- a/services/arv-git-httpd/gitolite_test.go
+++ b/services/arv-git-httpd/gitolite_test.go
@@ -48,7 +48,7 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
 		},
 		Listen:     ":0",
 		GitCommand: "/usr/share/gitolite3/gitolite-shell",
-		Root:       s.tmpRepoRoot,
+		RepoRoot:   s.tmpRepoRoot,
 	}
 	s.IntegrationSuite.SetUpTest(c)
 
diff --git a/services/arv-git-httpd/integration_test.go b/services/arv-git-httpd/integration_test.go
index a548d6d..5ec5ccb 100644
--- a/services/arv-git-httpd/integration_test.go
+++ b/services/arv-git-httpd/integration_test.go
@@ -74,7 +74,7 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 			},
 			Listen:     ":0",
 			GitCommand: "/usr/bin/git",
-			Root:       s.tmpRepoRoot,
+			RepoRoot:   s.tmpRepoRoot,
 		}
 	}
 	theConfig = s.Config
diff --git a/services/arv-git-httpd/main.go b/services/arv-git-httpd/main.go
index 202e0a2..ce18b71 100644
--- a/services/arv-git-httpd/main.go
+++ b/services/arv-git-httpd/main.go
@@ -16,7 +16,7 @@ type Config struct {
 	Client     arvados.Client
 	Listen     string
 	GitCommand string
-	Root       string
+	RepoRoot   string
 }
 
 var theConfig = defaultConfig()
@@ -29,7 +29,7 @@ func defaultConfig() *Config {
 	return &Config{
 		Listen:     ":80",
 		GitCommand: "/usr/bin/git",
-		Root:       cwd,
+		RepoRoot:   cwd,
 	}
 }
 
@@ -40,7 +40,7 @@ func init() {
 		"Address to listen on, \"host:port\" or \":port\"."+deprecated)
 	flag.StringVar(&theConfig.GitCommand, "git-command", theConfig.GitCommand,
 		"Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
-	flag.StringVar(&theConfig.Root, "repo-root", theConfig.Root,
+	flag.StringVar(&theConfig.RepoRoot, "repo-root", theConfig.RepoRoot,
 		"Path to git repositories."+deprecated)
 
 	cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
@@ -78,7 +78,7 @@ func main() {
 		log.Fatal(err)
 	}
 	log.Println("Listening at", srv.Addr)
-	log.Println("Repository root", theConfig.Root)
+	log.Println("Repository root", theConfig.RepoRoot)
 	if err := srv.Wait(); err != nil {
 		log.Fatal(err)
 	}
diff --git a/services/arv-git-httpd/usage.go b/services/arv-git-httpd/usage.go
index 649fb10..a4a9900 100644
--- a/services/arv-git-httpd/usage.go
+++ b/services/arv-git-httpd/usage.go
@@ -54,7 +54,7 @@ GitCommand:
     request will execute this program with the single argument
     "http-backend".
 
-Root:
+RepoRoot:
 
     Path to git repositories. Defaults to current working directory.
 

commit 10eaeae80362923facd3041fcafe8859d07ba4c5
Author: Tom Clegg <tom at curoverse.com>
Date:   Tue Sep 20 21:27:32 2016 -0400

    9950: Load config from /etc/arvados/arv-git-httpd/config.json.

diff --git a/services/arv-git-httpd/auth_handler.go b/services/arv-git-httpd/auth_handler.go
index fccb0c9..6ba0f38 100644
--- a/services/arv-git-httpd/auth_handler.go
+++ b/services/arv-git-httpd/auth_handler.go
@@ -5,6 +5,7 @@ import (
 	"net/http"
 	"os"
 	"strings"
+	"sync"
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/arvadosclient"
@@ -12,13 +13,20 @@ import (
 	"git.curoverse.com/arvados.git/sdk/go/httpserver"
 )
 
-var clientPool = arvadosclient.MakeClientPool()
-
 type authHandler struct {
-	handler http.Handler
+	handler    http.Handler
+	clientPool *arvadosclient.ClientPool
+	setupOnce  sync.Once
+}
+
+func (h *authHandler) setup() {
+	os.Setenv("ARVADOS_API_HOST", theConfig.Client.APIHost)
+	h.clientPool = arvadosclient.MakeClientPool()
 }
 
 func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
+	h.setupOnce.Do(h.setup)
+
 	var statusCode int
 	var statusText string
 	var apiToken string
@@ -68,12 +76,12 @@ func (h *authHandler) ServeHTTP(wOrig http.ResponseWriter, r *http.Request) {
 	repoName = pathParts[0]
 	repoName = strings.TrimRight(repoName, "/")
 
-	arv := clientPool.Get()
+	arv := h.clientPool.Get()
 	if arv == nil {
-		statusCode, statusText = http.StatusInternalServerError, "connection pool failed: "+clientPool.Err().Error()
+		statusCode, statusText = http.StatusInternalServerError, "connection pool failed: "+h.clientPool.Err().Error()
 		return
 	}
-	defer clientPool.Put(arv)
+	defer h.clientPool.Put(arv)
 
 	// Ask API server whether the repository is readable using
 	// this token (by trying to read it!)
diff --git a/services/arv-git-httpd/git_handler.go b/services/arv-git-httpd/git_handler.go
index 0312b29..f4baa72 100644
--- a/services/arv-git-httpd/git_handler.go
+++ b/services/arv-git-httpd/git_handler.go
@@ -23,7 +23,7 @@ func newGitHandler() http.Handler {
 			Env: []string{
 				"GIT_PROJECT_ROOT=" + theConfig.Root,
 				"GIT_HTTP_EXPORT_ALL=",
-				"SERVER_ADDR=" + theConfig.Addr,
+				"SERVER_ADDR=" + theConfig.Listen,
 			},
 			InheritEnv: []string{
 				"PATH",
diff --git a/services/arv-git-httpd/git_handler_test.go b/services/arv-git-httpd/git_handler_test.go
index 35c2f48..d87162d 100644
--- a/services/arv-git-httpd/git_handler_test.go
+++ b/services/arv-git-httpd/git_handler_test.go
@@ -37,7 +37,7 @@ func (s *GitHandlerSuite) TestEnvVars(c *check.C) {
 	c.Check(body, check.Matches, `(?ms).*^GL_BYPASS_ACCESS_CHECKS=yesplease$.*`)
 	c.Check(body, check.Matches, `(?ms).*^REMOTE_HOST=::1$.*`)
 	c.Check(body, check.Matches, `(?ms).*^REMOTE_PORT=12345$.*`)
-	c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Addr)+`$.*`)
+	c.Check(body, check.Matches, `(?ms).*^SERVER_ADDR=`+regexp.QuoteMeta(theConfig.Listen)+`$.*`)
 }
 
 func (s *GitHandlerSuite) TestCGIErrorOnSplitHostPortError(c *check.C) {
diff --git a/services/arv-git-httpd/gitolite_test.go b/services/arv-git-httpd/gitolite_test.go
index 20bdae7..96d9d24 100644
--- a/services/arv-git-httpd/gitolite_test.go
+++ b/services/arv-git-httpd/gitolite_test.go
@@ -6,6 +6,7 @@ import (
 	"os/exec"
 	"strings"
 
+	"git.curoverse.com/arvados.git/sdk/go/arvados"
 	check "gopkg.in/check.v1"
 )
 
@@ -41,8 +42,11 @@ func (s *GitoliteSuite) SetUpTest(c *check.C) {
 	runGitolite("gitolite", "setup", "--admin", "root")
 
 	s.tmpRepoRoot = s.gitoliteHome + "/repositories"
-	s.Config = &config{
-		Addr:       ":0",
+	s.Config = &Config{
+		Client: arvados.Client{
+			APIHost: os.Getenv("ARVADOS_API_HOST"),
+		},
+		Listen:     ":0",
 		GitCommand: "/usr/share/gitolite3/gitolite-shell",
 		Root:       s.tmpRepoRoot,
 	}
@@ -62,6 +66,10 @@ func (s *GitoliteSuite) TearDownTest(c *check.C) {
 	// upgrade to Go 1.4.
 	os.Setenv("GITOLITE_HTTP_HOME", "")
 	os.Setenv("GL_BYPASS_ACCESS_CHECKS", "")
+	if s.gitoliteHome != "" {
+		err := os.RemoveAll(s.gitoliteHome)
+		c.Check(err, check.Equals, nil)
+	}
 	s.IntegrationSuite.TearDownTest(c)
 }
 
diff --git a/services/arv-git-httpd/integration_test.go b/services/arv-git-httpd/integration_test.go
index 61d83ff..a548d6d 100644
--- a/services/arv-git-httpd/integration_test.go
+++ b/services/arv-git-httpd/integration_test.go
@@ -8,6 +8,7 @@ import (
 	"strings"
 	"testing"
 
+	"git.curoverse.com/arvados.git/sdk/go/arvados"
 	"git.curoverse.com/arvados.git/sdk/go/arvadostest"
 	check "gopkg.in/check.v1"
 )
@@ -23,7 +24,7 @@ type IntegrationSuite struct {
 	tmpRepoRoot string
 	tmpWorkdir  string
 	testServer  *server
-	Config      *config
+	Config      *Config
 }
 
 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
@@ -67,8 +68,11 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
 	c.Assert(err, check.Equals, nil)
 
 	if s.Config == nil {
-		s.Config = &config{
-			Addr:       ":0",
+		s.Config = &Config{
+			Client: arvados.Client{
+				APIHost: os.Getenv("ARVADOS_API_HOST"),
+			},
+			Listen:     ":0",
 			GitCommand: "/usr/bin/git",
 			Root:       s.tmpRepoRoot,
 		}
diff --git a/services/arv-git-httpd/main.go b/services/arv-git-httpd/main.go
index 98695c9..202e0a2 100644
--- a/services/arv-git-httpd/main.go
+++ b/services/arv-git-httpd/main.go
@@ -1,31 +1,67 @@
 package main
 
 import (
+	"encoding/json"
 	"flag"
 	"log"
 	"os"
+	"regexp"
+
+	"git.curoverse.com/arvados.git/sdk/go/arvados"
+	"git.curoverse.com/arvados.git/sdk/go/config"
 )
 
-type config struct {
-	Addr       string
+// Server configuration
+type Config struct {
+	Client     arvados.Client
+	Listen     string
 	GitCommand string
 	Root       string
 }
 
-var theConfig *config
+var theConfig = defaultConfig()
 
-func init() {
-	theConfig = &config{}
-	flag.StringVar(&theConfig.Addr, "address", "0.0.0.0:80",
-		"Address to listen on, \"host:port\".")
-	flag.StringVar(&theConfig.GitCommand, "git-command", "/usr/bin/git",
-		"Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\".")
+func defaultConfig() *Config {
 	cwd, err := os.Getwd()
 	if err != nil {
 		log.Fatalln("Getwd():", err)
 	}
-	flag.StringVar(&theConfig.Root, "repo-root", cwd,
-		"Path to git repositories.")
+	return &Config{
+		Listen:     ":80",
+		GitCommand: "/usr/bin/git",
+		Root:       cwd,
+	}
+}
+
+func init() {
+	const defaultCfgPath = "/etc/arvados/arv-git-httpd/config.json"
+	const deprecated = " (DEPRECATED -- use config file instead)"
+	flag.StringVar(&theConfig.Listen, "address", theConfig.Listen,
+		"Address to listen on, \"host:port\" or \":port\"."+deprecated)
+	flag.StringVar(&theConfig.GitCommand, "git-command", theConfig.GitCommand,
+		"Path to git or gitolite-shell executable. Each authenticated request will execute this program with a single argument, \"http-backend\"."+deprecated)
+	flag.StringVar(&theConfig.Root, "repo-root", theConfig.Root,
+		"Path to git repositories."+deprecated)
+
+	cfgPath := flag.String("config", defaultCfgPath, "Configuration file `path`.")
+	flag.Usage = usage
+	flag.Parse()
+
+	err := config.LoadFile(theConfig, *cfgPath)
+	if err != nil {
+		h := os.Getenv("ARVADOS_API_HOST")
+		if h == "" || !os.IsNotExist(err) || *cfgPath != defaultCfgPath {
+			log.Fatal(err)
+		}
+		log.Print("DEPRECATED: No config file found, but ARVADOS_API_HOST environment variable is set. Please use a config file instead.")
+		theConfig.Client.APIHost = h
+		if regexp.MustCompile("^(?i:1|yes|true)$").MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE")) {
+			theConfig.Client.Insecure = true
+		}
+		if j, err := json.MarshalIndent(theConfig, "", "    "); err == nil {
+			log.Print("Current configuration:\n", string(j))
+		}
+	}
 
 	// MakeArvadosClient returns an error if token is unset (even
 	// though we don't need to do anything requiring
@@ -37,7 +73,6 @@ func init() {
 }
 
 func main() {
-	flag.Parse()
 	srv := &server{}
 	if err := srv.Start(); err != nil {
 		log.Fatal(err)
diff --git a/services/arv-git-httpd/server.go b/services/arv-git-httpd/server.go
index 40e77a8..e2311d2 100644
--- a/services/arv-git-httpd/server.go
+++ b/services/arv-git-httpd/server.go
@@ -12,8 +12,8 @@ type server struct {
 
 func (srv *server) Start() error {
 	mux := http.NewServeMux()
-	mux.Handle("/", &authHandler{newGitHandler()})
+	mux.Handle("/", &authHandler{handler: newGitHandler()})
 	srv.Handler = mux
-	srv.Addr = theConfig.Addr
+	srv.Addr = theConfig.Listen
 	return srv.Server.Start()
 }
diff --git a/services/arv-git-httpd/usage.go b/services/arv-git-httpd/usage.go
new file mode 100644
index 0000000..649fb10
--- /dev/null
+++ b/services/arv-git-httpd/usage.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+	"encoding/json"
+	"flag"
+	"fmt"
+	"os"
+)
+
+func usage() {
+	c := defaultConfig()
+	c.Client.APIHost = "zzzzz.arvadosapi.com:443"
+	exampleConfigFile, err := json.MarshalIndent(c, "    ", "  ")
+	if err != nil {
+		panic(err)
+	}
+	fmt.Fprintf(os.Stderr, `
+
+arv-git-httpd provides authenticated access to Arvados-hosted git repositories.
+
+See http://doc.arvados.org/install/install-arv-git-httpd.html.
+
+Usage: arv-git-httpd [-config path/to/config.json]
+
+Options:
+`)
+	flag.PrintDefaults()
+	fmt.Fprintf(os.Stderr, `
+Example config file:
+    %s
+
+Client.APIHost:
+
+    Address (or address:port) of the Arvados API endpoint.
+
+Client.AuthToken:
+
+    Unused. Normally empty, or omitted entirely.
+
+Client.Insecure:
+
+    True if your Arvados API endpoint uses an unverifiable SSL/TLS
+    certificate.
+
+Listen:
+
+    Local port to listen on. Can be "address:port" or ":port", where
+    "address" is a host IP address or name and "port" is a port number
+    or name.
+
+GitCommand:
+
+    Path to git or gitolite-shell executable. Each authenticated
+    request will execute this program with the single argument
+    "http-backend".
+
+Root:
+
+    Path to git repositories. Defaults to current working directory.
+
+`, exampleConfigFile)
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list