docker-build.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. from os import environ, makedirs, chdir, listdir
  3. from os.path import isdir
  4. from subprocess import check_call
  5. from shutil import *
  6. from multiprocessing import cpu_count
  7. # Clean up and clone gluon
  8. if isdir('gluon'):
  9. rmtree('gluon')
  10. check_call('git clone https://github.com/freifunk-gluon/gluon.git gluon -b "%s"' % environ['GLUON_TAG'], shell=True)
  11. makedirs('output')
  12. # Add site configuration
  13. makedirs('gluon/site')
  14. copy('/usr/src/site.mk', 'gluon/site')
  15. copy('/usr/src/site.conf', 'gluon/site')
  16. copytree('/usr/src/i18n', 'gluon/site/i18n')
  17. # Prepare
  18. chdir('gluon')
  19. check_call('make update', shell=True)
  20. # Choose targets to build
  21. if 'GLUON_TARGETS' in environ:
  22. targets = environ['GLUON_TARGETS'].split()
  23. else:
  24. targets = [f for f in listdir('targets') if isdir('targets/%s' % f)]
  25. branch = environ['GLUON_BRANCH'] if 'GLUON_BRANCH' in environ else 'stable'
  26. broken = environ['GLUON_BROKEN'] if 'GLUON_BROKEN' in environ else '0'
  27. # Build
  28. for target in targets:
  29. print('Building for target %s' % target)
  30. check_call('make -j %s GLUON_BRANCH=%s BROKEN=%s GLUON_TARGET=%s' % (cpu_count()+1, branch, broken, target), shell=True)
  31. check_call('make manifest GLUON_BRANCH=%s' % branch, shell=True)
  32. copytree('output', '../output/%s' % target)
  33. check_call('make dirclean', shell=True)
  34. print('''BUILD FINISHED
  35. You can copy the resulting images from the container using:
  36. docker cp %s:/usr/src/build/output <destination>'''% environ.get('HOSTNAME'))