Switch back to cross-build

If you do not wish to cross build on your local, you can comment out the
cross-build lines and run.

Hacky way of making it easy to run on ARM

Just prefix any make command with 'arm'. Eg. `make arm shell'.
Don't commit the modified Makefile.

Update Readme
This commit is contained in:
ViViDboarder 2017-11-20 11:04:27 -08:00
parent aa7d331fac
commit 6e72221171
3 changed files with 46 additions and 7 deletions

View File

@ -1,7 +1,7 @@
FROM hypriot/rpi-node:8 FROM hypriot/rpi-node:8
MAINTAINER ViViDboarder <vividboarder@gmail.com> MAINTAINER ViViDboarder <vividboarder@gmail.com>
RUN cross-build-start || true RUN [ "cross-build-start" ]
ENV LANG en_US.UTF-8 ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8 ENV LC_ALL en_US.UTF-8
@ -34,7 +34,7 @@ RUN [ -s npm-shrinkwrap.json ] || rm npm-shrinkwrap.json
RUN npm install RUN npm install
RUN cross-build-end || true RUN [ "cross-build-end" ]
EXPOSE 5353 51826 EXPOSE 5353 51826

View File

@ -3,13 +3,16 @@ DOCKER_TAG ?= rpi-homebridge
DOCKER_TAG_DEV ?= $(DOCKER_TAG)-dev DOCKER_TAG_DEV ?= $(DOCKER_TAG)-dev
HOMEBRIDGE_USER ?= root HOMEBRIDGE_USER ?= root
.PHONY: default
default: build default: build
# Default target to build the image # Default target to build the image
.PHONY: build
build: build:
docker build -t $(DOCKER_TAG_DEV) . docker build -t $(DOCKER_TAG_DEV) .
# Target to build and run and subsequently remove image # Target to build and run and subsequently remove image
.PHONY: run
run: build run: build
docker run --net=host --rm \ docker run --net=host --rm \
-p "51826:51826" \ -p "51826:51826" \
@ -18,31 +21,44 @@ run: build
$(DOCKER_TAG_DEV) $(DOCKER_TAG_DEV)
# Target to drop into an interractive shell # Target to drop into an interractive shell
.PHONY: shell
shell: build shell: build
docker run --net=host --rm \ docker run --net=host --rm \
-p "51826:51826" \ -p "51826:51826" \
-v "$(shell pwd)/config.json:/$(HOMEBRIDGE_USER)/.homebridge/config.json" \ -v "$(shell pwd)/config.json:/$(HOMEBRIDGE_USER)/.homebridge/config.json" \
-v "$(shell pwd)/plugins.txt:/$(HOMEBRIDGE_USER)/.homebridge/plugins.txt" \ -v "$(shell pwd)/plugins.txt:/$(HOMEBRIDGE_USER)/.homebridge/plugins.txt" \
$(shell grep -q '^RUN.*cross-build-start' Dockerfile && echo '-v "/usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static"') \
-it $(DOCKER_TAG_DEV) \ -it $(DOCKER_TAG_DEV) \
bash bash
# Tags dev image so it can be pushed # Tags dev image so it can be pushed
.PHONY: tag
tag: build tag: build
docker tag $(DOCKER_TAG_DEV) $(DOCKER_REPO)/$(DOCKER_TAG) docker tag $(DOCKER_TAG_DEV) $(DOCKER_REPO)/$(DOCKER_TAG)
# Pushes tagged image to docker hub # Pushes tagged image to docker hub
.PHONY: push
push: tag push: tag
docker push $(DOCKER_REPO)/$(DOCKER_TAG) docker push $(DOCKER_REPO)/$(DOCKER_TAG)
# Clears shrinkwrap so next build will install latest version of everything # Clears shrinkwrap so next build will install latest version of everything
.PHONY: unshrinkwrap
unshrinkwrap: unshrinkwrap:
rm ./npm-shrinkwrap.json rm ./npm-shrinkwrap.json
touch ./npm-shrinkwrap.json touch ./npm-shrinkwrap.json
# Generates a new shrinkwrap from installed node modules # Generates a new shrinkwrap from installed node modules
.PHONY: shrinkwrap
shrinkwrap: build shrinkwrap: build
docker run --rm \ docker run --rm \
-v "$(shell pwd)/npm-shrinkwrap.json:/homebridge/npm-shrinkwrap-volume.json" \ -v "$(shell pwd)/npm-shrinkwrap.json:/homebridge/npm-shrinkwrap-volume.json" \
$(shell grep -q '^RUN.*cross-build-start' Dockerfile && echo '-v "/usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static"') \
$(DOCKER_TAG_DEV) \ $(DOCKER_TAG_DEV) \
bash -c "npm shrinkwrap && cat npm-shrinkwrap.json > npm-shrinkwrap-volume.json" bash -c "npm shrinkwrap && cat npm-shrinkwrap.json > npm-shrinkwrap-volume.json"
# Converts Dockerfile so that it can compile on ARM
.PHONY: arm
arm:
cat Dockerfile | sed '/^RUN.*cross-build-/s/^/# /' > Dockerfile.arm
mv Dockerfile.arm Dockerfile

View File

@ -34,7 +34,30 @@ make run # builds and runs container using same parameters as compose
make shell # builds and runs an interractive container make shell # builds and runs an interractive container
make tag # tags image to be pushed to docker hub make tag # tags image to be pushed to docker hub
make push # pushes image to docker hub make push # pushes image to docker hub
make unshrinkwrap # clears npm-shrinkwrap.json so the next build will use latest
make shrinkwrap # generates npm-shrinkwrap.json to pin versions
make arm # modifies Dockerfile for building against arm
``` ```
## Multi-arch
This project is capable of being compiled on arm or cross-built on an x86 machine. There is some trickiness involved in this, so here's the description broken down by platform. High level, the `cross-build-start` cannot be present when building on arm. When running the built image, a non-arm system needs to have `qemu-arm-static` mounted as a volume. The `Makefile` tries to automate this a bit.
### arm (Raspberry Pi)
The default is to support building on Docker Hub and not a Raspberry Pi. Unfortunately, `cross-build-start` will fail to run on an arm machine.
To build or shrinkwrap, just add `arm` to your make command. Eg. `make arm build shrinkwrap`. This will modify the `Dockerfile` to comment out the cross-build commands. If contributing changes back upstream, do not commit this change!
### Linux x86
Building can be done by directly running `make build`. If you want to run image, you need to install `qemu qemu-user qemu-user-static`. After that you should be able to run `make shrinkwrap or make shell`.
### macOS
Docker for Mac actually supports running arm binaries. So that's cool! To make things simple, you should follow the arm instructions.
## Development
Follow the instructions above for how to run on your architechture. Also, be sure to not commit commented out `cross-build-*` lines as those are necessary for Docker Hub to build.
### Bumping version numbers
This is most easily done by updating `package.json` and then running `make unshrinkwrap shrinkwrap`. That should force a reinstallation of all node packages and then provide you with an updated `npm-shrinkwrap.json` file to commit.
## Issues? ## Issues?
Feel free to report any issues you're having getting this to run on [Github](https://github.com/ViViDboarder/docker-rpi-homebridge/issues) Feel free to report any issues you're having getting this to run on [Github](https://github.com/ViViDboarder/docker-rpi-homebridge/issues)