Преглед изворни кода

Use python instead of shell for build script, only build some targets by default

Markus Lindenberg пре 8 година
родитељ
комит
5e2db27a05
5 измењених фајлова са 66 додато и 41 уклоњено
  1. 7 5
      Dockerfile
  2. 10 3
      README.md
  3. 5 0
      build.sh
  4. 44 0
      docker-build.py
  5. 0 33
      docker-build.sh

+ 7 - 5
Dockerfile

@@ -3,16 +3,17 @@ MAINTAINER Markus Lindenberg <markus@lindenberg.io>
 
 ENV GLUON_TAG v2016.1
 ENV DEFAULT_GLUON_RELEASE 0.8.0
+ENV GLUON_TARGETS ar71xx-generic ar71xx-nand mpc85xx-generic x86-generic x86-64
+ENV GLUON_BRANCH stable
 
 ENV DEBIAN_FRONTEND noninteractive
 ENV DEBIAN_PRIORITY critical
 ENV DEBCONF_NOWARNINGS yes
 
 RUN apt-get update
-RUN apt-get -y install --no-install-recommends ca-certificates python wget file git subversion build-essential gawk unzip libncurses5-dev zlib1g-dev openssl libssl-dev && apt-get clean
+RUN apt-get -y install --no-install-recommends ca-certificates python python3 wget file git subversion build-essential gawk unzip libncurses5-dev zlib1g-dev openssl libssl-dev && apt-get clean
 
-
-ADD docker-build.sh /usr/src/build.sh
+ADD docker-build.py /usr/src/build.py
 ADD site.mk /usr/src/site.mk
 ADD site.conf /usr/src/site.conf
 ADD i18n /usr/src/i18n
@@ -21,6 +22,7 @@ RUN adduser --system --home /usr/src/build build
 USER build
 WORKDIR /usr/src/build
 RUN git config --global user.email "technik@freifunk-dortmund.de"
-RUN git config --global user.name "FFDO Gluon Build System"
+RUN git config --global user.name "FFDO Gluon Build Container"
+
+CMD ["/usr/src/build.py"]
 
-CMD ["/usr/src/build.sh"]

+ 10 - 3
README.md

@@ -5,8 +5,15 @@ FF Dortmund (FFDO) specific Gluon configuration
 
 See https://docs.docker.com/installation/#installation on how to get Docker.
 
+
+```
+./build.sh
+```
+
+## Cleaning up
+
 ```
-docker build -t ffdobuild .
-docker run ffdobuild
+docker rm ffodbuild
+docker rmi ffdobuild
 ```
-After a successful build you can remove the used container. Use `docker ps -a` to find the container ID and `docker rm <container>` to remove the container. Use `docker rmi ffdobuild` to remove the image used to create the container.
+

+ 5 - 0
build.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+docker rm -f ffdobuild
+docker build -t ffdobuild .
+docker run --name ffdobuild ffdobuild

+ 44 - 0
docker-build.py

@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+from os import environ, makedirs, chdir, listdir
+from os.path import isdir
+from subprocess import check_call
+from shutil import *
+from multiprocessing import cpu_count
+
+# Clean up and clone gluon
+if isdir('gluon'):
+    rmtree('gluon')
+check_call('git clone https://github.com/freifunk-gluon/gluon.git gluon -b "%s"' % environ['GLUON_TAG'], shell=True)
+
+# Add site configuration
+makedirs('gluon/site')
+copy('/usr/src/site.mk', 'gluon/site')
+copy('/usr/src/site.conf', 'gluon/site')
+copytree('/usr/src/i18n', 'gluon/site/i18n')
+
+# Prepare
+chdir('gluon')
+check_call('make update', shell=True)
+
+# Choose targets to build
+if 'GLUON_TARGETS' in environ:
+    targets = environ['GLUON_TARGETS'].split()
+else:
+    targets = [f for f in listdir('targets') if isdir('targets/%s' % f)]
+
+branch = environ['GLUON_BRANCH'] if 'GLUON_BRANCH' in environ else 'stable'
+broken = environ['GLUON_BROKEN'] if 'GLUON_BROKEN' in environ else '0'
+
+# Build
+for target in targets:
+    print('Building for target %s' % target)
+    check_call('make -j %s GLUON_BRANCH=%s BROKEN=%s GLUON_TARGET=%s' % (cpu_count(), branch, broken, target), shell=True)
+    check_call('make dirclean', shell=True, check=True)
+
+check_call('make manifest GLUON_BRANCH=%s' % branch, shell=True)
+
+print('''BUILD FINISHED
+You can copy the resulting images from the container using:
+docker cp %s:/usr/src/build/gluon/output <destination>'''% environ.get('HOSTNAME'))
+

+ 0 - 33
docker-build.sh

@@ -1,33 +0,0 @@
-#!/bin/bash
-
-set -x -e
-
-# Clean up
-rm -rf gluon
-git clone https://github.com/freifunk-gluon/gluon.git gluon -b "${GLUON_TAG}"
-
-# Add site configuration
-mkdir -p gluon/site
-cp /usr/src/site.mk gluon/site/
-cp /usr/src/site.conf gluon/site/
-cp -r /usr/src/i18n gluon/site/
-
-# Build
-cd gluon
-make update
-
-for target in $(ls targets/)
-do
-	if [ -d "targets/$target" ]; then
-		echo "Building for target $target"
-		time make -j $(($(nproc)+1)) BROKEN=1 GLUON_TARGET=$target
-		make dirclean
-	fi
-done
-
-make manifest GLUON_BRANCH=stable
-
-set +x
-echo -e "\nBUILD FINISHED\n"
-echo "You can copy the resulting images from the container using:"
-echo -e "\ndocker cp ${HOSTNAME}:/usr/src/build/gluon/output <destination>\n"