bastilimbach / docker-MagicMirror

Docker image for the Magic Mirror 2 project by Michael Teeuw.
https://hub.docker.com/r/bastilimbach/docker-magicmirror/
MIT License
185 stars 54 forks source link

Change source image to node:lts-alpine. Closes #13 #18

Closed xbgmsharp closed 5 years ago

xbgmsharp commented 5 years ago

Update source image to node-lts from Alpine to have slimmer docker image, less than 400MB. Update entrypoint to check for valid directory #13

PS: Image node-lts from Alpine supports multiple architecture including raspberrypi as image hypriot/rpi-node:latest is no longer maintained.

bastilimbach commented 5 years ago

Thanks for your PR! 🎉 If I understand it correctly, this makes the raspberry pi Dockerfile unnecessary right? If that is the case we should delete it and update the travis ci config.

I'll take a look this evening.

xbgmsharp commented 5 years ago

Correct the raspberry pi Dockerfile is unnecessary. It also ensure we stay on NodeJS LTS.

xbgmsharp commented 5 years ago

Deleted the raspberry Dockerfile via 9bc67b8 Updated the travis ci config via ad132b6 Updated README via d9ab3f6

xbgmsharp commented 5 years ago

Added multi arch (x64,arm) environment via 0b664e9

bastilimbach commented 5 years ago

Thanks, @xbgmsharp for your great work! I just tested it locally and it looks very promising. Travis is probably failing because the "--platform" flag of the docker build command is experimental and not yet available in the docker version which Travis is using to build images. Maybe we can change the internal docker version somehow.

One question which came into my mind was if we still really need the entrypoint.sh file. It was introduced for the following use case:

If the user runs the docker image as a container, the shell script should look if there are already modules or configs present in the mounted folders. If this is the case, we do not want to override them with the default config/modules. But if the mounted folders are empty we want to copy the default content of theses from the magic mirror repository.

I just double checked this use case and I think Docker already provides this mechanism out of the box. I commented out the ENTRYPOINT from the Dockerfile and build a container. As soon as I started the container it created the folders on my host with the default modules and config. I then changed and added some files and deleted the container again. On my second run, these custom files weren't replaced.

If I'm not completely wrong, this is the expected outcome which should also fix #13. What do you think?

bastilimbach commented 5 years ago

I just had a quick read on the topic of building arm based images on x86 based systems again. It seems that Docker for Mac has binfmt_misc support built-in which makes it possible to build this image locally on my MacBook. (Reference)

To build arm based images on Linux, which Travis CI is using, it is a bit trickier as you need to manually set up binfmt_misc. Therefore I added the following to the script block to the .travis.yml file:

docker run --rm --privileged multiarch/qemu-user-static:register

The image multiarch/qemu-user-static does all the hard work for us.

Could you try adding this line again to see if the build works on travis?

xbgmsharp commented 5 years ago

The PR took care of the x86_64 image generated by Docker Hub for us. docker pull bastilimbach/docker-MagicMirror

The other images (Arm32v7 and Arm64v8) so far have to be built at home with your own devices. docker build -t bastilimbach/docker-MagicMirror github.com/bastilimbach/docker-MagicMirror.git

However Docker is multi-architecture, eg: amd64, armhf, arm64 and the Docker image node:lts-alpine image is multi-architecture. https://github.com/docker-library/official-images#architectures-other-than-amd64 https://github.com/nodejs/docker-node#nodealpine

To use Docker HUB multi architectures, you need a proper manifest so you can use the main tags directly (no need for amd64-X.X.X). https://blog.slucas.fr/blog/docker-multiarch-manifest-hub-2/ https://lobradov.github.io/Building-docker-multiarch-images/ https://stackoverflow.com/questions/47994152/how-to-automate-multi-arch-docker-image-builds

Then we need to automated the process using Travis CI.

xbgmsharp commented 5 years ago

I don't understand how the command docker run --rm --privileged multiarch/qemu-user-static:register --reset make you on arm architecture. In both case the arch is still x86_64 https://travis-ci.org/bastilimbach/docker-MagicMirror/jobs/503042203

# ./manifest-tool inspect node | grep -i arch
1           -    Arch: amd64
2           -    Arch: arm
3           -    Arch: arm64
4           -    Arch: ppc64le
5           -    Arch: s390x
# docker run --rm mplatform/mquery node:lts-alpine
Image: node:lts-alpine
 * Manifest List: Yes
 * Supported platforms:
   - linux/amd64
   - linux/arm/v6
   - linux/arm64
   - linux/386
   - linux/ppc64le
   - linux/s390x
xbgmsharp commented 5 years ago

Update README Add new architecture i386 and arm64v8/aarch64 Fix multi arch arm32v6,arm32v7 (Raspberry Pi) Travis CI Job under 10 minutes

manifest-tool won't run due a lack of permission. All images must be push before. https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504448669#L729 https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504448669#L870

docker build --build-arg ARCH=amd64 --build-arg QEMU_BIN=qemu-amd64-static -t bastilimbach/docker-magicmirror:amd64 .
Successfully tagged bastilimbach/docker-magicmirror:amd64

docker build --build-arg ARCH=arm32v6 --build-arg QEMU_BIN=qemu-arm-static -t bastilimbach/docker-magicmirror:arm32v6 .
Successfully tagged bastilimbach/docker-magicmirror:arm32v6

docker build --build-arg ARCH=arm32v7 --build-arg QEMU_BIN=qemu-arm-static -t bastilimbach/docker-magicmirror:arm32v7 .
arm32v7/node:lts-alpine not found

docker build --build-arg ARCH=arm64v8 --build-arg QEMU_BIN=qemu-aarch64-static -t bastilimbach/docker-magicmirror:arm64v8 .
Successfully tagged bastilimbach/docker-magicmirror:arm64v8

docker build --build-arg ARCH=i386 --build-arg QEMU_BIN=qemu-i386-static -t bastilimbach/docker-magicmirror:i386 .
Successfully tagged bastilimbach/docker-magicmirror:i386
xbgmsharp commented 5 years ago

Finally!

(build.sh)

(.travis.yml)

+docker build --build-arg ARCH=amd64 --build-arg QEMU_BIN=qemu-amd64-static -t bastilimbach/docker-magicmirror:amd64 .
...
Successfully tagged bastilimbach/docker-magicmirror:amd64

https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504628199#L605

+docker build --build-arg ARCH=arm32v6 --build-arg QEMU_BIN=qemu-arm-static -t bastilimbach/docker-magicmirror:arm32v6 .
...
Successfully tagged bastilimbach/docker-magicmirror:arm32v6

https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504628199#L695

+docker build --build-arg ARCH=arm64v8 --build-arg QEMU_BIN=qemu-aarch64-static -t bastilimbach/docker-magicmirror:arm64v8 .
...
Successfully tagged bastilimbach/docker-magicmirror:arm64v8

https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504628199#L785

+docker build --build-arg ARCH=i386 --build-arg QEMU_BIN=qemu-i386-static -t bastilimbach/docker-magicmirror:i386 .
...
Successfully tagged bastilimbach/docker-magicmirror:i386

https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504628199#L874

All images

+docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
bastilimbach/docker-magicmirror   i386                f5b96d6a601e        1 second ago        380MB
bastilimbach/docker-magicmirror   arm64v8             d94e32a59f61        48 seconds ago      365MB
bastilimbach/docker-magicmirror   arm32v6             f3007783a61b        3 minutes ago       328MB
bastilimbach/docker-magicmirror   amd64               e1e1b5381a8a        6 minutes ago       369MB

https://travis-ci.org/bastilimbach/docker-MagicMirror/builds/504628199#L919

bastilimbach commented 5 years ago

Wow this is a lot. I take a look at this on weekend to really understand what you are doing here. 👍

xbgmsharp commented 5 years ago

Sure no problem. I you like we can close this PR and i create a new clean PR.

sthuber90 commented 4 years ago

Seems like this PR never made it to master. Can we get an alpine or generally smaller images? On my amd64 the image is roughly 1 GB

xbgmsharp commented 4 years ago

The project was fork and is available at https://github.com/xbgmsharp/docker-MagicMirror/ and https://hub.docker.com/r/xbgmsharp/docker-magicmirror

sthuber90 commented 4 years ago

Thank you, but as this is the somewhat "official" image, I am wondering why we shouldn't have smaller docker images available here. Personally dislike to have a community around MagicMirror where everybody in the end is doing their own thing, instead of collaborating on getting the best version of one MagicMirror Docker solution. Just my personal thoughts.

bastilimbach commented 4 years ago

@sthuber90 Yes I totally agree with you on that. I created issue #44 to tackle this. Maybe you can help here :)