Beyang Liu

The fastest way to spin up a shareable Sourcegraph · 2021.3.27

Here’s how you can do it in 2 minutes flat using ngrok:

  1. Run the Sourcegraph single Docker container:

      docker run --publish 7080:7080 \
      --publish 127.0.0.1:3370:3370 --rm \
      --volume ~/.sourcegraph/config:/etc/sourcegraph \
      --volume ~/.sourcegraph/data:/var/opt/sourcegraph \
      sourcegraph/server:3.25.2
    
  2. Go to http://localhost:7080 and create an admin login.

  3. Download and run ngrok:

    ngrok http -bind-tls=true 7080
    
  4. Navigate to the public URL displayed by ngrok (looks something like this: “https://6481df2bd6ad.ngrok.io”).

Boom—you’re done! You now have a publicly shareable URL to your own private Sourcegraph.

Security disclaimer: As of this post’s publication date, ngrok uses HTTPS with ngrok.com certificates and does not record the data transmitted through its tunnels. Before adding any of your company’s private code to the instance, you should verify doing so does not violate company security policies.

Immediate next steps

  1. By default, ngrok imposes limits on the number of simultaneous connections for anti-spam reasons. You will likely hit this limit early in your use of Sourcegraph, as many pages open multiple HTTP connections. To raise it, you can create a free ngrok.com account and use the account’s authtoken:

    ngrok authtoken $TOKEN
    
  2. Update the Sourcegraph config so it is aware of its external ngrok URL.

  3. Add your repositories to Sourcegraph.

  4. Use it for yourself and then share with your teammates!

    The best moment to share is often when you’re asking or answering a code-related question. Instead of linking to your code host (limited code search, context, and navigation) or typing an awkward written description of where the code is (“it’s in http.go, not in that directory, but in this other one, line 45, oh wait, you’re on a different branch…"), just link to the code in Sourcegraph—chances are you’re already looking at it there anyway.

Note: This spins ups a minimally viable shareable instance of Sourcegraph. As more people use it, you may wish to move your Sourcegraph instance off your local machine. The Sourcegraph docs offer instructions for deploying to any infrastructure using Docker or Kubernetes (high scalability). Or, if you’re looking for a more opinionated guide to productionizing Sourcegraph, here’s an excellent one from one of our many community users.