2 # -*- coding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-Today OpenERP SA (<http://www.openerp.com>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
32 from contextlib import contextmanager
34 from os.path import abspath, dirname, join
35 from tempfile import NamedTemporaryFile
38 #----------------------------------------------------------
40 #----------------------------------------------------------
41 execfile(join(dirname(__file__), '..', 'openerp', 'release.py'))
42 timestamp = time.strftime("%Y%m%d-%H%M%S", time.gmtime())
49 'deb.tar.gz': ['deb', 'tar.gz'],
55 if not os.path.isdir(d):
58 def system(l, chdir=None):
63 if isinstance(l, list):
64 rc = os.spawnvp(os.P_WAIT, l[0], l)
65 elif isinstance(l, str):
67 rc = os.spawnvp(os.P_WAIT, tmp[0], tmp)
72 def _rpc_count_modules(addr='http://127.0.0.1', port=8069, dbname='mycompany'):
74 modules = xmlrpclib.ServerProxy('%s:%s/xmlrpc/object' % (addr, port)).execute(
75 dbname, 1, 'admin', 'ir.module.module', 'search', [('state', '=', 'installed')]
77 if modules and len(modules) > 1:
79 toinstallmodules = xmlrpclib.ServerProxy('%s:%s/xmlrpc/object' % (addr, port)).execute(
80 dbname, 1, 'admin', 'ir.module.module', 'search', [('state', '=', 'to install')]
83 print("Package test: FAILED. Not able to install dependencies of base.")
84 raise Exception("Installation of package failed")
86 print("Package test: successfuly installed %s modules" % len(modules))
88 print("Package test: FAILED. Not able to install base.")
89 raise Exception("Installation of package failed")
91 def publish(o, releases):
92 def _publish(o, release):
93 extension = ''.join(release.split('.', 1)[1])
94 release_extension = PUBLISH_DIRS[extension][1] if isinstance(PUBLISH_DIRS[extension], list) else extension
95 release_dir = PUBLISH_DIRS[extension][0] if isinstance(PUBLISH_DIRS[extension], list) else PUBLISH_DIRS[extension]
97 release_filename = 'odoo_%s-%s.%s' % (version, timestamp, release_extension)
98 release_path = join(o.pub, release_dir, release_filename)
100 system('mkdir -p %s' % join(o.pub, release_dir))
101 shutil.move(join(o.build_dir, release), release_path)
103 if release_extension == 'deb':
104 temp_path = tempfile.mkdtemp(suffix='debPackages')
105 system(['cp', release_path, temp_path])
106 subprocess.Popen('dpkg-scanpackages . /dev/null | gzip -9c > %s' % join(o.pub, 'deb', 'Packages.gz'), shell=True, cwd=temp_path)
107 shutil.rmtree(temp_path)
109 # Latest/symlink handler
110 release_abspath = abspath(release_path)
111 latest_abspath = release_abspath.replace(timestamp, 'latest')
113 if os.path.islink(latest_abspath):
114 os.unlink(latest_abspath)
116 os.symlink(release_abspath, latest_abspath)
118 if isinstance(releases, basestring):
119 _publish(o, releases)
120 elif isinstance(releases, list):
121 for release in releases:
124 class OdooDocker(object):
126 self.log_file = NamedTemporaryFile(mode='w+b', prefix="bash", suffix=".txt", delete=False)
127 self.port = 8069 # TODO sle: reliable way to get a free port?
128 self.prompt_re = '(\r\nroot@|bash-).*# '
131 def system(self, command):
132 self.docker.sendline(command)
133 self.docker.expect(self.prompt_re)
135 def start(self, docker_image, build_dir, pub_dir):
136 self.build_dir = build_dir
137 self.pub_dir = pub_dir
139 self.docker = pexpect.spawn(
140 'docker run -v %s:/opt/release -p 127.0.0.1:%s:8069'
141 ' -t -i %s /bin/bash --noediting' % (self.build_dir, self.port, docker_image),
144 time.sleep(2) # let the bash start
145 self.docker.logfile_read = self.log_file
146 self.id = subprocess.check_output('docker ps -l -q', shell=True)
150 _rpc_count_modules(port=str(self.port))
152 print('Exception during docker execution: %s:' % str(e))
153 print('Error during docker execution: printing the bash output:')
154 with open(self.log_file.name) as f:
155 print '\n'.join(f.readlines())
159 system('docker rm -f %s' % self.id)
160 self.log_file.close()
161 os.remove(self.log_file.name)
164 def docker(docker_image, build_dir, pub_dir):
165 _docker = OdooDocker()
167 _docker.start(docker_image, build_dir, pub_dir)
176 def __init__(self, o, image, ssh_key='', login='openerp'):
179 self.ssh_key = ssh_key
182 def timeout(self,signum,frame):
183 print "vm timeout kill",self.pid
187 l="kvm -net nic,model=rtl8139 -net user,hostfwd=tcp:127.0.0.1:10022-:22,hostfwd=tcp:127.0.0.1:18069-:8069,hostfwd=tcp:127.0.0.1:15432-:5432 -drive".split(" ")
188 #l.append('file=%s,if=virtio,index=0,boot=on,snapshot=on'%self.image)
189 l.append('file=%s,snapshot=on'%self.image)
190 #l.extend(['-vnc','127.0.0.1:1'])
191 l.append('-nographic')
193 self.pid=os.spawnvp(os.P_NOWAIT, l[0], l)
196 signal.signal(signal.SIGALRM, self.timeout)
200 signal.signal(signal.SIGALRM, signal.SIG_DFL)
205 l=['ssh','-o','UserKnownHostsFile=/dev/null','-o','StrictHostKeyChecking=no','-p','10022','-i',self.ssh_key,'%s@127.0.0.1'%self.login,cmd]
208 def rsync(self,args,options='--delete --exclude .bzrignore'):
209 cmd ='rsync -rt -e "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 -i %s" %s %s' % (self.ssh_key, options, args)
215 class KVMWinBuildExe(KVM):
217 with open(join(self.o.build_dir, 'setup/win32/Makefile.version'), 'w') as f:
218 f.write("VERSION=%s\n" % self.o.version_full)
219 with open(join(self.o.build_dir, 'setup/win32/Makefile.python'), 'w') as f:
220 f.write("PYTHON_VERSION=%s\n" % self.o.vm_winxp_python_version.replace('.', ''))
222 self.ssh("mkdir -p build")
223 self.rsync('%s/ %s@127.0.0.1:build/server/' % (self.o.build_dir, self.login))
224 self.ssh("cd build/server/setup/win32;time make allinone;")
225 self.rsync('%s@127.0.0.1:build/server/setup/win32/release/ %s/' % (self.login, self.o.build_dir), '')
226 print "KVMWinBuildExe.run(): done"
228 class KVMWinTestExe(KVM):
230 # Cannot use o.version_full when the version is not correctly parsed
231 # (for instance, containing *rc* or *dev*)
232 setuppath = glob("%s/openerp-server-setup-*.exe" % self.o.build_dir)[0]
233 setupfile = setuppath.split('/')[-1]
234 setupversion = setupfile.split('openerp-server-setup-')[1].split('.exe')[0]
236 self.rsync('"%s" %s@127.0.0.1:' % (setuppath, self.login))
237 self.ssh("TEMP=/tmp ./%s /S" % setupfile)
238 self.ssh('PGPASSWORD=openpgpwd /cygdrive/c/"Program Files"/"Odoo %s"/PostgreSQL/bin/createdb.exe -e -U openpg mycompany' % setupversion)
239 self.ssh('/cygdrive/c/"Program Files"/"Odoo %s"/server/openerp-server.exe -d mycompany -i base --stop-after-init' % setupversion)
240 self.ssh('net start odoo-server-8.0')
241 _rpc_count_modules(port=18069)
243 #----------------------------------------------------------
245 #----------------------------------------------------------
246 def _prepare_build_dir(o):
247 cmd = ['rsync', '-a', '--exclude', '.git', '--exclude', '*.pyc', '--exclude', '*.pyo']
248 system(cmd + ['%s/' % o.odoo_dir, o.build_dir])
249 for i in glob(join(o.build_dir, 'addons/*')):
250 shutil.move(i, join(o.build_dir, 'openerp/addons'))
253 system(['python2', 'setup.py', '--quiet', 'sdist'], o.build_dir)
254 system(['cp', glob('%s/dist/openerp-*.tar.gz' % o.build_dir)[0], '%s/odoo.tar.gz' % o.build_dir])
257 system(['dpkg-buildpackage', '-rfakeroot', '-uc', '-us'], o.build_dir)
258 system(['cp', glob('%s/../odoo_*.deb' % o.build_dir)[0], '%s/odoo.deb' % o.build_dir])
259 system(['cp', glob('%s/../odoo_*.dsc' % o.build_dir)[0], '%s/odoo.dsc' % o.build_dir])
260 system(['cp', glob('%s/../odoo_*_amd64.changes' % o.build_dir)[0], '%s/odoo_amd64.changes' % o.build_dir])
261 system(['cp', glob('%s/../odoo_*.tar.gz' % o.build_dir)[0], '%s/odoo.deb.tar.gz' % o.build_dir])
264 system(['python2', 'setup.py', '--quiet', 'bdist_rpm'], o.build_dir)
265 system(['cp', glob('%s/dist/openerp-*.noarch.rpm' % o.build_dir)[0], '%s/odoo.noarch.rpm' % o.build_dir])
266 system(['cp', glob('%s/dist/openerp-*.src.rpm' % o.build_dir)[0], '%s/odoo.src.rpm' % o.build_dir])
269 KVMWinBuildExe(o, o.vm_winxp_image, o.vm_winxp_ssh_key, o.vm_winxp_login).start()
270 system(['cp', glob('%s/openerp*.exe' % o.build_dir)[0], '%s/odoo.exe' % o.build_dir])
272 #----------------------------------------------------------
274 #----------------------------------------------------------
276 with docker('debian:stable', o.build_dir, o.pub) as wheezy:
277 wheezy.release = 'odoo.tar.gz'
278 wheezy.system('apt-get update -qq && apt-get upgrade -qq -y')
279 wheezy.system("apt-get install postgresql python-dev postgresql-server-dev-all python-pip build-essential libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libssl-dev libjpeg-dev -y")
280 wheezy.system("service postgresql start")
281 wheezy.system('su postgres -s /bin/bash -c "pg_dropcluster --stop 9.1 main"')
282 wheezy.system('su postgres -s /bin/bash -c "pg_createcluster --start -e UTF-8 9.1 main"')
283 wheezy.system('pip install -r /opt/release/requirements.txt')
284 wheezy.system('/usr/local/bin/pip install /opt/release/%s' % wheezy.release)
285 wheezy.system("useradd --system --no-create-home odoo")
286 wheezy.system('su postgres -s /bin/bash -c "createuser -s odoo"')
287 wheezy.system('su postgres -s /bin/bash -c "createdb mycompany"')
288 wheezy.system('mkdir /var/lib/odoo')
289 wheezy.system('chown odoo:odoo /var/lib/odoo')
290 wheezy.system('su odoo -s /bin/bash -c "odoo.py --addons-path=/usr/local/lib/python2.7/dist-packages/openerp/addons -d mycompany -i base --stop-after-init"')
291 wheezy.system('su odoo -s /bin/bash -c "odoo.py --addons-path=/usr/local/lib/python2.7/dist-packages/openerp/addons -d mycompany &"')
294 with docker('debian:stable', o.build_dir, o.pub) as wheezy:
295 wheezy.release = 'odoo.deb'
296 wheezy.system('/usr/bin/apt-get update -qq && /usr/bin/apt-get upgrade -qq -y')
297 wheezy.system("apt-get install postgresql -y")
298 wheezy.system("service postgresql start")
299 wheezy.system('su postgres -s /bin/bash -c "pg_dropcluster --stop 9.1 main"')
300 wheezy.system('su postgres -s /bin/bash -c "pg_createcluster --start -e UTF-8 9.1 main"')
301 wheezy.system('su postgres -s /bin/bash -c "createdb mycompany"')
302 wheezy.system('/usr/bin/dpkg -i /opt/release/%s' % wheezy.release)
303 wheezy.system('/usr/bin/apt-get install -f -y')
304 wheezy.system('su odoo -s /bin/bash -c "odoo.py -c /etc/odoo/openerp-server.conf -d mycompany -i base --stop-after-init"')
305 wheezy.system('su odoo -s /bin/bash -c "odoo.py -c /etc/odoo/openerp-server.conf -d mycompany &"')
308 with docker('centos:centos7', o.build_dir, o.pub) as centos7:
309 centos7.release = 'odoo.noarch.rpm'
310 centos7.system('rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-1.noarch.rpm')
311 centos7.system('yum update -y && yum upgrade -y')
312 centos7.system('yum install python-pip gcc python-devel -y')
313 centos7.system('pip install pydot pyPdf vatnumber xlwt http://download.gna.org/pychart/PyChart-1.39.tar.gz')
314 centos7.system('yum install postgresql postgresql-server postgresql-libs postgresql-contrib postgresql-devel -y')
315 centos7.system('mkdir -p /var/lib/postgres/data')
316 centos7.system('chown -R postgres:postgres /var/lib/postgres/data')
317 centos7.system('chmod 0700 /var/lib/postgres/data')
318 centos7.system('su postgres -c "initdb -D /var/lib/postgres/data -E UTF-8"')
319 centos7.system('cp /usr/share/pgsql/postgresql.conf.sample /var/lib/postgres/data/postgresql.conf')
320 centos7.system('su postgres -c "/usr/bin/pg_ctl -D /var/lib/postgres/data start"')
321 centos7.system('su postgres -c "createdb mycompany"')
322 centos7.system('export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/dist-packages')
323 centos7.system('su postgres -c "createdb mycompany"')
324 centos7.system('yum install /opt/release/%s -y' % centos7.release)
325 centos7.system('su odoo -s /bin/bash -c "openerp-server -c /etc/odoo/openerp-server.conf -d mycompany -i base --stop-after-init"')
326 centos7.system('su odoo -s /bin/bash -c "openerp-server -c /etc/odoo/openerp-server.conf -d mycompany &"')
329 KVMWinTestExe(o, o.vm_winxp_image, o.vm_winxp_ssh_key, o.vm_winxp_login).start()
331 #----------------------------------------------------------
333 #----------------------------------------------------------
335 op = optparse.OptionParser()
336 root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
337 build_dir = "%s-%s" % (root, timestamp)
339 op.add_option("-b", "--build-dir", default=build_dir, help="build directory (%default)", metavar="DIR")
340 op.add_option("-p", "--pub", default=None, help="pub directory (%default)", metavar="DIR")
341 op.add_option("", "--no-testing", action="store_true", help="don't test the builded packages")
342 op.add_option("-v", "--version", default='8.0', help="version (%default)")
344 op.add_option("", "--no-debian", action="store_true", help="don't build the debian package")
345 op.add_option("", "--no-rpm", action="store_true", help="don't build the rpm package")
346 op.add_option("", "--no-tarball", action="store_true", help="don't build the tarball")
347 op.add_option("", "--no-windows", action="store_true", help="don't build the windows package")
350 op.add_option("", "--vm-winxp-image", default='/home/odoo/vm/winxp27/winxp27.vdi', help="%default")
351 op.add_option("", "--vm-winxp-ssh-key", default='/home/odoo/vm/winxp27/id_rsa', help="%default")
352 op.add_option("", "--vm-winxp-login", default='Naresh', help="Windows login (%default)")
353 op.add_option("", "--vm-winxp-python-version", default='2.7', help="Windows Python version installed in the VM (default: %default)")
355 (o, args) = op.parse_args()
356 # derive other options
358 o.pkg = join(o.build_dir, 'pkg')
359 o.version_full = '%s-%s' % (o.version, timestamp)
360 o.work = join(o.build_dir, 'openerp-%s' % o.version_full)
361 o.work_addons = join(o.work, 'openerp', 'addons')
366 _prepare_build_dir(o)
373 publish(o, 'odoo.tar.gz')
375 print("Won't publish the tgz release.\n Exception: %s" % str(e))
381 publish(o, ['odoo.deb', 'odoo.dsc', 'odoo_amd64.changes', 'odoo.deb.tar.gz'])
383 print("Won't publish the deb release.\n Exception: %s" % str(e))
389 publish(o, ['odoo.noarch.rpm', 'odoo.src.rpm'])
391 print("Won't publish the rpm release.\n Exception: %s" % str(e))
397 publish(o, 'odoo.exe')
399 print("Won't publish the exe release.\n Exception: %s" % str(e))
403 for leftover in glob('%s/../odoo_*' % o.build_dir):
406 shutil.rmtree(o.build_dir)
407 print('Build dir %s removed' % o.build_dir)
410 system("docker rm -f `docker ps -a | awk '{print $1 }'` 2>>/dev/null")
411 print('Remaining dockers removed')
414 if __name__ == '__main__':