docker: add initial release build scripts

This commit is contained in:
Danny Robson 2019-04-04 14:56:37 +11:00
parent 1882bcc7e1
commit 8c4e37a85d
6 changed files with 171 additions and 0 deletions

36
docker/base/Dockerfile Normal file
View File

@ -0,0 +1,36 @@
FROM archlinux/base
RUN echo "Server = http://mirror.internode.on.net/pub/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
#RUN sed -i 's/https/http/g' /etc/pacman.d/mirrorlist
RUN pacman --noconfirm -Syu
RUN pacman --noconfirm -S python3
RUN pacman --noconfirm -S gcc
RUN pacman --noconfirm -S ninja
RUN pacman --noconfirm -S cmake
RUN pacman --noconfirm -S ragel
RUN pacman --noconfirm -S git
RUN pacman --noconfirm -S autoconf
RUN pacman --noconfirm -S automake
RUN pacman --noconfirm -S make
RUN pacman --noconfirm -S asciidoctor
# glfw dependencies
RUN pacman --noconfirm -S libxi
RUN pacman --noconfirm -S libxrandr
RUN pacman --noconfirm -S libxinerama
RUN pacman --noconfirm -S libxcursor
RUN pacman --noconfirm -S libgl
RUN pacman --noconfirm -S bison
RUN pacman --noconfirm -S flex
RUN pacman --noconfirm -S pkg-config
RUN pacman --noconfirm -S glslang
RUN gem install asciidoctor-diagram
COPY build.sh /opt/nerdcruft/
RUN chmod a+rx /opt/nerdcruft/build.sh
ENTRYPOINT /opt/nerdcruft/build.sh

38
docker/base/build.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/sh
die() { echo "$*" 1>&2 ; exit 1; }
buildroot="/build/"
config="release/gcc"
configroot="${buildroot}/build/${config}/"
mkdir -p "${buildroot}/" || die "Could not create buildroot"
# Half-arse a clone of the provided .git directory.
#
# The standard mechanism for cloning of `git clone --local` won't work
# without requiring us to use non-local clones to initalise the submodules.
# This is problematic mostly because of the heavyweight KHR submodules.
#
# Instead we copy the provided live .git directory and reset everything back
# into existence.
cp -ra /mnt/git "${buildroot}/.git" || die "Unable to copy gitdir"
cd "${buildroot}" && git checkout && git reset --hard HEAD || die "Unable to checkout root"
git submodule update --init --recursive || die "Unable to checkout submodules"
git submodule foreach git checkout master || die "Unable to checkout master for submodules"
# Create a build directory and configure the project
mkdir -p "${configroot}"|| die "Unable to create builddir"
cd "${configroot}" || die "Unable to switch to builddir"
sh -c "$(${buildroot}/build/init.py)" || die "Unable to configure project"
# Build the required targets
ninja || die "Unable to build binaries"
ninja doc || die "Unable to build docs"
ninja test || die "Tests failed"
ninja package || die "Unable to build package"
cp "${configroot}/"edict-*.tar.* /mnt/export || die "Could not copy installers"
exit 0

91
docker/proxify.py Executable file
View File

@ -0,0 +1,91 @@
#!/usr/bin/env python3
import http.server
import hashlib
import urllib.request
import http.server
import subprocess
import sys
import signal
import itertools
import requests
class CachingHandler(http.server.BaseHTTPRequestHandler):
def _cached_read(self, input, chunksize=4096):
# >>> datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
with open(input, 'rb') as data:
while True:
chunk = data.read(chunksize)
if not chunk:
break
yield chunk
def _saving_read(self, output):
with requests.get(self.path, stream=True) as src:
if src.status_code != 200:
self.send_error(src.status_code)
return
self.send_response(200)
self.end_headers()
try:
with open(output, 'wb') as data:
for chunk in src.iter_content(chunk_size=4096):
if chunk:
data.write(chunk)
yield(chunk)
except Exception as err:
os.unlink(output)
raise err
def do_GET(self):
h = hashlib.sha256()
h.update(self.path.encode())
path = os.path.join(args.store, h.hexdigest() + ".data")
chunker = self._saving_read if not os.path.exists(path) else self._cached_read
for chunk in chunker(path):
self.wfile.write(chunk)
if __name__ == '__main__':
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('--store', type=str, required=True)
parser.add_argument('--address', type=str, default="0.0.0.0")
parser.add_argument('--port', type=int, default=8000)
parser.add_argument('cmd', type=str, nargs=1)
parser.add_argument('args', type=str, nargs=argparse.REMAINDER)
args = parser.parse_args()
# Instantiate the server before we run the child process
os.makedirs(args.store, exist_ok=True)
server = http.server.HTTPServer(
(args.address, args.port),
CachingHandler
)
pid = os.fork()
if pid == 0:
# Start the child process. Tell the parent to shutdown the server when
# we are finished.
res = subprocess.run(
['env', f"http_proxy={args.address}:{args.port}"] + args.cmd + args.args,
stderr=sys.stderr, stdout=sys.stdout
)
os.kill(os.getppid(), signal.SIGHUP)
sys.exit(res.returncode)
else:
# Run a server until we get a SIGHUP, then wait for the child to exit.
server.serve_forever()
(_, status) = os.waitpid(pid)
sys.exit(status)

3
docker/reimage.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
./proxify.py --store ~/tmp/cache/ -- docker build -t nerdcruft/base base/

3
docker/release.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
docker run -v /home/danny/src/lobo/.git:/mnt/git:ro -v /home/danny/src/lobo/build/package:/mnt/export nerdcruft/base /opt/nerdcruft/build.sh

0
package/.keep Normal file
View File