From 354b745c39a19915c3a8547445a5049555bd37ff Mon Sep 17 00:00:00 2001 From: Sebastian Limbach Date: Tue, 31 Jan 2017 11:41:40 +0100 Subject: [PATCH] Added Docker support --- .dockerignore | 72 ++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 +- Dockerfile | 15 +++++++++ README.md | 22 +++++++++++++- docker-entrypoint.sh | 11 +++++++ js/defaults.js | 2 +- 6 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..3b40663030 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,72 @@ +# Various Node ignoramuses. + +logs +*.log +npm-debug.log* +pids +*.pid +*.seed +lib-cov +coverage +.grunt +.lock-wscript +build/Release +node_modules +jspm_modules +.npm +.node_repl_history + +# Various Windows ignoramuses. +Thumbs.db +ehthumbs.db +Desktop.ini +$RECYCLE.BIN/ +*.cab +*.msi +*.msm +*.msp +*.lnk + +# Various OSX ignoramuses. +.DS_Store +.AppleDouble +.LSOverride +Icon +._* +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Various Linux ignoramuses. + +.fuse_hidden* +.directory +.Trash-* + +# Various Magic Mirror ignoramuses and anti-ignoramuses. + +# Don't ignore the node_helper core module. +!/modules/node_helper +!/modules/node_helper/** + +# Ignore all modules except the default modules. +/modules/** +!/modules/default/** + +# Ignore changes to the custom css files. +/css/custom.css + +# Ignore unnecessary files for docker +CHANGELOG.md +LICENSE.md +README.md +Gruntfile.js +.* diff --git a/.gitignore b/.gitignore index 67feae5409..b8935c9317 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,7 @@ Temporary Items # Various Magic Mirror ignoramuses and anti-ignoramuses. -# Don't ignore the node_helper nore module. +# Don't ignore the node_helper core module. !/modules/node_helper !/modules/node_helper/** diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..d845bac0f4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:latest + +WORKDIR /opt/magic_mirror +COPY . . +COPY /modules unmount_modules +COPY /config unmount_config + +ENV NODE_ENV production +ENV MM_PORT 8080 + +RUN npm install +RUN ["chmod", "+x", "docker-entrypoint.sh"] + +EXPOSE $MM_PORT +ENTRYPOINT ["/opt/magic_mirror/docker-entrypoint.sh"] diff --git a/README.md b/README.md index 7c5286ddb4..4fb1fce50c 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,28 @@ curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installer **Note:** if you want to debug on Raspberry Pi you can use `npm start dev` which will start the MagicMirror app with Dev Tools enabled. ### Server Only +In some cases, you want to start the application without an actual app window. In this case, you can start MagicMirror² in server only mode. This will start the server, after which you can open the application in your browser of choice. -In some cases, you want to start the application without an actual app window. In this case, execute the following command from the MagicMirror folder: `node serveronly`. This will start the server, after which you can open the application in your browser of choice. +#### Docker + +The simplest way to start MagicMirror² in server only mode is using [Docker](https://docker.com). After a successful [Docker installation](https://docs.docker.com/engine/installation/) you just need to execute the following command in the shell: + +```bash +docker run -d \ + --publish 80:8080 \ + --restart always \ + --volume ~/Documents/docker_volumes/mm/config:/opt/magic_mirror/config \ + --volume ~/Documents/docker_volumes/mm/modules:/opt/magic_mirror/modules \ + --name magic_mirror \ + magic_mirror +``` + +#### Manual + +1. Download and install the latest Node.js version. +2. Clone the repository and check out the beta branch: `git clone https://github.com/MichMich/MagicMirror` +3. Enter the repository: `cd ~/MagicMirror` +4. Install and run the app: `node serveronly` ### Raspberry Configuration & Auto Start. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000000..9d91492f0a --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ ! -f /opt/magic_mirror/modules ]; then + cp -R /opt/magic_mirror/unmount_modules/. /opt/magic_mirror/modules +fi + +if [ ! -f /opt/magic_mirror/config ]; then + cp -R /opt/magic_mirror/unmount_config/. /opt/magic_mirror/config +fi + +node serveronly diff --git a/js/defaults.js b/js/defaults.js index 4639e2b3b5..677edc98ac 100644 --- a/js/defaults.js +++ b/js/defaults.js @@ -8,7 +8,7 @@ */ var defaults = { - port: 8080, + port: process.env.MM_PORT || 8080, kioskmode: false, electronOptions: {}, ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],