From 8262f3ac0fc77f40fc5bf2fc97da021d4e564f39 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Fri, 28 Oct 2016 13:25:27 -0500 Subject: [PATCH] containerize script for a Yocto build env The containerize script fetches down a Docker container and wires up the current directory inside so that you can use a known good environment for compiling Yocto that has all the dependencies. Signed-off-by: Doug Goldstein --- scripts/containerize.sh | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 scripts/containerize.sh diff --git a/scripts/containerize.sh b/scripts/containerize.sh new file mode 100755 index 0000000..c9ac0db --- /dev/null +++ b/scripts/containerize.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# what container are we using to build this +CONTAINER="starlabio/yocto:1.5" + +einfo() { + echo "$*" >&2 +} + +die() { + echo "$*" >&2 + exit 1 +} + +# Save the commands for future use +cmd=$@ + +# If no command was specified, just drop us into a shell if we're interactive +[ $# -eq 0 ] && tty -s && cmd="/bin/bash" + +# user and group we are running as to ensure files created inside +# the container retain the same permissions +my_uid=$(id -u) +my_gid=$(id -g) + +# Are we in an interactive terminal? +tty -s && termint=t + +# Fetch the latest version of the container +einfo "*** Ensuring local container is up to date" +docker pull ${CONTAINER} > /dev/null || die "Failed to update docker container" + +# Ensure we've got what we need for SSH_AUTH_SOCK +if [[ -n ${SSH_AUTH_SOCK} ]]; then + SSH_AUTH_DIR=$(dirname $(readlink -f ${SSH_AUTH_SOCK})) + SSH_AUTH_NAME=$(basename ${SSH_AUTH_SOCK}) +fi + +# Kick off Docker +einfo "*** Launching container ..." +exec docker run \ + --privileged \ + -e BUILD_UID=${my_uid} \ + -e BUILD_GID=${my_gid} \ + -e TEMPLATECONF=meta-rust/conf \ + -e MACHINE=${MACHINE:-qemux86} \ + ${SSH_AUTH_SOCK:+-e SSH_AUTH_SOCK="/tmp/ssh-agent/${SSH_AUTH_NAME}"} \ + -v ${HOME}/.ssh:/var/build/.ssh \ + -v "${PWD}":/var/build:rw \ + ${SSH_AUTH_SOCK:+-v "${SSH_AUTH_DIR}":/tmp/ssh-agent} \ + ${EXTRA_CONTAINER_ARGS} \ + -${termint}i --rm -- \ + ${CONTAINER} \ + ${cmd}