Skip to content

Commit fc919e2

Browse files
committed
Install PostgreSQL server in postgres recipe and connect locally
It's strange that we install a MySQL server in the mysql recipe but don't install a PostgreSQL server in the postgres recipe. This allows us to treat the server as local when creating the user and database, simplifying the recipe. The recipe no longer references the userhost attribute as this concept does not exist in PostgreSQL. Recent GitLab versions require the pg_trgm extension, which we now install via the postgresql::contrib recipe. This really should be a resource but we can force override node['postgresql']['database_name'] in the short term. We could install the extension to template1 instead but this will not help existing users.
1 parent 0a453c9 commit fc919e2

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

attributes/default.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
default['gitlab']['database']['database'] = 'gitlab'
5656
default['gitlab']['database']['username'] = 'gitlab'
5757
default['gitlab']['database']['userhost'] = '127.0.0.1'
58-
default['gitlab']['postgresql']['username'] = 'postgres'
5958
default['gitlab']['database']['password'] = nil
6059

6160
# Ruby setup
@@ -157,6 +156,9 @@
157156
default['mysql']['server_root_password'] = 'Ch4ngm3'
158157
default['build-essential']['compile_time'] = true # needed for mysql chef_gem
159158

159+
# PostgreSQL
160+
default['postgresql']['contrib']['extensions'] = ['pg_trgm']
161+
160162
# nginx
161163
default['nginx']['default_site_enabled'] = false
162164

recipes/postgres.rb

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
#
19+
20+
include_recipe 'postgresql::server'
1921
include_recipe 'database::postgresql'
2022

2123
# Enable secure password generation
@@ -31,38 +33,20 @@
3133
end
3234
end
3335

34-
# Helper variables
35-
database = node['gitlab']['database']['database']
36-
database_user = node['gitlab']['database']['username']
37-
database_override_user = node['postgresql']['username']
38-
database_password = node['gitlab']['database']['password']
39-
database_host = node['gitlab']['database']['host']
40-
database_userhost = node['gitlab']['database']['userhost']
41-
database_connection = {
42-
host: database_host,
43-
port: '5432',
44-
username: database_override_user,
45-
password: node['postgresql']['password']['postgres']
46-
}
47-
48-
# Create the database
49-
postgresql_database database do
50-
connection database_connection
36+
# Create the database user
37+
postgresql_database_user node['gitlab']['database']['username'] do
38+
connection :host => 'localhost'
39+
password node['gitlab']['database']['password']
5140
action :create
5241
end
5342

54-
# Create the database user
55-
postgresql_database_user database_user do
56-
connection database_connection
57-
password database_password
58-
host database_userhost
59-
database_name database
43+
# Create the database
44+
postgresql_database node['gitlab']['database']['database'] do
45+
connection :host => 'localhost'
46+
owner node['gitlab']['database']['username']
6047
action :create
6148
end
6249

63-
# Grant all privileges to user on database
64-
postgresql_database_user database_user do
65-
connection database_connection
66-
database_name database
67-
action :grant
68-
end
50+
# FIXME: Add extension resource to postgresql cookbook
51+
node.force_override['postgresql']['database_name'] = node['gitlab']['database']['database']
52+
include_recipe 'postgresql::contrib'

0 commit comments

Comments
 (0)