docker-build.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. # Add site configuration
  12. makedirs('gluon/site')
  13. copy('/usr/src/site.mk', 'gluon/site')
  14. copy('/usr/src/site.conf', 'gluon/site')
  15. copytree('/usr/src/i18n', 'gluon/site/i18n')
  16. # Prepare
  17. chdir('gluon')
  18. check_call('make update', shell=True)
  19. # Choose targets to build
  20. if 'GLUON_TARGETS' in environ:
  21. targets = environ['GLUON_TARGETS'].split()
  22. else:
  23. targets = [f for f in listdir('targets') if isdir('targets/%s' % f)]
  24. branch = environ['GLUON_BRANCH'] if 'GLUON_BRANCH' in environ else 'stable'
  25. broken = environ['GLUON_BROKEN'] if 'GLUON_BROKEN' in environ else '0'
  26. # Build
  27. for target in targets:
  28. print('Building for target %s' % target)
  29. check_call('make -j %s GLUON_BRANCH=%s BROKEN=%s GLUON_TARGET=%s' % (cpu_count(), branch, broken, target), shell=True)
  30. check_call('make dirclean', shell=True)
  31. check_call('make manifest GLUON_BRANCH=%s' % branch, shell=True)
  32. print('''BUILD FINISHED
  33. You can copy the resulting images from the container using:
  34. docker cp %s:/usr/src/build/gluon/output <destination>'''% environ.get('HOSTNAME'))