Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Created February 7, 2019 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-blunden/9cc31c5ee6fc239f580963288782dcc6 to your computer and use it in GitHub Desktop.
Save ryan-blunden/9cc31c5ee6fc239f580963288782dcc6 to your computer and use it in GitHub Desktop.
Testing Sourcegraph 3.0 db upgrade
#!/usr/bin/env bash
set -xeuo pipefail
export OLD=${OLD:-"9.6"}
export NEW=${NEW:-"11"}
export SRC_DIR=${SRC_DIR:-"$HOME/.sourcegraph"}
docker run \
-w /tmp/upgrade \
-v "$SRC_DIR/data/postgres-$NEW-upgrade:/tmp/upgrade" \
-v "$SRC_DIR/data/postgresql:/var/lib/postgresql/$OLD/data" \
-v "$SRC_DIR/data/postgresql-$NEW:/var/lib/postgresql/$NEW/data" \
"tianon/postgres-upgrade:$OLD-to-$NEW"
mv "$SRC_DIR/data/"{postgresql,postgresql-$OLD}
mv "$SRC_DIR/data/"{postgresql-$NEW,postgresql}
curl -fsSL -o "$SRC_DIR/data/postgres-$NEW-upgrade/optimize.sh" https://raw.githubusercontent.com/sourcegraph/sourcegraph/master/cmd/server/rootfs/postgres-optimize.sh
docker run \
--entrypoint "/bin/bash" \
-w /tmp/upgrade \
-v "$SRC_DIR/data/postgres-$NEW-upgrade:/tmp/upgrade" \
-v "$SRC_DIR/data/postgresql:/var/lib/postgresql/data" \
"postgres:$NEW" \
-c 'chown -R postgres $PGDATA . && gosu postgres bash ./optimize.sh $PGDATA'
#!/usr/bin/env bash
# Testing upgrade using Docker socket
echo -e "\n[info]: removing ~/.sourcegraph"
sudo rm -fr ~/.sourcegraph
echo -e "\n[info]: testing sourcegraph/server:${FROM}\n"
sudo docker run --publish 7080:7080 --publish 2633:2633 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:${FROM}
echo -e "\n[info]: testing sourcegraph/server:3${TO} without mounting docker socket\n"
sudo docker run --publish 7080:7080 --publish 2633:2633 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:${TO}
echo -e "\n[info]: testing sourcegraph/server:${TO} docker socket mounted\n"
sudo docker run --publish 7080:7080 --publish 2633:2633 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph -v /var/run/docker.sock:/var/run/docker.sock:ro sourcegraph/server:${TO}
echo -e "\n[info]: PostgreSQL upgrade successful\n"
#!/usr/bin/env bash
# Testing upgrade using script - https://docs.sourcegraph.com/admin/postgres#option-2-upgrading-with-a-script-that-uses-the-postgresql-upgrade-container-directly
echo -e "\n[info]: removing ~/.sourcegraph"
rm -fr ~/.sourcegraph
echo -e "\n[info]: testing sourcegraph/server:${FROM}\n"
docker run --publish 7080:7080 --publish 2633:2633 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:${FROM}
echo -e "\n[info]: testing sourcegraph/server:3${TO} without script\n"
docker run --publish 7080:7080 --publish 2633:2633 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:${TO}
echo -e "\n[info]: testing script\n"
./postgres-upgrade.sh
echo -e "\n[info]: PostgreSQL upgrade successful\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment