This issue captures the work (which spans multiple releases) to improve Sourcegraph's integration with Gerrit.
Customers using Gerrit (not exhaustive):
In case anyone lands here like me after Googling for "Sourcegraph Gerrit", here is what I wound up doing to make it work.
First of all, do not try to mount Gerrit's bare repos into Sourcegraph's container, that won't work as Sourcegraph expects a different layout on the filesystem and will actively move things around in a way that breaks Gerrit (and since it runs as root, it can).
First create an SSH key pair for Sourcegraph to access Gerrit (note: I personally use /etc/sourcegraph instead of ~/.sourcegraph because I don't want the daemon's config to be in my home directory, not sure why that's the default recommendation in the docs, but I'll just stick with that here even though that's against best practices):
mkdir ~/.sourcegraph/config/ssh
chmod 700 ~/.sourcegraph/config/ssh
ssh-keygen -f ~/.sourcegraph/config/ssh/id_rsa
<hit enter for no password>
Then create an account on Gerrit for Sourcegraph (using the public key from ~/.sourcegraph/config/ssh/id_rsa.pub):
ssh -p <gerrit-port> gerrit.example.com "gerrit create-account --email [email protected] --full-name Sourcegraph --ssh-key 'ssh-rsa <public-key-here> sourcegraph@localhost' sourcegraph"
ssh -p <gerrit-port> gerrit.example.com "gerrit set-members -a sourcegraph 'Non-Interactive Users'"
Check that the account has been created properly:
ssh -i ~/.sourcegraph/config/ssh/id_rsa -o UserKnownHostsFile=$HOME/.sourcegraph/config/ssh/known_hosts -p <gerrit-port> [email protected]
This should print a **** Welcome to Gerrit Code Review **** banner if things worked properly. Also as a side-effect of running that command, the known_hosts file be created and seeded properly.
Then need to create a bit of SSH config in order for Sourcegraph to use the correct user when SSH'ing into Gerrit (otherwise it'll attempt to log in as root):
cat >~/.sourcegraph/config/ssh/config <<EOF
Host gerrit.example.com
User sourcegraph
EOF
chmod 600 ~/.sourcegraph/config/ssh/config
After having done this, you can docker run the Sourcegraph container and then in the site-admin external services, configure an external repo of kind "other" with this config:
{
"url": "ssh://gerrit.example.com:<gerrit-port>",
"repos": ["myrepo"]
}
@tsuna Thanks for the comment. This basically connects the bare-git repository to sourcegraph. And this only works for branches which have been checked in - not the CLs on gerrit.
Wanted to know if you have also figured out a way to extract information from gerrit's refs/for/
Nope, it's not something that I am interested in, so I didn't try to figure out how to make this work, sorry.
Most helpful comment
In case anyone lands here like me after Googling for "Sourcegraph Gerrit", here is what I wound up doing to make it work.
First of all, do not try to mount Gerrit's bare repos into Sourcegraph's container, that won't work as Sourcegraph expects a different layout on the filesystem and will actively move things around in a way that breaks Gerrit (and since it runs as root, it can).
First create an SSH key pair for Sourcegraph to access Gerrit (note: I personally use
/etc/sourcegraphinstead of~/.sourcegraphbecause I don't want the daemon's config to be in my home directory, not sure why that's the default recommendation in the docs, but I'll just stick with that here even though that's against best practices):Then create an account on Gerrit for Sourcegraph (using the public key from
~/.sourcegraph/config/ssh/id_rsa.pub):Check that the account has been created properly:
This should print a
**** Welcome to Gerrit Code Review ****banner if things worked properly. Also as a side-effect of running that command, theknown_hostsfile be created and seeded properly.Then need to create a bit of SSH config in order for Sourcegraph to use the correct user when SSH'ing into Gerrit (otherwise it'll attempt to log in as
root):After having done this, you can
docker runthe Sourcegraph container and then in the site-admin external services, configure an external repo of kind "other" with this config: