Skip to content

Instantly share code, notes, and snippets.

@roman-mazur
Last active July 11, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roman-mazur/4ab90dcfc8e4f8a38f8809f1809d0f8b to your computer and use it in GitHub Desktop.
Save roman-mazur/4ab90dcfc8e4f8a38f8809f1809d0f8b to your computer and use it in GitHub Desktop.
Docker image with environment suitable for building balena OS

Building with yocto inside of a docker container

  • Build the image described in Dockerfile here:
docker build -t build-yocto .
  • Create a volume that will store build data.
docker create volume yoctovolume
  • Make enter-yocto available in you PATH, and run
enter-yocto
  • Now you inside of docker container, current directory is /balena-yocto-build. Clone your repo and start building, and /balena-yocto-build content will be stored acrosss multiple container runs.

Please note that if you change image and volume names, you have to modify enter-yocto script too.

On MacOS, you may need to adjust Docker settings to give it access to more CPU, memory, and disk.

FROM gmacario/build-yocto
# Install extra tools for balena build.
RUN sudo apt-get update && sudo apt-get -y install \
nodejs \
npm \
jq \
iptables
# Install docker.
RUN sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
RUN sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
RUN sudo apt-get update && sudo apt-get -y install docker-ce-cli
RUN sudo groupadd docker && sudo usermod -a -G docker build
COPY entry.sh /entry.sh
ENTRYPOINT [ "/bin/bash", "/entry.sh" ]
#!/usr/bin/env bash
VOLUME_NAME=yoctovolume
if ! [[ -z $1 ]]; then
VOLUME_NAME=$1
fi
docker inspect $VOLUME_NAME > /dev/null 2>/dev/null || (echo "Volume $VOLUME_NAME is not found!" && exit 1)
echo "Using $VOLUME_NAME volume..."
DOCKER_SOCKET_PATH=/var/run/docker.sock
WORKDIR_SLUG="balena-yocto-build"
CONTAINER_WORKDIR=/${WORKDIR_SLUG}
docker run -it --rm \
-v ${VOLUME_NAME}:${CONTAINER_WORKDIR} \
-w=${CONTAINER_WORKDIR} \
-v ${DOCKER_SOCKET_PATH}:${DOCKER_SOCKET_PATH} \
-e "BUILD_DOCKER_SHARED_VOLUME=${VOLUME_NAME}" \
-e "BUILD_DOCKER_SHARED_VOLUME_MOUNT_PATH=${CONTAINER_WORKDIR}" \
-e "BB_ENV_EXTRAWHITE=BUILD_DOCKER_SHARED_VOLUME BUILD_DOCKER_SHARED_VOLUME_MOUNT_PATH" \
build-yocto
sudo chown root:docker /var/run/docker.sock
/bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment