Skip to content

Commit

Permalink
Merge pull request #549 from alphagov/fix-router
Browse files Browse the repository at this point in the history
Update MongoDB to work for Router
  • Loading branch information
Karl Baker authored Dec 16, 2021
2 parents 84b4380 + f943256 commit f378e9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion bin/replicate-mongodb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ replication_dir="${GOVUK_DOCKER_REPLICATION_DIR:-${GOVUK_DOCKER_DIR:-${GOVUK_ROO

bucket="govuk-integration-database-backups"

mongo_version=3.6

case "$app" in
"authenticating-proxy")
hostname=router_backend
Expand All @@ -21,6 +23,8 @@ case "$app" in
"router"|"draft-router")
hostname=router_backend
database="${app//-/_}"
mongo_version=2.6
wait_for_rs=1
;;
"asset-manager")
hostname=mongo
Expand Down Expand Up @@ -67,12 +71,18 @@ pv "$archive_path" | gunzip | tar -zx -f - -C "$extract_path" "var/lib/mongodb/b
echo "stopping running govuk-docker containers..."
govuk-docker down

container=$(govuk-docker run -d --rm -v "${extract_path}:/replication" mongo-3.6 | tail -n1)
container=$(govuk-docker run -d --rm -v "${extract_path}:/replication" --name "mongo-${mongo_version}" mongo-${mongo_version} | tail -n1)
# we want $container to be expanded now
# shellcheck disable=SC2064
trap "docker stop '$container'" EXIT

echo "waiting for mongo..."

if [[ -n "${wait_for_rs:-}" ]]; then
echo "Sleeping for 60s to allow replica set initialisation..."
sleep 60
fi

until docker exec "$container" mongo --eval 1 &>/dev/null; do
sleep 1
done
Expand Down
11 changes: 10 additions & 1 deletion projects/router/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
router: clone-router
$(GOVUK_DOCKER) up -d mongo-2.6
$(GOVUK_DOCKER) exec mongo-2.6 mongo --eval "rs.initiate()"
$(GOVUK_DOCKER) exec mongo-2.6 mongo --eval 'rs.initiate({ \
"_id" : "mongo-replica-set", \
"version" : 1, \
"members" : [ \
{ \
"_id" : 0, \
"host" : "mongo-2.6:27017" \
} \
]\
}).ok || rs.status().ok'
$(GOVUK_DOCKER) run $@-lite make build

0 comments on commit f378e9c

Please sign in to comment.