sh: Execute micobu.sh instead of generating own script

This commit is contained in:
Markus Koch 2022-01-21 20:35:56 +01:00
parent 32c7ec2912
commit f9d58f334f

View File

@ -6,12 +6,13 @@
ROOTFS_BASE='/opt/micobu/rootfs'
ROOTFS_DIR='/home/builduser/base' # in rootfs
BUILD_BASE=$ROOTFS_BASE$ROOTFS_DIR
ARTEFACT_BASE='/opt/micobu/rootfs/home/builduser/artefacts'
BUILD_TIMEOUT='600'
API_KEY='mykey'
SERVER_PIPE='/var/tmp/micobu_pipe'
BUILD_BASE=$ROOTFS_BASE$ROOTFS_DIR
function build() {
NAME="$1"
REPO="$2"
@ -19,7 +20,7 @@ function build() {
BUILD_DIR="$BUILD_BASE/$NAME"
ARTEFACT_DIR="$ARTEFACT_BASE/$NAME/$HASH"
MICOBU_TEMP_NAME="micobu_$NAME_$HASH" # Relative to $BUILD_BASE
MICOBU_TEMP_NAME="$NAME/micobu_$HASH" # Relative to $BUILD_BASE
if [ -d "$ARTEFACT_DIR" ]; then
echo "$NAME revision $HASH has already been built."
@ -44,34 +45,22 @@ function build() {
git reset --hard
git checkout $HASH
DESCRIPTION="`git describe --all`"
DESCRIPTION="`git describe --all --always`"
mkdir -p $BUILD_BASE/$MICOBU_TEMP_NAME
cat <<EOF > $BUILD_BASE/micobu_run.sh
#!/bin/bash
cd ~/$NAME
./run.py --no-color
RET=\$?
cd vunit_out/test_output
tar cvJf ~/$MICOBU_TEMP_NAME/artefacts.tar.xz *
exit \$RET
EOF
chmod +x $BUILD_BASE/micobu_run.sh
mkdir -p $ARTEFACT_DIR
echo "[sec] Creating jail"
META_DATE_START="`date '+%s'`"
set +e
set -o pipefail
firejail --noprofile --chroot=$ROOTFS_BASE --net=none --read-write="$BUILD_BASE" env -i HOME=$ROOTFS_DIR PATH=/bin:/usr/bin "bash" "-c" "timeout $BUILD_TIMEOUT ~/micobu_run.sh" | tee $BUILD_BASE/$MICOBU_TEMP_NAME/log.txt
firejail --noprofile --chroot=$ROOTFS_BASE --net=none --read-write="$BUILD_BASE/" env -i HOME=$ROOTFS_DIR/$NAME PATH=/bin:/usr/bin MCB_NAME=$NAME MCB_ARTEFACTS=$ROOTFS_DIR/$MICOBU_TEMP_NAME "bash" "-c" "cd ~; timeout $BUILD_TIMEOUT ~/micobu.sh" | tee $ARTEFACT_DIR/log.txt
RET=$?
set +o pipefail
set -e
META_DATE_STOP="`date '+%s'`"
rm $BUILD_BASE/micobu_run.sh
cat <<EOF > $BUILD_BASE/$MICOBU_TEMP_NAME/meta.json
cat <<EOF > $ARTEFACT_DIR/meta.json
{
"name" : "$NAME",
"url" : "$REPO",
@ -83,11 +72,16 @@ EOF
}
EOF
mkdir -p $ARTEFACT_DIR
mv -T $BUILD_BASE/$MICOBU_TEMP_NAME $ARTEFACT_DIR
cd $BUILD_BASE/$MICOBU_TEMP_NAME
if [ "`ls`" == "" ]; then
echo "No artefacts generated."
else
tar cvJf $ARTEFACT_DIR/artefacts.tar.xz *
echo "Stored artefacts in $ARTEFACT_DIR"
find $ARTEFACT_DIR
fi
find $ARTEFACT_BASE
cd $ARTEFACT_DIR
cat $ARTEFACT_DIR/meta.json
echo ""