Skip to content

Instantly share code, notes, and snippets.

@trinitronx
Last active March 12, 2017 04:10
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 trinitronx/7a0d24557c01aca54608e907bfe6f713 to your computer and use it in GitHub Desktop.
Save trinitronx/7a0d24557c01aca54608e907bfe6f713 to your computer and use it in GitHub Desktop.
ResinOS bitbake hack to get docker-custom-disk to build inside a docker-in-docker container (blank disk img)
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export WORKDIR=/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0/
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export TARGET_REPOSITORY=${SUPERVISOR_REPOSITORY}
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export TARGET_TAG=v3.0.1
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export SUPERVISOR_REPOSITORY="resin/armv7hf-supervisor"
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export WORKDIR=/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0/
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export SUPERVISOR_REPOSITORY="resin/armv7hf-supervisor"
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export TARGET_REPOSITORY=${SUPERVISOR_REPOSITORY}
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export TARGET_TAG=v3.0.1
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ export PARTITION_SIZE="1024"
bitbake@9854c74a3bbb:/src/resin-raspberrypi$ cd $WORKDIR
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ losetup -f
/dev/loop0
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ docker build -t looper -f ${WORKDIR}/Dockerfile ${WORKDIR}
Sending build context to Docker daemon 2.148 GB
Step 1 : FROM docker:1.10.3-dind
---> 305c151749f4
Step 2 : RUN apk add --update bash util-linux && rm -rf /var/cache/apk/*
---> Using cache
---> 8f0e31a2fa40
Step 3 : ADD entry.sh /entry.sh
---> Using cache
---> 20dd9eea5272
Step 4 : RUN chmod a+x /entry.sh
---> Using cache
---> 416da0fcd711
Step 5 : CMD /entry.sh
---> Using cache
---> cda7b9a28877
Successfully built cda7b9a28877
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ docker run --rm --privileged -e PARTITION_SIZE=${PARTITION_SIZE} -e TARGET_REPOSITORY=${TARGET_REPOSITORY} -e TARGET_TAG=${TARGET_TAG} -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v ${B}:/export looper
0+0 records in
0+0 records out
mke2fs 1.43 (17-May-2016)
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 131072 inodes
Filesystem UUID: 46533ed2-58eb-4e67-9065-5934b21bdd15
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
Waiting for docker to become ready..
time="2017-03-11T23:55:15.920041169Z" level=fatal msg="Error starting daemon: error initializing graphdriver: driver not supported"
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ ls -l /export
total 724
-rw-r--r--. 1 root root 1073741824 Mar 11 23:55 resin-data.img
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ ls -l /data_disk/
total 0
## Now run fix interactively so we can avoid the docker daemon start...
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ docker run -ti --entrypoint=/bin/bash --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -e PARTITION_SIZE=${PARTITION_SIZE} -e TARGET_REPOSITORY=${TARGET_REPOSITORY} -e TARGET_TAG=${TARGET_TAG} -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v ${B}:/export looper
bash-4.3#
bash-4.3# sed -i -e 's/\(docker daemon.*\)/#\1/' entry.sh
bash-4.3#
bash-4.3# bash -x entry.sh
+ set -o errexit
+ set -o nounset
+ DOCKER_TIMEOUT=20
+ PARTITION_SIZE=1024
+ dd if=/dev/zero of=/export/resin-data.img bs=1M count=0 seek=1024
0+0 records in
0+0 records out
+ mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 -i 8192 -F /export/resin-data.img
mke2fs 1.43 (17-May-2016)
/export/resin-data.img contains a ext4 file system
last mounted on Sun Mar 12 00:02:04 2017
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 131072 inodes
Filesystem UUID: f0a36995-76c7-462c-92ee-272ae1ffeeda
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
+ mkdir /resin-data
+ mount -o loop /export/resin-data.img /resin-data
+ mkdir -p /resin-data/docker
+ mkdir -p /resin-data/resin-data
+ echo 'Waiting for docker to become ready..'
Waiting for docker to become ready..
++ date +%s
+ STARTTIME=1489276974
++ date +%s
+ ENDTIME=1489276974
+ '[' '!' -S /var/run/docker.sock ']'
+ '[' -n resin/armv7hf-supervisor ']'
+ '[' -n v3.0.1 ']'
+ docker pull resin/armv7hf-supervisor:v3.0.1
v3.0.1: Pulling from resin/armv7hf-supervisor
3cd6617dce80: Already exists
a3ed95caeb02: Already exists
f1a066da4710: Already exists
ca87fd050229: Already exists
9c21ab1d6cac: Already exists
2c87582e7ef0: Already exists
Digest: sha256:907d5414792cda7e4b63b1cd12457e81c04705f339d59372bc3baca5c8dd0b1e
Status: Image is up to date for resin/armv7hf-supervisor:v3.0.1
+ docker tag resin/armv7hf-supervisor:v3.0.1 resin/armv7hf-supervisor:latest
++ cat /var/run/docker.pid
cat: can't open '/var/run/docker.pid': No such file or directory
+ kill -TERM
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
+ echo 'Docker export successful.'
Docker export successful.
bash-4.3#
bash-4.3# ls /export/resin-data.img
/export/resin-data.img
bash-4.3# exit
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ cp /export/resin-data.img /src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0
bitbake@9854c74a3bbb:/src/resin-raspberrypi/build/tmp/work/raspberrypi3-poky-linux-gnueabi/docker-custom-disk/1.0-r0$ ls
deploy-docker-custom-disk Dockerfile license-destdir patches resin-data.img sstate-build-packagedata sstate-build-populate_lic temp
deploy-rpms entry.sh package pkgdata sstate-build-deploy sstate-build-package_qa sstate-build-populate_sysroot
docker-custom-disk.spec image packages-split pseudo sstate-build-package sstate-build-package_write_rpm sysroot-destdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment