mirror of https://github.com/perkeep/perkeep.git
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:
parent
7332aad3aa
commit
d9fa1ed87e
|
@ -495,7 +495,6 @@ func setProdFlags() {
|
||||||
"camlistore/git",
|
"camlistore/git",
|
||||||
"git",
|
"git",
|
||||||
"clone",
|
"clone",
|
||||||
"--depth=1",
|
|
||||||
"https://camlistore.googlesource.com/camlistore",
|
"https://camlistore.googlesource.com/camlistore",
|
||||||
prodSrcDir).CombinedOutput()
|
prodSrcDir).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -180,7 +180,7 @@ func execGit(workdir string, mounts map[string]string, gitArgs ...string) *exec.
|
||||||
"--rm",
|
"--rm",
|
||||||
}
|
}
|
||||||
for host, container := range mounts {
|
for host, container := range mounts {
|
||||||
args = append(args, "-v", host+":"+container)
|
args = append(args, "-v", host+":"+container+":ro")
|
||||||
}
|
}
|
||||||
args = append(args, []string{
|
args = append(args, []string{
|
||||||
"-v", workdir + ":" + workdir,
|
"-v", workdir + ":" + workdir,
|
||||||
|
@ -203,13 +203,13 @@ type GitCommit struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pollCommits(dir string) {
|
func pollCommits(dir string) {
|
||||||
cmd := execGit(dir, nil, "fetch", "origin")
|
cmd := execGit(dir, nil, "pull", "origin")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Ran git fetch.")
|
log.Printf("Ran git pull.")
|
||||||
// TODO: see if .git/refs/remotes/origin/master
|
// TODO: see if .git/refs/remotes/origin/master
|
||||||
// changed. (quicker than running recentCommits each time)
|
// changed. (quicker than running recentCommits each time)
|
||||||
|
|
||||||
|
@ -248,9 +248,7 @@ func pollCommits(dir string) {
|
||||||
}
|
}
|
||||||
if githubSSHKey != "" {
|
if githubSSHKey != "" {
|
||||||
if err := syncToGithub(dir, hashes[0]); err != nil {
|
if err := syncToGithub(dir, hashes[0]); err != nil {
|
||||||
log.Printf("Failed to push to github: %v", err)
|
log.Printf("Failed to push commit %v to github: %v", hashes[0], err)
|
||||||
} else {
|
|
||||||
log.Printf("Successfully pushed commit %v to github", hashes[0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,18 +65,19 @@ func initGithubSyncing() error {
|
||||||
if err := os.MkdirAll(sshDir, 0700); err != nil {
|
if err := os.MkdirAll(sshDir, 0700); err != nil {
|
||||||
return fmt.Errorf("failed to create ssh config dir %v: %v", sshDir, err)
|
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 {
|
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(
|
if err := ioutil.WriteFile(
|
||||||
filepath.Join(sshDir, "config"),
|
filepath.Join(sshDir, "config"),
|
||||||
[]byte(githubSSHConfig(keyFile)),
|
[]byte(githubSSHConfig(keyFileName)),
|
||||||
0600); err != nil {
|
0600); err != nil {
|
||||||
return fmt.Errorf("failed to create github SSH config: %v", err)
|
return fmt.Errorf("failed to create github SSH config: %v", err)
|
||||||
}
|
}
|
||||||
hostSSHDir = sshDir
|
hostSSHDir = sshDir
|
||||||
githubSSHKey = filepath.Base(keyFile)
|
githubSSHKey = keyFileName
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,16 +116,18 @@ func syncToGithub(dir, gerritHEAD string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error looking up the github HEAD commit: %v", err)
|
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 {
|
if gh == gerritHEAD {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
mounts := map[string]string{
|
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")
|
cmd := execGit(dir, mounts, "push", "git@github.com:camlistore/camlistore.git", "master:master")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error running git push to github: %v\n%s", err, out)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue