Merge lp:~wgrant/charms/trusty/turnip/single-dir into lp:~canonical-launchpad-branches/charms/trusty/turnip/devel

Proposed by William Grant on 2015-03-05
Status: Merged
Merged at revision: 34
Proposed branch: lp:~wgrant/charms/trusty/turnip/single-dir
Merge into: lp:~canonical-launchpad-branches/charms/trusty/turnip/devel
Diff against target: 223 lines (+47/-58)
8 files modified
Makefile (+0/-2)
config.yaml (+1/-13)
hooks/actions.py (+33/-32)
hooks/services.py (+3/-1)
templates/envs/REPO_STORE.j2 (+1/-1)
templates/envs/TURNIP_LOG_DIR.j2 (+1/-1)
templates/turnip-api.conf.j2 (+5/-5)
templates/turnip.conf.j2 (+3/-3)
To merge this branch: bzr merge lp:~wgrant/charms/trusty/turnip/single-dir
Reviewer Review Type Date Requested Status
Kit Randel 2015-03-05 Approve on 2015-03-05
Review via email: mp+251873@code.launchpad.net

Description of the Change

Move the /srv/* directories down into a configurable base_dir, defaulting to /srv/turnip.

To post a comment you must log in.
Kit Randel (blr) wrote :

Much tidier, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-02-27 18:13:29 +0000
3+++ Makefile 2015-03-05 06:48:41 +0000
4@@ -43,7 +43,6 @@
5
6 pip-cache: fetch-code
7 @echo "Updating python dependency cache..."
8- @sudo apt-get install -qq -y python-pip
9 @mkdir -p $(PIP_CACHE)
10 @pip install --no-use-wheel --download $(PIP_CACHE) -r $(SOURCE_DIR)/requirements.txt
11
12@@ -69,7 +68,6 @@
13
14
15 setup: clean
16- @sudo apt-get install -qq -y python-virtualenv
17 ifeq ($(wildcard .venv),)
18 @echo "Creating virtualenv in .venv"
19 @virtualenv .venv --python=/usr/bin/python3
20
21=== modified file 'config.yaml'
22--- config.yaml 2015-03-02 14:21:35 +0000
23+++ config.yaml 2015-03-05 06:48:41 +0000
24@@ -41,19 +41,7 @@
25 type: string
26 default: '1'
27 description: Current bzr revision.
28- data_dir:
29- type: string
30- default: '/srv/data'
31- description: Repository data directory; block storage mount on staging/production.
32- env_dir:
33- type: string
34- default: '/srv/envs'
35- description: Envar exports.
36- log_dir:
37- type: string
38- default: '/srv/logs'
39- description: Log directory.
40- srv_dir:
41+ base_dir:
42 type: string
43 default: '/srv/turnip'
44 description: Root checkout/srv directory.
45
46=== modified file 'hooks/actions.py'
47--- hooks/actions.py 2015-03-02 14:21:35 +0000
48+++ hooks/actions.py 2015-03-05 06:48:41 +0000
49@@ -15,8 +15,12 @@
50 # Globals
51 CHARM_FILES_DIR = os.path.join(hookenv.charm_dir(), 'files')
52 REQUIRED_PACKAGES = ['python-virtualenv', 'python-dev', 'python-pygit2']
53-APP = config['app_name']
54-SRV_DIR = config['srv_dir']
55+BASE_DIR = config['base_dir']
56+CODE_DIR = os.path.join(BASE_DIR, 'code')
57+VENV_DIR = os.path.join(BASE_DIR, 'venv')
58+LOGS_DIR = os.path.join(BASE_DIR, 'logs')
59+DATA_DIR = os.path.join(BASE_DIR, 'data')
60+
61 CODE_USER = config['code_user']
62 CODE_GROUP = config['code_group']
63 USER = config['user']
64@@ -31,14 +35,10 @@
65 def make_srv_location():
66 hookenv.log('Creating directories...')
67
68- data_dir = config['data_dir']
69- log_dir = config['log_dir']
70- deploymgr_dir = os.path.join(os.sep, 'srv', 'deploymgr')
71-
72- for dir in (deploymgr_dir, SRV_DIR):
73- host.mkdir(dir, owner=CODE_USER, group=CODE_GROUP, perms=0o775)
74- for dir in (data_dir, log_dir):
75- host.mkdir(dir, owner=USER, group=GROUP, perms=0o775)
76+ for dir in (BASE_DIR, CODE_DIR):
77+ host.mkdir(dir, owner=CODE_USER, group=CODE_GROUP, perms=0o755)
78+ for dir in (LOGS_DIR, DATA_DIR):
79+ host.mkdir(dir, owner=USER, group=GROUP, perms=0o755)
80
81
82 def create_users(service_name):
83@@ -57,17 +57,17 @@
84 make_srv_location()
85
86 # Copy source archive
87- archive_path = os.path.join(SRV_DIR, '%s.tar.gz' % APP)
88+ archive_path = os.path.join(BASE_DIR, 'turnip.tar.gz')
89
90- with open(os.path.join(CHARM_FILES_DIR, '%s.tar.gz' % APP)) as file:
91+ with open(os.path.join(CHARM_FILES_DIR, 'turnip.tar.gz')) as file:
92 host.write_file(archive_path, file.read(), perms=0o644)
93
94 # Unpack source
95- archive.extract_tarfile(archive_path, os.path.join(SRV_DIR))
96+ archive.extract_tarfile(archive_path, os.path.join(CODE_DIR))
97 os.chown(
98- SRV_DIR,
99+ CODE_DIR,
100 pwd.getpwnam(CODE_USER).pw_uid, grp.getgrnam(CODE_GROUP).gr_gid)
101- host.lchownr(SRV_DIR, CODE_USER, CODE_GROUP)
102+ host.lchownr(CODE_DIR, CODE_USER, CODE_GROUP)
103
104
105 def install_packages(service_name):
106@@ -78,21 +78,22 @@
107
108 def install_python_packages(service_name):
109 hookenv.log('Installing python packages...')
110- env_dir = os.path.join(SRV_DIR, 'env')
111 pip_cache = os.path.join(CHARM_FILES_DIR, 'pip-cache')
112- requirements = os.path.join(SRV_DIR, 'requirements.txt')
113-
114- subprocess.call(['virtualenv', '--system-site-packages', env_dir])
115- for dirpath, dirname, files in os.walk(pip_cache):
116- if files:
117- hookenv.log('Installing from download cache.')
118- subprocess.call(['%s/bin/pip' % env_dir,
119- 'install',
120- '--no-index',
121- '--find-links={}'.format(pip_cache),
122- '-r', requirements])
123- else:
124- subprocess.call(['%s/bin/pip' % env_dir,
125- 'install', '-r', requirements])
126- subprocess.call(['%s/bin/pip' % env_dir,
127- 'install', '--no-deps', '-e', SRV_DIR])
128+ requirements = os.path.join(CODE_DIR, 'requirements.txt')
129+
130+ pip_bin = os.path.join(VENV_DIR, 'bin', 'pip')
131+
132+ subprocess.call([
133+ 'sudo', '-u', CODE_USER, 'virtualenv', '--system-site-packages',
134+ VENV_DIR])
135+ if os.listdir(pip_cache):
136+ hookenv.log('Installing from download cache.')
137+ subprocess.call([
138+ 'sudo', '-u', CODE_USER, pip_bin, 'install', '--no-index',
139+ '--find-links={}'.format(pip_cache), '-r', requirements])
140+ else:
141+ subprocess.call([
142+ 'sudo', '-u', CODE_USER, pip_bin, 'install', '-r', requirements])
143+ subprocess.call([
144+ 'sudo', '-u', CODE_USER, pip_bin, 'install', '--no-deps',
145+ '-e', CODE_DIR])
146
147=== modified file 'hooks/services.py'
148--- hooks/services.py 2015-03-02 14:21:35 +0000
149+++ hooks/services.py 2015-03-05 06:48:41 +0000
150@@ -1,3 +1,5 @@
151+import os
152+
153 from charmhelpers.core import hookenv
154 from charmhelpers.core.services.base import ServiceManager
155 from charmhelpers.core.services import helpers
156@@ -9,7 +11,7 @@
157 def render_env_template(config, name):
158 return helpers.render_template(
159 source='envs/{}.j2'.format(name),
160- target='{}/{}'.format(config['env_dir'], name),
161+ target='{}/{}'.format(os.path.join(config['base_dir'], 'envs'), name),
162 owner=config['code_user'],
163 group=config['code_group'])
164
165
166=== modified file 'templates/envs/REPO_STORE.j2'
167--- templates/envs/REPO_STORE.j2 2015-02-28 00:27:07 +0000
168+++ templates/envs/REPO_STORE.j2 2015-03-05 06:48:41 +0000
169@@ -1,1 +1,1 @@
170-{{ data_dir }}
171+{{ base_dir }}/data/repos
172
173=== modified file 'templates/envs/TURNIP_LOG_DIR.j2'
174--- templates/envs/TURNIP_LOG_DIR.j2 2015-03-02 11:25:29 +0000
175+++ templates/envs/TURNIP_LOG_DIR.j2 2015-03-05 06:48:41 +0000
176@@ -1,1 +1,1 @@
177-{{ log_dir }}
178\ No newline at end of file
179+{{ base_dir }}/logs
180
181=== modified file 'templates/turnip-api.conf.j2'
182--- templates/turnip-api.conf.j2 2015-02-27 18:13:29 +0000
183+++ templates/turnip-api.conf.j2 2015-03-05 06:48:41 +0000
184@@ -4,13 +4,13 @@
185 setuid {{ user }}
186 setgid {{ group }}
187
188-env PYTHON_HOME=/srv/{{ app_name }}/env
189+env PYTHON_HOME={{ base_dir }}/venv
190 env PATH=$PYTHON_HOME/bin:$PATH
191
192-start on started turnip
193-stop on stopping turnip
194+start on started {{ app_name }}
195+stop on stopping {{ app_name }}
196
197-chdir /srv/{{ app_name }}
198-exec $PYTHON_HOME/bin/envdir {{ env_dir }} $PYTHON_HOME/bin/pserve api.ini
199+chdir {{ base_dir }}/code
200+exec $PYTHON_HOME/bin/envdir {{ base_dir }}/envs $PYTHON_HOME/bin/pserve api.ini
201
202 respawn
203
204=== modified file 'templates/turnip.conf.j2'
205--- templates/turnip.conf.j2 2015-02-27 12:27:16 +0000
206+++ templates/turnip.conf.j2 2015-03-05 06:48:41 +0000
207@@ -4,13 +4,13 @@
208 setuid {{ user }}
209 setgid {{ group }}
210
211-env PYTHON_HOME=/srv/{{ app_name }}/env
212+env PYTHON_HOME={{ base_dir }}/venv
213 env PATH=$PYTHON_HOME/bin:$PATH
214
215 start on runlevel [2345]
216 stop on runlevel [016]
217
218-chdir /srv/{{ app_name }}
219-exec $PYTHON_HOME/bin/envdir {{ env_dir }} $PYTHON_HOME/bin/python turnipserver.py
220+chdir {{ base_dir }}/code
221+exec $PYTHON_HOME/bin/envdir {{ base_dir }}/envs $PYTHON_HOME/bin/python turnipserver.py
222
223 respawn

Subscribers

People subscribed via source and target branches

to all changes: