Since Sourcegraph 3.13, deploying via Docker Compose is the recommended method for production deployments as it provides resource isolation between Sourcegraph services which makes it more scalable and stable. This page describes how to migrate from a single Docker image deployment to the Docker Compose deployment method.
Sourcegraph's core data (including user accounts, configuration, repository-metadata, etc.), can be migrated from the single Docker image (sourcegraph/server
) to the Docker Compose deployment by dumping and restoring the Postgres database.
sourcegraph/server:3.17.3
you must follow this guide using the Docker Compose deployment version v3.13.1
.After migration, Sourcegraph's data will be stored in Docker volumes instead of ~/.sourcegraph/
. For more information, see the cloud-provider documentation referred to in "Create the new Docker Compose instance".
The migration will bring over core data including user accounts, configuration, repository-metadata, etc. Other data will be regenerated automatically:
The above may take awhile if you have a lot of repositories. In the meantime, searches may be slow or return incomplete results. Usually this process will not take longer than 6 hours.
If you are on a monthly-based usage pricing model, please check first with your Sourcegraph point of contact before continuing with these migration steps.
CONTAINER_ID
ssh
from your local machine into the instance hosting the sourcegraph/server
containersourcegraph/server
's CONTAINER_ID
:> docker ps CONTAINER ID IMAGE ... sourcegraph/server
/tmp/db.out
# Use the CONTAINER_ID found in the previous step docker exec -it "$CONTAINER_ID" sh -c 'pg_dumpall --verbose --username=postgres' > /tmp/db.out
sourcegraph/server
container to the host machinedocker cp "$CONTAINER_ID":/tmp/db.out /tmp/db.out
End your ssh
session with the sourcegraph/server
host machine
Copy the Postgres dump from the sourcegraph/server
host to your local machine:
# Modify this command with your authentication information scp example_user@example_docker_host.com:/tmp/db.out db.out
less "/tmp/db.out"
and verify that the database dump has contents that you expect (e.g. that some of your repository names appear)Follow your cloud provider's installation guide to create the new Docker Compose instance:
Once you have finished the above, come back here for directions on how to copy over the database from your old sourcegraph/server
instance.
ssh
from your local machine into the new instance running the Docker Compose deployment
Navigate to the directory containing the Docker Compose definition:
# Refer to the script in your cloud provider's installation guide # to find the value for "DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT" cd "$DEPLOY_SOURCEGRAPH_DOCKER_CHECKOUT"/docker-compose
docker-compose down --volumes
docker-compose -f pgsql-only-migrate.docker-compose.yaml up -d
ssh
session with the new Docker Compose deployment host# Modify this command with your authentication information scp db.out example_user@example_docker_compose_host.com:/tmp/db.out
ssh
from your local machine into the Docker Compose deployment host
Copy database dump from the Docker Compose host to the Postgres container
docker cp /tmp/db.out pgsql:/tmp/db.out
docker exec -it pgsql /bin/sh
psql --username=sg -f /tmp/db.out postgres
psql --username=sg postgres
DROP DATABASE sg; ALTER DATABASE sourcegraph RENAME TO sg; ALTER DATABASE sg OWNER TO sg;
psql
session\q
exit
docker-compose -f docker-compose.yaml up -d
The migration process is now complete.
You should be able to log into your instance and verify that previous users and configuration are still present. Repositories may take awhile to clone and index, but their names should be immediately visible in the site admin repositories list. Wait for repositories to clone and verify the new Sourcegraph instance works as expected.
After verifying the new instance is functional, you can tear down the old sourcegraph/server
single Docker container Sourcegraph instance.