Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Chroot seems to work for simple enough builds
Browse files Browse the repository at this point in the history
  • Loading branch information
apourchet committed Oct 23, 2019
1 parent 1bacf2a commit 41c2c6d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions testdata/chroot-simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM debian:9
RUN echo "ASD" > /asd
RUN cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
55 changes: 55 additions & 0 deletions tools/scripts/makisu_chroot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#! /bin/bash

set -e

[ -z "$1" ] && echo "Must at least provide context of build" && exit 1

CHROOT=${CHROOT_LOCATION:-$HOME/.makisu-chroot-$RANDOM}
SSL_CERT_DIR=${SSL_CERTS:-/etc/ssl/certs}
CONTEXT=${@: -1}
BUILD_VOLUMES="$CONTEXT:/context,$BUILD_VOLUMES"

function makisu::prepare_internals () {
mkdir -p $CHROOT/makisu-internal/certs
cp $(which makisu) $CHROOT/makisu-internal/makisu
cat $SSL_CERT_DIR/* > $CHROOT/makisu-internal/certs/cacerts.pem
}

function makisu::prepare_dev () {
mkdir -p $CHROOT/dev
mknod -m 622 $CHROOT/dev/console c 5 1
mknod -m 666 $CHROOT/dev/null c 1 3
mknod -m 666 $CHROOT/dev/zero c 1 5
mknod -m 666 $CHROOT/dev/ptmx c 5 2
mknod -m 666 $CHROOT/dev/tty c 5 0
mknod -m 444 $CHROOT/dev/random c 1 8
mknod -m 444 $CHROOT/dev/urandom c 1 9
chown root:tty $CHROOT/dev/{console,ptmx,tty}
}

function makisu::prepare_etc () {
mkdir -p $CHROOT/etc
cp /etc/*.conf $CHROOT/etc/
}

function makisu::prepare_volumes () {
for vol in $(sed "s/,/ /g" <<< $BUILD_VOLUMES); do
from=$(cut -d ':' -f 1 <<< $vol)
to=$(cut -d ':' -f 2 <<< $vol)
echo "Copying volume $from to chroot directory $CHROOT/$to"
mkdir -p $CHROOT/$to
cp -r $from/* $CHROOT/$to
done
}

echo "Preparing chroot at $CHROOT"
rm -rf $CHROOT

makisu::prepare_internals
makisu::prepare_etc
makisu::prepare_dev
makisu::prepare_volumes

makisu_args=${@:1:$#-1}
echo "Starting Makisu: makisu $makisu_args /context"
chroot $CHROOT/ /makisu-internal/makisu $makisu_args /context

0 comments on commit 41c2c6d

Please sign in to comment.