diff options
author | Camil Staps | 2017-02-07 17:49:32 +0100 |
---|---|---|
committer | Camil Staps | 2017-02-07 17:50:45 +0100 |
commit | d1405a49f81fe0a8278ea58b71e4fc70999f1f13 (patch) | |
tree | f4fdc0f7386820f12b227f9fa0c6280ca3b0b37d | |
parent | Web interface (diff) |
buildslave
-rw-r--r-- | buildslave/Dockerfile | 13 | ||||
-rwxr-xr-x | buildslave/entrypoint.sh | 6 | ||||
-rwxr-xr-x | buildslave/update.py | 72 | ||||
-rw-r--r-- | docker-compose.yml | 14 |
4 files changed, 98 insertions, 7 deletions
diff --git a/buildslave/Dockerfile b/buildslave/Dockerfile new file mode 100644 index 0000000..36c2ef6 --- /dev/null +++ b/buildslave/Dockerfile @@ -0,0 +1,13 @@ +FROM python:2-slim + +RUN apt-get update -qq \ + && PACKAGES="libmysqlclient-dev gcc" \ + && apt-get install -qq $PACKAGES \ + && pip install MySQL-python gitpython \ + && ADDED_PACKAGES=`apt-mark showauto` \ + && apt-get remove --purge -qq $PACKAGES $ADDED_PACKAGES \ + && apt-get install -qq libmysqlclient-dev git make \ + && rm -rf /var/lib/apt/lists/* + +COPY . / +CMD ["bash", "entrypoint.sh"] diff --git a/buildslave/entrypoint.sh b/buildslave/entrypoint.sh new file mode 100755 index 0000000..7a7f526 --- /dev/null +++ b/buildslave/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +while :; do + ./update.py >> update.log + sleep 10 +done diff --git a/buildslave/update.py b/buildslave/update.py new file mode 100755 index 0000000..0228059 --- /dev/null +++ b/buildslave/update.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +import json +import os +import re +from subprocess import call +import shutil + +import MySQLdb +from git import Repo + +PLATFORMS = ['linux32', 'linux64', 'mac', 'win32', 'win64'] + +os.chdir('/tmp') + +db = MySQLdb.connect(host="db", user="clpm", passwd="clpm", db="clpmdb") + +pcur = db.cursor() +vcur = db.cursor() + +pcur.execute('SELECT `id`,`name`,`git_url` FROM `package`') +for pkg in pcur.fetchall(): + print(pkg[1]) + + known_versions = [] + vcur.execute('SELECT `major`,`minor`,`revision` FROM `version` ' + \ + 'WHERE `package_id`=%d' % pkg[0]) + for ver in vcur.fetchall(): + known_versions.append((ver[0], ver[1], ver[2])) + + try: + shutil.rmtree(pkg[1]) + except: + pass + + repo = Repo.clone_from(pkg[2], pkg[1]) + for tag in repo.tags: + mat = re.match(r'v(\d+)\.(\d+)\.(\d+)', str(tag)) + if mat: + [vmaj, vmin, vrev] = [int(mat.group(i)) for i in [1,2,3]] + + if (vmaj, vmin, vrev) in known_versions: + continue + + repo.head.reference = tag + repo.head.reset(index=True, working_tree=True) + + os.makedirs('/repo/%s/%d.%d.%d' % (pkg[1], vmaj, vmin, vrev)) + for pf in PLATFORMS: + print(str(tag) + '-' + pf) + call(['make', '-C', pkg[1], pf + '.tar.gz']) + shutil.move( + '/tmp/%s/%s.tar.gz' % (pkg[1], pf), + '/repo/%s/%d.%d.%d/%s.tar.gz' % + (pkg[1], vmaj, vmin, vrev, pf)) + call(['make', '-C', pkg[1], 'clean']) + + depends = [] + with open('/tmp/%s/clpm.json' % pkg[1], 'r') as clpm: + depends = json.load(clpm)['depends'] + + vcur.execute('INSERT INTO `version` ' + \ + '(`package_id`,`major`,`minor`,`revision`,`depends`) ' + \ + 'VALUES (%d,%d,%d,%d,\'%s\')' % + (pkg[0], vmaj, vmin, vrev, json.dumps(depends))) + + try: + shutil.rmtree(pkg[1]) + except: + pass + +db.commit() +db.close() diff --git a/docker-compose.yml b/docker-compose.yml index b9a2a86..c3e4391 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,10 +22,10 @@ services: - "./frontend/:/var/www/html/" restart: always -# buildslave: -# build: buildslave -# depends_on: -# - db -# volumes: -# - "./frontend/repo:/repo" -# restart: always + buildslave: + build: buildslave + depends_on: + - db + volumes: + - "./frontend/repo:/repo" + restart: always |