Merge ~mthaddon/discourse-charm/+git/discourse-charm:system-packages into discourse-charm:master

Proposed by Tom Haddon
Status: Work in progress
Proposed branch: ~mthaddon/discourse-charm/+git/discourse-charm:system-packages
Merge into: discourse-charm:master
Diff against target: 100 lines (+28/-9)
4 files modified
layer.yaml (+2/-0)
reactive/discourse.py (+24/-7)
templates/sidekiq.service (+1/-1)
templates/unicorn.service (+1/-1)
Reviewer Review Type Date Requested Status
Discourse Charm Maintainers Pending
Review via email: mp+372550@code.launchpad.net

Commit message

Be explicit in layer.yaml that we're using venv, and include system packages, and update rake commands to use correct format.

Description of the change

Be explicit in layer.yaml that we're using venv, and include system packages, and update rake commands to use correct format.

To post a comment you must log in.
fabba07... by Tom Haddon

Update bundle commands to use correct format

3605d59... by Tom Haddon

Run any DB migrations after creation

751b26f... by Tom Haddon

Use os.environ before bundle commands as documented in ruby layer usage

29a84d9... by Tom Haddon

Update config files given snap location of bundle binary, install unicorn gem, ensure we get full output from bundle exec commands

Unmerged commits

29a84d9... by Tom Haddon

Update config files given snap location of bundle binary, install unicorn gem, ensure we get full output from bundle exec commands

751b26f... by Tom Haddon

Use os.environ before bundle commands as documented in ruby layer usage

3605d59... by Tom Haddon

Run any DB migrations after creation

fabba07... by Tom Haddon

Update bundle commands to use correct format

afcb549... by Tom Haddon

Be explicit in layer.yaml that we're using venv, and include system packages

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/layer.yaml b/layer.yaml
2index c3d5c9a..5e622b7 100644
3--- a/layer.yaml
4+++ b/layer.yaml
5@@ -7,6 +7,8 @@ includes:
6 - 'interface:nrpe-external-master'
7 options:
8 basic:
9+ use_venv: true
10+ include_system_packages: true
11 packages:
12 - imagemagick
13 - optipng
14diff --git a/reactive/discourse.py b/reactive/discourse.py
15index a7edb9f..0ad3894 100644
16--- a/reactive/discourse.py
17+++ b/reactive/discourse.py
18@@ -11,6 +11,7 @@ import pwd
19 import grp
20 import time
21 import subprocess
22+import sh
23
24
25 # Utility function to read the discourse.conf file, which is just key=value
26@@ -105,15 +106,14 @@ def install_discourse():
27 if hookenv.config('admin-users'):
28 config['developer_emails'] = hookenv.config('admin-users')
29 write_config(config)
30- # Bionic seems to require that you manually install rake globally before
31- # running bundle install, as far as I can tell this shouldn't hurt anything
32- # in the xenial version, it's just not necessary per se there.
33- rake_install_cmd = ['gem', 'install', 'rake']
34+ # Install required gems
35+ rake_install_cmd = ['gem', 'install', 'rake', 'concurrent-ruby', 'unicorn']
36 proxy = hookenv.config('http-proxy')
37 if proxy:
38 rake_install_cmd.extend(['-p', proxy])
39 subprocess.call(rake_install_cmd)
40 # Bundle command is from the ruby layer, it'll install our gem dependencies
41+ os.environ['RAILS_ENV'] = 'production'
42 bundle('install')
43 hookenv.status_set('blocked', 'Discourse installed, waiting on database.')
44 set_state('discourse.installed')
45@@ -138,9 +138,26 @@ def db_available(pgsql):
46 @when('discourse.database.created')
47 def prepare_codebase(pgsql):
48 # Create all the Discourse specific DB schema
49- bundle('exec rake db:migrate RAILS_ENV=production')
50- # Compile CSS/JS? I'm not sure what this does but it's necessary.
51- bundle('exec rake assets:precompile RAILS_ENV=production')
52+ os.environ['RAILS_ENV'] = 'production'
53+ try:
54+ for line in bundle('exec', 'rake', 'db:create', _bg_exc=False, _iter=True):
55+ print(line)
56+ except sh.ErrorReturnCode as error:
57+ print("Exception occured: \n{}".format(error))
58+ # Run any necessary migrations
59+ try:
60+ for line in bundle('exec', 'rake', 'db:migrate', _bg_exc=False, _iter=True):
61+ print(line)
62+ except sh.ErrorReturnCode as error:
63+ print("Exception occured: \n{}".format(error))
64+
65+ # Compile CSS/JS
66+ try:
67+ for line in bundle('exec', 'rake', 'assets:precompile', _bg_exc=False, _iter=True):
68+ print(line)
69+ except sh.ErrorReturnCode as error:
70+ print("Exception occured: \n{}".format(error))
71+
72 if hookenv.config('plugins'):
73 fetch_plugins()
74 # The ruby layer doesn't have a concept of ownership, so after the rakes
75diff --git a/templates/sidekiq.service b/templates/sidekiq.service
76index d46528e..2ea58ae 100644
77--- a/templates/sidekiq.service
78+++ b/templates/sidekiq.service
79@@ -28,7 +28,7 @@ WorkingDirectory=/srv/discourse/current/
80 # If you use rbenv:
81 # ExecStart=/bin/bash -lc 'bundle exec sidekiq -e production'
82 # If you use the system's ruby:
83-ExecStart=/usr/bin/bundle exec sidekiq -e production -q critical -q default -q low
84+ExecStart=/snap/bin/bundle exec sidekiq -e production -q critical -q default -q low
85 User=www-data
86 Group=www-data
87 UMask=0002
88diff --git a/templates/unicorn.service b/templates/unicorn.service
89index 2649472..dafa503 100644
90--- a/templates/unicorn.service
91+++ b/templates/unicorn.service
92@@ -13,7 +13,7 @@ Environment=RAILS_ENV=production
93 SyslogIdentifier=unicorn
94 PIDFile=/srv/discourse/current/tmp/pids/unicorn.pid
95
96-ExecStart=/usr/bin/bundle exec "unicorn -D -c /srv/discourse/current/config/unicorn.conf.rb -E production"
97+ExecStart=/snap/bin/bundle exec unicorn -D -c /srv/discourse/current/config/unicorn.conf.rb -E production
98
99 [Install]
100 WantedBy=multi-user.target

Subscribers

People subscribed via source and target branches