commit 03c9d835dc56f08604a20dcc71ae5eae8d9097e1 Author: Kris Lamoureux Date: Sat Jun 29 21:22:52 2024 -0400 Add basic Unifi Network Application deployment - Write initial docker-compose.yml for Unifi containers - Create a template for initializing MongoDB databases - Add README with setup instructions for the initial environment diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fe999c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +init-mongo.js diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..837cd13 --- /dev/null +++ b/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2024 by Kris Lamoureux + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b988753 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# UniFi Network Server Deployment + +This project provides a simple setup for self-hosting a UniFi Network Server +inside a container to manage Ubiquiti networking gear. It leverages the +community-managed linuxserver.io container to save time and engineering effort. + +## Requirements +- Docker / Docker Compose +- `pwgen` (optional, for password generation) + +## Compatibility +Starting with version 8.1 of UniFi Network Application, MongoDB versions 3.6 +through 7.0 are supported. + +## Quick Start +Follow these steps to get your UniFi Network Server up and running. + +1. Clone this repository and navigate to the project directory + +2. Copy the example MongoDB initialization script + ```txt + cp example-init-mongo.js init-mongo.js + ``` + +3. Change the default password to a random string + ```txt + sed -i "s/changeme/$(pwgen -s 32 1)/g" init-mongo.js + ``` + Note: This command requires `pwgen`. If you don't have it installed, you can + manually edit the file and replace "changeme" with a strong password of your + choice. + +4. Set the following environment variables in the `.env` file + - `UNIFI_VERSION`: The desired UniFi Network Application version + - `MONGO_VERSION`: The desired MongoDB version + - `MONGO_PASS`: The password you set in step 3 + +5. Start the containers using Docker Compose: + ```txt + docker-compose up -d + ``` + +## Version Selection + +### UniFi Network Application +It's recommended to install the +[latest UniFi version](https://github.com/linuxserver/docker-unifi-network-application/releases), +preferably by specifying the version number. You can omit the `-lsXX` suffix if desired. + +### MongoDB +It's highly recommended to use a specific version tag for +[MongoDB](https://www.mongodb.com/try/download/community) since there are no +automatic upgrades between major versions. + +**Note:** Modern MongoDB relies on AVX support. You might encounter issues with +pre-Tiger Lake Celeron and Pentium CPUs on versions after 4.4. For non-AVX +systems, you can use version 4.4. + +## Additional Information +For more details and configuration options, please refer to the +[linuxserver/docker-unifi-network-application](https://docs.linuxserver.io/images/docker-unifi-network-application/) +documentation. + +## License +This project is free software under the [Zero-Clause BSD](LICENSE). diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4af2862 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +services: + app: + image: ${UNIFI_IMAGE:-linuxserver/unifi-network-application}:${UNIFI_VERSION:?} + container_name: ${UNIFI_NAME:-unifi} + environment: + PUID: 1000 + PGID: 1000 + TZ: ${TIMEZONE:-America/New_York} + MONGO_HOST: db + MONGO_PORT: 27017 + MONGO_DBNAME: ${MONGO_DBNAME:-unifi} + MONGO_USER: ${MONGO_USER:-unifi} + MONGO_PASS: ${MONGO_PASS:?} + volumes: + - app:/config + ports: + - 8443:8443 + - 3478:3478/udp + - 10001:10001/udp + - 8080:8080 + + db: + image: ${MONGO_IMAGE:-mongo}:${MONGO_VERSION:?} + container_name: ${MONGO_NAME:-unifi-db} + volumes: + - db:/data/db + - ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro + +volumes: + db: + app: diff --git a/example-init-mongo.js b/example-init-mongo.js new file mode 100644 index 0000000..54fb9f9 --- /dev/null +++ b/example-init-mongo.js @@ -0,0 +1,8 @@ +db.getSiblingDB("unifi").createUser({ + user: "unifi", + pwd: "changeme", + roles: [ + { role: "dbOwner", db: "unifi" }, + { role: "dbOwner", db: "unifi_stat" } + ] +}); \ No newline at end of file