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
This commit is contained in:
mpl 2016-04-25 17:29:03 -07:00
parent 7332aad3aa
commit d9fa1ed87e
3 changed files with 13 additions and 13 deletions

View File

@ -495,7 +495,6 @@ func setProdFlags() {
"camlistore/git",
"git",
"clone",
"--depth=1",
"https://camlistore.googlesource.com/camlistore",
prodSrcDir).CombinedOutput()
if err != nil {

View File

@ -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)
}
}
}

View File

@ -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
}