forked from subuk/awx-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awx.spec
266 lines (232 loc) · 8.68 KB
/
awx.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
%define _prefix /opt/awx
%define _mandir %{_prefix}/share/man
%global __os_install_post %{nil}
%define ansible_version 2.3.1.0
%define service_user awx
%define service_group awx
%define service_homedir /var/lib/awx
%define service_logdir /var/log/awx
%define service_configdir /etc/awx
Summary: Ansible AWX
Name: awx
Version: 1.0.1.225
Release: 1%{dist}
Source0: https://github.com/subuk/awx-rpm/releases/download/v%{version}/awx-%{version}.tar.gz
Source1: settings.py.dist
%if 0%{?amzn}
Source2: awx-cbreceiver.upstart
Source3: awx-celery-beat.upstart
Source4: awx-celery-worker.upstart
Source5: awx-channels-worker.upstart
Source6: awx-daphne.upstart
Source7: awx-web.upstart
%endif
%if 0%{?el7}
Source2: awx-cbreceiver.service
Source3: awx-celery-beat.service
Source4: awx-celery-worker.service
Source5: awx-channels-worker.service
Source6: awx-daphne.service
Source7: awx-web.service
%endif
Source8: nginx.conf.example
License: GPLv3
Group: AWX
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}.buildroot
Vendor: AWX
Prefix: %{_prefix}
BuildRequires: gcc gcc-c++ git
BuildRequires: libffi-devel libxslt-devel xmlsec1-devel xmlsec1-openssl-devel libyaml-devel openldap-devel libtool-ltdl-devel
%{?amzn:BuildRequires: python27 python27-virtualenv python27-devel postgresql95-devel}
%{?el7:BuildRequires: systemd python python-virtualenv python-devel postgresql-devel}
Requires: git subversion curl
Requires(pre): /usr/sbin/useradd, /usr/bin/getent
%{?systemd_requires}
%description
%{summary}
%prep
%setup -q
%build
# Setup build environment
virtualenv _buildenv/
_buildenv/bin/pip install -U wheel
_buildenv/bin/pip install -U pip
_buildenv/bin/pip install -U setuptools
export PYTHONPATH="`pwd`/embedded/lib/python2.7/site-packages:`pwd`/embedded/lib64/python2.7/site-packages"
# Install dependencies
cat requirements/requirements_ansible.txt requirements/requirements_ansible_git.txt | \
_buildenv/bin/pip install --no-binary cffi,pycparser,psycopg2,twilio --prefix=`pwd`/embedded/ -r /dev/stdin
cat requirements/requirements.txt requirements/requirements_git.txt | \
_buildenv/bin/pip install --no-binary cffi,pycparser,psycopg2,twilio --prefix=`pwd`/embedded/ -r /dev/stdin
_buildenv/bin/pip install --no-binary cffi,pycparser,psycopg2,twilio --prefix=`pwd`/embedded/ ansible==%{ansible_version}
_buildenv/bin/pip install --no-binary cffi,pycparser,psycopg2,twilio --prefix=`pwd`/embedded/ .
# Fix nested packages
touch embedded/lib64/python2.7/site-packages/zope/__init__.py
touch embedded/lib/python2.7/site-packages/jaraco/__init__.py
touch embedded/lib64/python2.7/site-packages/dm/__init__.py
touch embedded/lib64/python2.7/site-packages/dm/xmlsec/__init__.py
# Collect django static
cat > _awx_rpmbuild_collectstatic_settings.py <<EOF
from awx.settings.defaults import *
DEFAULTS_SNAPSHOT = {}
STATIC_ROOT = "static/"
EOF
export DJANGO_SETTINGS_MODULE="_awx_rpmbuild_collectstatic_settings"
export PYTHONPATH="$PYTHONPATH:."
mkdir -p static/
embedded/bin/awx-manage collectstatic --noinput --clear
# Cleanup
unset PYTHONPATH
unset DJANGO_SETTINGS_MODULE
%install
mkdir -p %{buildroot}%{service_homedir}
mkdir -p %{buildroot}%{service_logdir}
mkdir -p %{buildroot}%{_prefix}/embedded
mkdir -p %{buildroot}%{_prefix}/embedded/bin
mkdir -p %{buildroot}%{_prefix}/bin
mkdir -p %{buildroot}%{service_configdir}
mkdir -p %{buildroot}/var/lib/awx/
echo %{version} > %{buildroot}%{service_homedir}/.tower_version
cp %{_sourcedir}/settings.py.dist %{buildroot}%{service_configdir}/settings.py
mv embedded/lib %{buildroot}%{_prefix}/embedded/lib
mv embedded/lib64 %{buildroot}%{_prefix}/embedded/lib64
mv static %{buildroot}%{_prefix}/static
%if 0%{?amzn}
# Install upstart configuration
mkdir -p %{buildroot}/etc/init
mkdir -p %{buildroot}/etc/rc.d/init.d
for service in awx-cbreceiver awx-celery-beat awx-celery-worker awx-channels-worker awx-daphne awx-web; do
cp %{_sourcedir}/${service}.upstart %{buildroot}/etc/init/${service}.conf
cat > %{buildroot}/etc/rc.d/init.d/${service} <<EOF
#!/bin/sh
#chkconfig: - 99 02
#description: $service
exec /sbin/initctl \$1 $service
EOF
done
%endif
%if 0%{?el7}
# Install systemd configuration
mkdir -p %{buildroot}%{_unitdir}
for service in awx-cbreceiver awx-celery-beat awx-celery-worker awx-channels-worker awx-daphne awx-web; do
cp %{_sourcedir}/${service}.service %{buildroot}%{_unitdir}/
done
%endif
# Create fake python executable
cat > %{buildroot}%{_prefix}/bin/python <<"EOF"
#!/bin/sh
export PYTHONPATH="%{_prefix}/embedded/lib/python2.7/site-packages:%{_prefix}/embedded/lib64/python2.7/site-packages"
export AWX_SETTINGS_FILE=/etc/awx/settings.py
exec %{?amzn:python27}%{?el7:python2} "$@"
EOF
# Export usefull scripts
mv embedded/bin/uwsgi %{buildroot}%{_prefix}/bin/uwsgi
for script_name in awx-manage ansible ansible-playbook daphne celery;do
mv embedded/bin/$script_name %{buildroot}%{_prefix}/bin/$script_name
sed -i '1c#!%{_prefix}/bin/python' %{buildroot}%{_prefix}/bin/$script_name
done
# Install docs
cp %{_sourcedir}/nginx.conf.example ./
%pre
/usr/bin/getent group %{service_group} >/dev/null || /usr/sbin/groupadd --system %{service_group}
/usr/bin/getent passwd %{service_user} >/dev/null || /usr/sbin/useradd --no-create-home --system -g %{service_group} --home-dir %{service_homedir} -s /sbin/nologin %{service_user}
%post
%if 0%{?el7}
%systemd_post awx-cbreceiver
%systemd_post awx-celery-beat
%systemd_post awx-celery-worker
%systemd_post awx-channels-worker
%systemd_post awx-daphne
%systemd_post awx-web
%endif
%if 0%{?amzn}
if [ $1 -eq 1 ]; then
/sbin/chkconfig --add awx-cbreceiver
/sbin/chkconfig --add awx-celery-beat
/sbin/chkconfig --add awx-celery-worker
/sbin/chkconfig --add awx-channels-worker
/sbin/chkconfig --add awx-daphne
/sbin/chkconfig --add awx-web
fi
%endif
%preun
%if 0%{?el7}
%systemd_preun awx-cbreceiver
%systemd_preun awx-celery-beat
%systemd_preun awx-celery-worker
%systemd_preun awx-channels-worker
%systemd_preun awx-daphne
%systemd_preun awx-web
%endif
%if 0%{?amzn}
if [ $1 -eq 0 ]; then
/sbin/service awx-cbreceiver stop >/dev/null 2>&1
/sbin/service awx-celery-beat stop >/dev/null 2>&1
/sbin/service awx-celery-worker stop >/dev/null 2>&1
/sbin/service awx-channels-worker stop >/dev/null 2>&1
/sbin/service awx-daphne stop >/dev/null 2>&1
/sbin/service awx-web stop >/dev/null 2>&1
/sbin/chkconfig --del awx-cbreceiver
/sbin/chkconfig --del awx-celery-beat
/sbin/chkconfig --del awx-celery-worker
/sbin/chkconfig --del awx-channels-worker
/sbin/chkconfig --del awx-daphne
/sbin/chkconfig --del awx-web
fi
%endif
%postun
%if 0%{?el7}
%systemd_postun awx-cbreceiver
%systemd_postun awx-celery-beat
%systemd_postun awx-celery-worker
%systemd_postun awx-channels-worker
%systemd_postun awx-daphne
%systemd_postun awx-web
%endif
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(0644, root, root, 0755)
%doc nginx.conf.example
%attr(0755, root, root) %{_prefix}/bin/uwsgi
%attr(0755, root, root) %{_prefix}/bin/python
%attr(0755, root, root) %{_prefix}/bin/celery
%attr(0755, root, root) %{_prefix}/bin/awx-manage
%attr(0755, root, root) %{_prefix}/bin/daphne
%attr(0755, root, root) %{_prefix}/bin/ansible
%attr(0755, root, root) %{_prefix}/bin/ansible-playbook
%{_prefix}/static
%{_prefix}/embedded/lib
%{_prefix}/embedded/lib64
%dir %attr(0750, %{service_user}, %{service_group}) %{service_homedir}
%{service_homedir}/.tower_version
%dir %attr(0750, root, %{service_group}) %{service_logdir}
%config(noreplace) %{service_configdir}/settings.py
%if 0%{?amzn}
%attr(0644, root, root) /etc/init/awx-cbreceiver.conf
%attr(0644, root, root) /etc/init/awx-celery-beat.conf
%attr(0644, root, root) /etc/init/awx-celery-worker.conf
%attr(0644, root, root) /etc/init/awx-channels-worker.conf
%attr(0644, root, root) /etc/init/awx-daphne.conf
%attr(0644, root, root) /etc/init/awx-web.conf
%attr(0755, root, root) /etc/rc.d/init.d/awx-cbreceiver
%attr(0755, root, root) /etc/rc.d/init.d/awx-celery-beat
%attr(0755, root, root) /etc/rc.d/init.d/awx-celery-worker
%attr(0755, root, root) /etc/rc.d/init.d/awx-channels-worker
%attr(0755, root, root) /etc/rc.d/init.d/awx-daphne
%attr(0755, root, root) /etc/rc.d/init.d/awx-web
%endif
%if 0%{?el7}
%attr(0644, root, root) %{_unitdir}/awx-cbreceiver.service
%attr(0644, root, root) %{_unitdir}/awx-celery-beat.service
%attr(0644, root, root) %{_unitdir}/awx-celery-worker.service
%attr(0644, root, root) %{_unitdir}/awx-channels-worker.service
%attr(0644, root, root) %{_unitdir}/awx-daphne.service
%attr(0644, root, root) %{_unitdir}/awx-web.service
%endif
%changelog
* Thu Nov 21 2017 18:14:55 +0300 Matvey Kruglov <[email protected]> 1.0.1.225-1
- Update upstream version
- Improve centos 7 support
* Wed Sep 21 2017 14:44:23 +0300 Matvey Kruglov <[email protected]> 1.0.0.505-1
- Initial RPM release