-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathMakefile.example
64 lines (49 loc) · 2.13 KB
/
Makefile.example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Example makefile demonstrating the use of the emulated container to prepare a build environment
# This makefile is standalone, and can be used as the basis of projects that build applications or images for the RPi
DATE=2016-05-27
DIST=$(DATE)-raspbian-jessie-lite
ZIP=$(DIST).zip
IMAGE=$(DIST).img
PATH=http://vx2-downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2016-05-31/$(ZIP)
CWD=$(shell pwd)
# Docker run arguments
# Container must run in privileged mode to allow binding of loopback interfaces
RUN_ARGS=-it --rm --privileged=true -v $(CWD)/images:/usr/rpi/images -v $(CWD)/resources:/usr/rpi/resources -w /usr/rpi ryankurte/docker-rpi-emu
# Internal container mount directory
MOUNT_DIR=/media/rpi
# Build the docker image
pull:
@docker pull ryankurte/docker-rpi-emu
# Bootstrap a RPI image into the images directory
bootstrap: images/$(IMAGE)
# Fetch the RPI image from the path above
images/$(IMAGE):
@mkdir -p images
@wget -O images/$(ZIP) -c $(PATH)
@unzip -d images/ images/$(ZIP)
@touch $@
# Launch the docker image without running any of the utility scripts
run: pull bootstrap
@docker run $(RUN_ARGS) /bin/bash
# Launch the docker image into an emulated session
run-emu: pull bootstrap
@docker run $(RUN_ARGS) /bin/bash -c './run.sh images/$(IMAGE)'
# Build some fake resources to copy / execute
resources: resources/setup.sh
resources/setup.sh:
@mkdir -p resources
@echo "#!/bin/bash" > resources/setup.sh
@echo "echo Executing example setup script" >> resources/setup.sh
@echo "uname -a" >> resources/setup.sh
@chmod +x resources/setup.sh
# Copy files from local resources directory into image /usr/resources
# Note that the resources directory is mapped to the container as a volume in the RUN_ARGS variable above
copy: pull bootstrap resources
@echo Copying files
@docker run $(RUN_ARGS) /bin/bash -c 'mkdir $(MOUNT_DIR) && \
./mount.sh images/$(IMAGE) $(MOUNT_DIR) && \
cp -Rv /usr/rpi/resources $(MOUNT_DIR)/usr/; \
./unmount.sh $(MOUNT_DIR)'
# Run a command inside the qemu environment
setup: copy
@docker run $(RUN_ARGS) /bin/bash -c './run.sh images/$(IMAGE) /usr/resources/setup.sh'