├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── unifi-video ├── Dockerfile ├── Makefile ├── README.md ├── mock_test.sh └── start.sh └── unifi ├── Dockerfile ├── Makefile ├── mock_test.sh ├── mongo_prune_js.js └── start.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # vim files 36 | *~ 37 | .*~ 38 | .*.swp 39 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: bash 2 | sudo: required 3 | 4 | env: 5 | global: 6 | - secure: "tJ8w+API6tv7Yqg6wnyRPBxMNwrZQURrYsMAyJ7dsr+M0ssGKPiQsy83ccIvDDibEYXk/5OXonjRzsyCJqqzkXYbkQD9voeTEdqec1AT8UikquzvEZCG33Sqg3oUEuAD44nPNkUTx+OqVnTfrfstc6x+fXDUf96F9pC3J4O9tvJulCC7eIhQq98Vxp4KDhQHsKWCKxYEnXZfKMExLoUFNKbGJxOJLgYtb+S4wxxolvYOkcE7OtTXpCcqWymSyAdjtUGn5TmK3DD3PIqDVT/y4CUPSZJunaHpwE4U8JHpDAGuKwUgRodveS2p9deANBeKkmv+aKSrjgO19OELObqQ9zmPWix9TlWPTg1j197g0+LC+aPkbw/B7hqyjJW/CrqScPu6duu+KYBsYKU3/Z5C9WpO4AlonJSHomWXRMbtcAXe2GLI6Rym1nIvp6WrhR/5RjA4nKnc6/D+dbWS4czncLl3ReRJwVYw+2qVV6wFSYR/1nAKAY2FMXntFeNdHNd47FTg0Po3X0v26Zeir/oAZeVH3OD0WR3Uhv8o9Qir5HL3SMmKxzMNEVbqIzSZVFOZGobtjEWX6ljCI0PZwyLHOwDeUa3LRCsYTeI4KNrinSiE7q4nhhKRLHeJq0wnOPEQiQ8RiHhlBfNI0WR5UG2mkqTNf8Nv5DNhHbNclN5aot0=" # DOCKER_USER 7 | - secure: "iLt6yiQiNWDtloDUEUl3yK3y9GkcY5763AuzcizmksBNny3ioFUYYfNkKJrHSOLi+K/Lme9Mv4sMiZyFv2bIlZRhKWakA3MaWzPp6POSFl3Fd9Z8aNvDzT7p11HWgcZZUx6urtvbIyeXFCaOOKTt3S7g1AU5hbRj/MdYlCVh8hk8FIAImqzzcMVm5571j7zeC43VSF5Ggpk93yECP3G59ANrPXo8hHHdNJpxFf/YXALC6/W/P6U5/ZPWy1wF8iUDHeZirJ8WosjHuFCiRV00hS6XCvSXhtFWHjWitMhsZMkV6HJzQUTuuBs/1vVRyL2vDaSbzom1dhFIyZgyEsfNOO06TEDB3+1mVAOC2MCkzXPV7nT6Izp7GUp9HOXqjYOHoy9AJOGO391xLnikxHpZtNw5yeKr13fYdNlHtq680IewNsCBi2vWkTj+FW6Km0/5sy3Rao41fczh92g3/PqMsjZVgs2aO68cS2jEB+7gDklTinph84AU3Y8EpDNE3dtqw5kji1k8z4SKU6CW30KwyTRRSnUo3k3vAoMYWFgB/l0A9CnvaP02jMoLGtiZy143t0gSZg5t+yRZPWxetbWkSrasMfTXB4hczJCT+tGYgmlaC8LG62eKvn6vZFlndO+LbMYqpL8HKlVF9vlXsiNeJ6QI6BKB5yYaiUnynH+z3cE=" # DOCKER_PASS 8 | - secure: "t+LU5M0vHV5DvaGK9vzQwCGFWiI3XVFbDyVi9QwJHFgoojZkHEaA1h10TYtXODweFrkEXhDblo9+HTgWos+Z0Ova6/B3KbSvp8yjdWJwQyIr2KP7bzS6Pj2do73YT/b2bZ+a6qM7QrZIU5sEtXmenYf1VX504t5l2peJZPghNB27lL4335bGVd3JvYTXvpQ5mjCfNrqVW6L5Sij1bbLmQ3yqpdh52ottLlou1HgklGE5MXCOzkbI3KxyT7/ymDOiuH4UyEyQFTkC1ka+Kas2Uxc8h9t3G4amHfoKZG2ameDJfIBWmqlaCLaV4bSeEGWJF5acaovwNBYwXKFp17IkwFDjEhMl3NvN2J4PrcbAxoH/3TRQKUn2mM1E5HDCLOoq0p4wmnN3AZEzRgY1wggf4c+Cy7vFKtdFvXJvH6mvnMUAaM7WOYncqLm1m3qMNLv39qG1l3u7dPZeIZKDUVApb6imSgh6b2s6zItfS2gewH6AhHE3hSyXi5ad3ZmKExqnW8MNRzRsm/O7jgCGtkEDUjtIC9Yd8uw1ZxXP7YjFfx0HdBzUN4rvetXHtMzm3nWaXQ0hLWIdLoGAEcM8IVwvkxUPJ9l1to4bC0aN8gZdl5jIE18vjUlpu8fJ99ZzB9OofSlK57wn+myRTfOyJPwoBLvNmXu7A/8209Mm5+s6g3c=" # DOCKER_EMAIL 9 | 10 | branches: 11 | only: 12 | - master 13 | 14 | services: 15 | - docker 16 | 17 | before_script: 18 | 19 | script: 20 | - bash ./unifi/mock_test.sh 21 | - docker login -u $DOCKER_USER -p $DOCKER_PASS 22 | - export REPO=$DOCKER_USER/ubiquiti-docker 23 | - make -C unifi build 24 | - 'if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then make -C unifi release; fi' 25 | - bash ./unifi-video/mock_test.sh 26 | - make -C unifi-video build 27 | - 'if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then make -C unifi-video release; fi' 28 | 29 | after_success: 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/ctindel/ubiquiti-docker.svg?branch=master)](https://travis-ci.org/ctindel/ubiquiti-docker) 2 | 3 | # ubiquiti-docker 4 | 5 | Docker images to work with Ubiquiti Products on a Synology NAS. 6 | 7 | See Subdirectories for relevant README. 8 | -------------------------------------------------------------------------------- /unifi-video/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.22 2 | MAINTAINER Chad Tindel "chad@tindel.net" 3 | 4 | # Must be passed in at build time with --build-arg 5 | ARG UNIFI_VIDEO_VERSION 6 | ARG UNIFI_VIDEO_DEB_URL 7 | 8 | # We are installing mongodb 3.4 here so that the wiredtiger storage 9 | # engine will get used by default. Unifi Video starts mongod with 10 | # the --smallfiles option, which is a config that is only relevant 11 | # for mmapv1 storage engine. We end up with a log that says 12 | # "Detected configuration for non-active storage engine mmapv1 when 13 | # current storage engine is wiredTiger" but it seems to be harmless. 14 | # Still, would be nice to be able to override the mongod options. 15 | # 16 | RUN echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections && \ 17 | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \ 18 | echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.4.list && \ 19 | apt-get update && apt-get install -y mongodb-org tzdata && \ 20 | curl -L ${UNIFI_VIDEO_DEB_URL} -o /tmp/unifi-video.deb && \ 21 | mkdir -p /var/cache/unifi-video && \ 22 | mkdir -p /var/run/unifi-video && \ 23 | dpkg -i /tmp/unifi-video.deb || /bin/true && apt-get -yf --force-yes install && \ 24 | apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ 25 | sed -i.bak 's/ulimit -H -c 200//g' /usr/sbin/unifi-video && \ 26 | chmod 755 /usr/sbin/unifi-video && \ 27 | mkdir -p /usr/lib/unifi-video/certificates 28 | #sed -i.bak 's/PKGUSER=unifi-video/PKGUSER=root/g' /usr/sbin/unifi-video && \ 29 | #chown -R unifi-video:unifi-video /var/lib/unifi-video /usr/lib/unifi-video /var/log/unifi-video && \ 30 | #chwon -R root:root /var/log/unifi-video 31 | 32 | ADD start.sh /bin 33 | RUN /bin/chmod +x /bin/start.sh 34 | 35 | # No reason to expose the MongoDB port 7441 to the outside for most people 36 | EXPOSE 1935 6666 7080 7443 7445 7446 7447 37 | #EXPOSE 7441 38 | 39 | ENV SHELL /bin/bash 40 | 41 | CMD [] 42 | ENTRYPOINT ["/bin/start.sh"] 43 | -------------------------------------------------------------------------------- /unifi-video/Makefile: -------------------------------------------------------------------------------- 1 | NAME=ctindel/unifi-video-controller 2 | VERSION=3.9.4 3 | UNIFI_VIDEO_DEB_URL=http://dl.ubnt.com/firmwares/ufv/v$(VERSION)/unifi-video.Ubuntu16.04_amd64.v$(VERSION).deb 4 | 5 | .PHONY: all build test tag_latest release 6 | 7 | all: build 8 | 9 | build: 10 | docker build --no-cache --build-arg UNIFI_VIDEO_VERSION=$(VERSION) --build-arg UNIFI_VIDEO_DEB_URL=$(UNIFI_VIDEO_DEB_URL) -t $(NAME):$(VERSION) --rm=true . 11 | 12 | test: 13 | env NAME=$(NAME) VERSION=$(VERSION) ./mock_test.sh 14 | 15 | tag_latest: 16 | docker tag $(NAME):$(VERSION) $(NAME):latest 17 | 18 | release: tag_latest 19 | @if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi 20 | docker push $(NAME) 21 | @echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)" 22 | -------------------------------------------------------------------------------- /unifi-video/README.md: -------------------------------------------------------------------------------- 1 | Docker image ctindel/unifi-video-controller is a Docker images to 2 | run the Unifi Video Controller a Synology NAS. The image requires 3 | you to run the container with a number of extra capabilities, as 4 | well as disabling apparmor for the container and mounting a host 5 | volume to store all your configuration, videos, and mongodb database 6 | files into the /var/lib/unifi-video location on the container. 7 | 8 | The Synology Docker UI doesn't provide the ability to set these 9 | more esoteric security policies, so if you want to start it from there 10 | you will need to select "privileged" mode for the container. 11 | 12 | Alternately, if you prefer to have a more reduced security 13 | profile you can run it from the command line. Here's an example 14 | from my system, you'll probably need to change the directory for 15 | the host volume mount: 16 | 17 | ``` 18 | docker run --restart always --name unifi-video-controller -p 1935:1935 -p 6666:6666 -p 7080:7080 -p 7443:7443 -p 7445:7445 -p 7446:7446 -p 7447:7447 -d -v /volume3/docker/unifi-video-controller:/var/lib/unifi-video --cap-add=SYS_ADMIN --cap-add=DAC_READ_SEARCH --cap-add=NET_BIND_SERVICE --cap-add=SYS_PTRACE --cap-add=SETUID --cap-add=SETGID --security-opt apparmor:unconfined ctindel/unifi-video-controller:3.1.5 19 | ``` 20 | 21 | If you feel like building the container for yourself, here's 22 | how I do it: 23 | 24 | ``` 25 | docker build --no-cache --build-arg UNIFI_VIDEO_VERSION=3.1.5 --build-arg UNIFI_VIDEO_DEB_URL=http://dl.ubnt.com/firmwares/unifi-video/3.1.5/unifi-video_3.1.5~Ubuntu14.04_amd64.deb -t ctindel/unifi-video-controller:3.1.5 --rm . 26 | ``` 27 | -------------------------------------------------------------------------------- /unifi-video/mock_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exit 0 4 | -------------------------------------------------------------------------------- /unifi-video/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # I had a previous incarnation which would install the debian package on first 4 | # container boot instead of during image building so that we could use the init 5 | # script instead of running jsvc manually. The init script needs to do things 6 | # like mounting a tmpfs which requires various security capabilities and 7 | # unconfined apparmor, so it could not be done at image build time 8 | # (https://github.com/docker/docker/issues/1916). But if we recreate all the 9 | # startup tasks from the init script here instead, then we can get away without 10 | # using it, and we'll be able to install the debian package at image build 11 | # time instead. I'm leaving the code here below commented out in case for some 12 | # reason I need we to use it again 13 | # 14 | # The first time we boot, the deb file will have been downloaded to /tmp/unifi-video.deb 15 | # but we need to install it after the container boots the first time 16 | # so the configuration files can be written to the external 17 | # /usr/lib/unifi-video/conf directory 18 | #PKG_OK=$(dpkg-query -W --showformat='${Status}\n' unifi-video|grep "install ok installed") 19 | #echo "Checking if unifi-video is installed: $PKG_OK" 20 | #if [ "" == "$PKG_OK" ]; then 21 | # dpkg -i /tmp/unifi-video.deb || /bin/true && apt-get -yf --force-yes install 22 | #fi 23 | 24 | # This system.properties file would normally be laid down by the debian package 25 | # installer, but as we expect the user to overlay an external volume onto 26 | # /var/lib/unifi-video it will be empty on first container start so we need 27 | # to fill it in ourselves. 28 | if [ ! -f /var/lib/unifi-video/system.properties ]; then 29 | echo "is_default=true" > /var/lib/unifi-video/system.properties 30 | fi 31 | 32 | # check for presence of perms file, if it exists then skip setting 33 | # permissions, otherwise recursively set on volume mappings for host 34 | if [[ ! -f "/var/lib/unifi-video/perms.txt" ]]; then 35 | echo "About to run 'chown -R unifi-video:unifi-video /var/lib/unifi-video' this could take a while..." 36 | chown -R unifi-video:unifi-video /var/lib/unifi-video 37 | 38 | echo "This file prevents permissions from being applied/re-applied to /config, if you want to reset permissions then please delete this file and restart the container." > /var/lib/unifi-video/perms.txt || exit 1 39 | chown unifi-video:unifi-video /var/lib/unifi-video/perms.txt || exit 1 40 | else 41 | echo "Ownership permissions already set, no need to chown again" 42 | fi 43 | 44 | mkdir -p /var/lib/unifi-video/logs 45 | chown -R unifi-video:unifi-video /var/lib/unifi-video/logs 46 | 47 | #sed -i.bak 's/PKGUSER=.*/PKGUSER=root/g' /usr/sbin/unifi-video 48 | 49 | #while true 50 | #do 51 | # echo "Press [CTRL+C] to stop.." 52 | # sleep 1 53 | #done 54 | /usr/sbin/unifi-video --nodetach --debug --verbose start 55 | -------------------------------------------------------------------------------- /unifi/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM phusion/baseimage:0.9.22 2 | MAINTAINER Chad Tindel "chad@tindel.net" 3 | 4 | # Must be passed in at build time with --build-arg 5 | ARG UNIFI_VERSION 6 | ARG UNIFI_DEB_URL 7 | 8 | # We'll run the mongo prune script every day at 2am to minimize 9 | # DB Stats to last 14 days. See crontab addition above 10 | # https://help.ubnt.com/hc/en-us/articles/204911424-UniFi-How-to-remove-prune-older-data-and-adjust-mongo-database-size 11 | 12 | ADD mongo_prune_js.js /bin 13 | ADD start.sh /bin 14 | RUN /bin/chmod +x /bin/start.sh 15 | 16 | # We download the exact version of Unifi that we want so that we know our 17 | # docker tags are correct instead of apt-get update && apt-get -y install unifi 18 | # 19 | # We need to run the unifi script once because it sets up all the 20 | # /var/lib/unifi and /usr/lib/unifi symlinks for us. But we don't 21 | # want to keep any of that data around, we want our union mount to 22 | # replace /var/lib/unifi so we remove a bunch of dirs at the end 23 | RUN echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections && \ 24 | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv C0A52C50 && \ 25 | apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 && \ 26 | echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" > /etc/apt/sources.list.d/mongodb-org-3.4.list && \ 27 | echo "deb http://www.ubnt.com/downloads/unifi/debian stable ubiquiti" > /etc/apt/sources.list.d/100-ubnt.list && \ 28 | apt-get update && apt-get install -y mongodb-org tzdata && \ 29 | apt-get install -y curl cron procps net-tools vim mongodb-org && \ 30 | curl -L ${UNIFI_DEB_URL} -o /tmp/unifi.deb && \ 31 | dpkg -i /tmp/unifi.deb || /bin/true && apt-get -yf --force-yes install && \ 32 | crontab -l | { cat; echo "0 2 * * * mongo --port 27117 < /bin/mongo_prune_js.js"; } | crontab - && \ 33 | /etc/init.d/unifi start && /etc/init.d/unifi stop && \ 34 | dpkg --purge curl && \ 35 | apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ 36 | rm -rf /var/lib/unifi/* /usr/lib/unifi/{data.,logs.,run.}* 37 | 38 | # No reason to expose the MongoDB port 27117 to the outside for most people 39 | EXPOSE 8080 8443 8843 8880 40 | #EXPOSE 27117 41 | 42 | ENV SHELL /bin/bash 43 | 44 | CMD [] 45 | ENTRYPOINT ["/bin/start.sh"] 46 | -------------------------------------------------------------------------------- /unifi/Makefile: -------------------------------------------------------------------------------- 1 | NAME=ctindel/unifi-controller 2 | VERSION=5.7.20 3 | UNIFI_DEB_URL=http://dl.ubnt.com/unifi/$(VERSION)/unifi_sysvinit_all.deb 4 | 5 | .PHONY: all build test tag_latest release 6 | 7 | all: build 8 | 9 | build: 10 | docker build --no-cache --build-arg UNIFI_VERSION=$(VERSION) --build-arg UNIFI_DEB_URL=$(UNIFI_DEB_URL) -t $(NAME):$(VERSION) --rm=true . 11 | 12 | test: 13 | env NAME=$(NAME) VERSION=$(VERSION) ./mock_test.sh 14 | 15 | tag_latest: 16 | docker tag $(NAME):$(VERSION) $(NAME):latest 17 | 18 | release: tag_latest 19 | @if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi 20 | docker push $(NAME) 21 | @echo "*** Don't forget to create a tag. git tag rel-$(VERSION) && git push origin rel-$(VERSION)" 22 | -------------------------------------------------------------------------------- /unifi/mock_test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | exit 0 4 | -------------------------------------------------------------------------------- /unifi/mongo_prune_js.js: -------------------------------------------------------------------------------- 1 | // keep N-day worth of data 2 | var days=14; 3 | 4 | // change to false to have the script to really exclude old records 5 | // from the database. While true, no change at all will be made to the DB 6 | var dryrun=true; 7 | 8 | var now = new Date().getTime(), 9 | time_criteria = now - days * 86400 * 1000, 10 | time_criteria_in_seconds = time_criteria / 1000; 11 | 12 | print((dryrun ? "[dryrun] " : "") + "pruning data older than " + days + " days (" + time_criteria + ")... "); 13 | 14 | use ace; 15 | var collectionNames = db.getCollectionNames(); 16 | for (i=0; i