From d9fa1ed87e44f1dbedaae4c62a84f839d99779a9 Mon Sep 17 00:00:00 2001 From: mpl Date: Mon, 25 Apr 2016 17:29:03 -0700 Subject: [PATCH] website: do a full cloning of camlistore.org on startup We used to have --depth=1 when cloning camlistore.org on startup, for efficiency reasons. But not having all the commits locally caused problems when pushing to github, because it would see the remote had commits that we didn't. So we're now doing a full cloning. It looks like it's now taking ~4s (as opposed to ~2.5s before), and consuming ~50MB diskspace (as opposed to 35MB before). Plus a few bugfixes. Change-Id: If7dbae1d3119d8b3336fb7d735f6bd0ba7606fc6 --- website/camweb.go | 1 - website/email.go | 12 +++++------- website/github.go | 13 ++++++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/website/camweb.go b/website/camweb.go index 3e325eb5d..60040cf78 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -495,7 +495,6 @@ func setProdFlags() { "camlistore/git", "git", "clone", - "--depth=1", "https://camlistore.googlesource.com/camlistore", prodSrcDir).CombinedOutput() if err != nil { diff --git a/website/email.go b/website/email.go index ef4409adf..b92a9f7ec 100644 --- a/website/email.go +++ b/website/email.go @@ -180,7 +180,7 @@ func execGit(workdir string, mounts map[string]string, gitArgs ...string) *exec. "--rm", } for host, container := range mounts { - args = append(args, "-v", host+":"+container) + args = append(args, "-v", host+":"+container+":ro") } args = append(args, []string{ "-v", workdir + ":" + workdir, @@ -203,13 +203,13 @@ type GitCommit struct { } func pollCommits(dir string) { - cmd := execGit(dir, nil, "fetch", "origin") + cmd := execGit(dir, nil, "pull", "origin") out, err := cmd.CombinedOutput() if err != nil { - log.Printf("Error running git fetch origin master in %s: %v\n%s", dir, err, out) + log.Printf("Error running git pull origin master in %s: %v\n%s", dir, err, out) return } - log.Printf("Ran git fetch.") + log.Printf("Ran git pull.") // TODO: see if .git/refs/remotes/origin/master // changed. (quicker than running recentCommits each time) @@ -248,9 +248,7 @@ func pollCommits(dir string) { } if githubSSHKey != "" { if err := syncToGithub(dir, hashes[0]); err != nil { - log.Printf("Failed to push to github: %v", err) - } else { - log.Printf("Successfully pushed commit %v to github", hashes[0]) + log.Printf("Failed to push commit %v to github: %v", hashes[0], err) } } } diff --git a/website/github.go b/website/github.go index 0ee6eb548..abb4e6b86 100644 --- a/website/github.go +++ b/website/github.go @@ -65,18 +65,19 @@ func initGithubSyncing() error { if err := os.MkdirAll(sshDir, 0700); err != nil { return fmt.Errorf("failed to create ssh config dir %v: %v", sshDir, err) } - keyFile := filepath.Join(sshDir, "id_github_camlistorebot_push") + keyFileName := filepath.Base(githubSSHKeyGCS) + keyFile := filepath.Join(sshDir, keyFileName) if err := ioutil.WriteFile(keyFile, keyData, 0600); err != nil { - return fmt.Errorf("failed to create temp github SSH key: %v", err) + return fmt.Errorf("failed to create temp github SSH key %v: %v", keyFile, err) } if err := ioutil.WriteFile( filepath.Join(sshDir, "config"), - []byte(githubSSHConfig(keyFile)), + []byte(githubSSHConfig(keyFileName)), 0600); err != nil { return fmt.Errorf("failed to create github SSH config: %v", err) } hostSSHDir = sshDir - githubSSHKey = filepath.Base(keyFile) + githubSSHKey = keyFileName return nil } @@ -115,16 +116,18 @@ func syncToGithub(dir, gerritHEAD string) error { if err != nil { return fmt.Errorf("error looking up the github HEAD commit: %v", err) } + log.Printf("HEAD commits: on github=%v, on gerrit=%v", gh, gerritHEAD) if gh == gerritHEAD { return nil } mounts := map[string]string{ - hostSSHDir: filepath.Join("/root", ".ssh"), + hostSSHDir: "/root/.ssh", } cmd := execGit(dir, mounts, "push", "git@github.com:camlistore/camlistore.git", "master:master") out, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("error running git push to github: %v\n%s", err, out) } + log.Printf("Successfully pushed commit %v to github", gerritHEAD) return nil }