From aaf47c7b4ff21d4ba8e6c4e1d961590a23403df4 Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 14:51:36 -0800 Subject: [PATCH 1/8] Add support for running GitLab Geo tracking database See https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1197 --- Makefile | 16 +++++++++++++++- Procfile.example | 1 + database_geo.yml.example | 13 +++++++++++++ run | 7 +++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 database_geo.yml.example diff --git a/Makefile b/Makefile index b94c7eb..f96b13b 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,14 @@ postgres_bin_dir = $(shell pg_config --bindir) postgres_replication_user = gitlab_replication postgres_dir = $(realpath ./postgresql) postgres_replica_dir = $(realpath ./postgresql-replica) +postgres_geo_dir = $(realpath ./postgresql-geo) port = $(shell cat port 2>/dev/null) username = $(shell whoami) sshd_bin = $(shell which sshd) git_bin = $(shell which git) webpack_port = $(shell cat webpack_port 2>/dev/null || echo '3808') -all: gitlab-setup gitlab-shell-setup gitlab-workhorse-setup support-setup gitaly-setup +all: gitlab-setup gitlab-shell-setup gitlab-workhorse-setup support-setup gitaly-setup geo-setup # Set up the GitLab Rails app @@ -187,6 +188,19 @@ postgresql-replication/backup: postgresql-replication/config: ./support/postgres-replication ${postgres_dir} +# Setup GitLab Geo databases + +.PHONY: geo-setup +geo-setup: gitlab/config/database_geo.yml postgresql/geo postgresql-replication/cluster postgresql-replication/role postgresql-replication/backup + +gitlab/config/database_geo.yml: + sed "s|/home/git|${gitlab_development_root}|" database_geo.yml.example > gitlab/config/database_geo.yml + +postgresql/geo: + ${postgres_bin_dir}/initdb --locale=C -E utf-8 postgresql-geo/data + grep '^postgresql-geo:' Procfile || (printf ',s/^#postgresql-geo/postgresql/\nwq\n' | ed -s Procfile) + support/bootstrap-geo + .PHONY: foreman foreman: command -v $@ > /dev/null || gem install $@ diff --git a/Procfile.example b/Procfile.example index 33f02f6..76bb1a1 100644 --- a/Procfile.example +++ b/Procfile.example @@ -5,6 +5,7 @@ redis: exec redis-server /home/git/redis/redis.conf postgresql: exec support/postgresql-signal-wrapper postgres -D /home/git/postgresql/data -k /home/git/postgresql -h '' #postgresql-replica: exec support/postgresql-signal-wrapper postgres -D /home/git/postgresql-replica/data -k /home/git/postgresql-replica -h '' +#postgresql-geo: exec support/postgresql-signal-wrapper postgres -D /home/git/postgresql-geo/data -k /home/git/postgresql-geo -h '' #openldap: exec support/exec-cd gitlab-openldap libexec/slapd -F slapd.d -d2 -h "ldap://$host:3890" gitlab-workhorse: exec /usr/bin/env PATH="/home/git/gitlab-workhorse/bin:$PATH" gitlab-workhorse -authSocket /home/git/gitlab.socket -listenAddr $host:$port -documentRoot /home/git/gitlab/public -developmentMode -secretPath /home/git/gitlab/.gitlab_workhorse_secret -config /home/git/gitlab-workhorse/config.toml rails-web: exec /usr/bin/env RAILS_ENV=development support/exec-cd gitlab bin/web start_foreground diff --git a/database_geo.yml.example b/database_geo.yml.example new file mode 100644 index 0000000..43551c2 --- /dev/null +++ b/database_geo.yml.example @@ -0,0 +1,13 @@ +development: + adapter: postgresql + encoding: unicode + database: gitlabhq_geo_development + pool: 5 + host: /home/git/postgresql + +test: &test + adapter: postgresql + encoding: unicode + database: gitlabhq_geo_test + pool: 5 + host: /home/git/postgresql diff --git a/run b/run index 95b1f99..cce396b 100755 --- a/run +++ b/run @@ -53,6 +53,10 @@ db() { foreman_start -c all=0,redis=1,postgresql=1,openldap=1,influxdb=1,webpack=1 } +geo_db() { + foreman_start -c all=0,postgresql-geo=1 +} + app() { print_port foreman_start -c all=0,rails-web=1,rails-background-jobs=1,gitlab-workhorse=1,nginx=1,grafana=1,sshd=1,gitaly=1 @@ -75,6 +79,9 @@ case "x$1" in xdb) db ;; +xgeo_db) + geo_db + ;; xapp) app ;; -- GitLab From 9d620ffd0746b3dd07ea8683ce978dccd8b328e1 Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 15:26:49 -0800 Subject: [PATCH 2/8] Add missing bootstrap-geo script --- support/bootstrap-geo | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 support/bootstrap-geo diff --git a/support/bootstrap-geo b/support/bootstrap-geo new file mode 100755 index 0000000..82128a0 --- /dev/null +++ b/support/bootstrap-geo @@ -0,0 +1,19 @@ +#!/usr/bin/env ruby + +success = true +begin + foreman_pid = spawn('./run', 'geo_db') + [ + %W(bundle exec rake geo:db:create) + ].each do |cmd| + success &&= system({'force' => 'yes', 'BOOTSTRAP' => '1'}, *cmd, chdir: 'gitlab') + end +ensure + Process.kill('TERM', foreman_pid) +end + +Process.wait(foreman_pid) + +exit true if success + +abort "#$0 failed" -- GitLab From 88ad250c96359f11bce5c2fbf26e3beda3197010 Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 15:29:10 -0800 Subject: [PATCH 3/8] Fix paths for GitLab Geo DB example file --- database_geo.yml.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database_geo.yml.example b/database_geo.yml.example index 43551c2..9cb28f4 100644 --- a/database_geo.yml.example +++ b/database_geo.yml.example @@ -3,11 +3,11 @@ development: encoding: unicode database: gitlabhq_geo_development pool: 5 - host: /home/git/postgresql + host: /home/git/postgresql-geo test: &test adapter: postgresql encoding: unicode database: gitlabhq_geo_test pool: 5 - host: /home/git/postgresql + host: /home/git/postgresql-geo -- GitLab From d654416285631d4f3f93d46a7cf1efc845afc900 Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 15:30:50 -0800 Subject: [PATCH 4/8] Use geo:db:setup instead of geo:db:create --- support/bootstrap-geo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/bootstrap-geo b/support/bootstrap-geo index 82128a0..98163d8 100755 --- a/support/bootstrap-geo +++ b/support/bootstrap-geo @@ -4,7 +4,7 @@ success = true begin foreman_pid = spawn('./run', 'geo_db') [ - %W(bundle exec rake geo:db:create) + %W(bundle exec rake geo:db:setup) ].each do |cmd| success &&= system({'force' => 'yes', 'BOOTSTRAP' => '1'}, *cmd, chdir: 'gitlab') end -- GitLab From b0feff0f2a408cfdba531a8bedff374636ee3693 Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 20:43:52 -0800 Subject: [PATCH 5/8] Fix typo in Procfile fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f96b13b..accfe3e 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,7 @@ gitlab/config/database_geo.yml: postgresql/geo: ${postgres_bin_dir}/initdb --locale=C -E utf-8 postgresql-geo/data - grep '^postgresql-geo:' Procfile || (printf ',s/^#postgresql-geo/postgresql/\nwq\n' | ed -s Procfile) + grep '^postgresql-geo:' Procfile || (printf ',s/^#postgresql-geo/postgresql-geo/\nwq\n' | ed -s Procfile) support/bootstrap-geo .PHONY: foreman -- GitLab From cc3c55df0ccda1e32acf23474e61fe9032edfaac Mon Sep 17 00:00:00 2001 From: Stan Hu <stanhu@gmail.com> Date: Mon, 20 Feb 2017 20:45:26 -0800 Subject: [PATCH 6/8] Don't attempt to run other PostgreSQL tasks in geo-setup task --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index accfe3e..4cddd30 100644 --- a/Makefile +++ b/Makefile @@ -191,7 +191,7 @@ postgresql-replication/config: # Setup GitLab Geo databases .PHONY: geo-setup -geo-setup: gitlab/config/database_geo.yml postgresql/geo postgresql-replication/cluster postgresql-replication/role postgresql-replication/backup +geo-setup: gitlab/config/database_geo.yml postgresql/geo gitlab/config/database_geo.yml: sed "s|/home/git|${gitlab_development_root}|" database_geo.yml.example > gitlab/config/database_geo.yml -- GitLab From f244a8d31974c3a08552a37c5d636a3269d25860 Mon Sep 17 00:00:00 2001 From: Robert Speicher <rspeicher@gmail.com> Date: Tue, 11 Apr 2017 15:24:19 -0400 Subject: [PATCH 7/8] Ignore `postgresql-geo` folder created by `geo-setup` target --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6885722..dd7acba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ /Procfile /postgresql/data /postgresql/.s.* +/postgresql-geo/ /postgresql-primary/ /postgresql-replica/data /postgresql-replica/.s.* -- GitLab From 3b339c4b08c827eee3a60b75bfd2a9e04415287d Mon Sep 17 00:00:00 2001 From: Robert Speicher <rspeicher@gmail.com> Date: Tue, 11 Apr 2017 15:24:48 -0400 Subject: [PATCH 8/8] The geo-setup target is now an optional/manual step --- Makefile | 2 +- doc/set-up-gdk.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4cddd30..b663de0 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ sshd_bin = $(shell which sshd) git_bin = $(shell which git) webpack_port = $(shell cat webpack_port 2>/dev/null || echo '3808') -all: gitlab-setup gitlab-shell-setup gitlab-workhorse-setup support-setup gitaly-setup geo-setup +all: gitlab-setup gitlab-shell-setup gitlab-workhorse-setup support-setup gitaly-setup # Set up the GitLab Rails app diff --git a/doc/set-up-gdk.md b/doc/set-up-gdk.md index 4f191a8..9a27725 100644 --- a/doc/set-up-gdk.md +++ b/doc/set-up-gdk.md @@ -86,6 +86,7 @@ cd gdk-geo echo 3002 > port echo 3807 > webpack_port gdk install gitlab_repo=https://gitlab.com/gitlab-org/gitlab-ee.git +make geo-setup ``` Now that you've installed a primary and a secondary GDK instance, follow the -- GitLab