commit 582b2abea8432f951db5b4e2a4e148b2a790970f Author: Jeremy Stretch Date: Wed Apr 19 10:48:21 2017 -0400 Copied Docker components from main repo diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..70032b5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM python:2.7-wheezy + +WORKDIR /opt/netbox + +ARG BRANCH=v2-beta +ARG URL=https://github.com/digitalocean/netbox.git +RUN git clone --depth 1 $URL -b $BRANCH . && \ + apt-get update -qq && apt-get install -y libldap2-dev libsasl2-dev libssl-dev graphviz && \ + pip install gunicorn==17.5 && \ + pip install django-auth-ldap && \ + pip install -r requirements.txt + +ADD docker/docker-entrypoint.sh /docker-entrypoint.sh +ADD netbox/netbox/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py + +ENTRYPOINT [ "/docker-entrypoint.sh" ] + +ADD docker/gunicorn_config.py /opt/netbox/ +ADD docker/nginx.conf /etc/netbox-nginx/ +VOLUME ["/etc/netbox-nginx/"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c846a7 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# netbox-docker + +This repository houses the components needed to build NetBox as a Docker container. It is a work in progress; please submit a bug report for any issues you encounter. + +## Quickstart + +To get NetBox up and running: + +``` +# git clone -b master https://github.com/digitalocean/netbox-docker.git +# cd netbox +# docker-compose up -d +``` + +The application will be available on http://localhost/ after a few minutes. + +Default credentials: + +* Username: **admin** +* Password: **admin** + +## Configuration + +You can configure the app at runtime using variables (see `docker-compose.yml`). Possible environment variables include: + +* SUPERUSER_NAME +* SUPERUSER_EMAIL +* SUPERUSER_PASSWORD +* ALLOWED_HOSTS +* DB_NAME +* DB_USER +* DB_PASSWORD +* DB_HOST +* DB_PORT +* SECRET_KEY +* EMAIL_SERVER +* EMAIL_PORT +* EMAIL_USERNAME +* EMAIL_PASSWORD +* EMAIL_TIMEOUT +* EMAIL_FROM +* LOGIN_REQUIRED +* MAINTENANCE_MODE +* NETBOX_USERNAME +* NETBOX_PASSWORD +* PAGINATE_COUNT +* TIME_ZONE +* DATE_FORMAT +* SHORT_DATE_FORMAT +* TIME_FORMAT +* SHORT_TIME_FORMAT +* DATETIME_FORMAT +* SHORT_DATETIME_FORMAT diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d435066 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,53 @@ +version: '2' + +services: + postgres: + image: postgres:9.6 + container_name: postgres + environment: + POSTGRES_USER: netbox + POSTGRES_PASSWORD: J5brHrAXFLQSif0K + POSTGRES_DB: netbox + netbox: + build: . + image: digitalocean/netbox + links: + - postgres + container_name: netbox + depends_on: + - postgres + environment: + SUPERUSER_NAME: admin + SUPERUSER_EMAIL: admin@example.com + SUPERUSER_PASSWORD: admin + ALLOWED_HOSTS: localhost + DB_NAME: netbox + DB_USER: netbox + DB_PASSWORD: J5brHrAXFLQSif0K + DB_HOST: postgres + SECRET_KEY: r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj + EMAIL_SERVER: localhost + EMAIL_PORT: 25 + EMAIL_USERNAME: foo + EMAIL_PASSWORD: bar + EMAIL_TIMEOUT: 10 + EMAIL_FROM: netbox@bar.com + NETBOX_USERNAME: guest + NETBOX_PASSWORD: guest + volumes: + - netbox-static-files:/opt/netbox/netbox/static + nginx: + image: nginx:1.11.1-alpine + links: + - netbox + container_name: nginx + command: nginx -g 'daemon off;' -c /etc/netbox-nginx/nginx.conf + depends_on: + - netbox + ports: + - 80:80 + volumes_from: + - netbox +volumes: + netbox-static-files: + driver: local diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 0000000..53e52ef --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# run db migrations (retry on error) +while ! /opt/netbox/netbox/manage.py migrate 2>&1; do + sleep 5 +done + +# create superuser silently +if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} ]]; then + SUPERUSER_NAME='admin' + SUPERUSER_EMAIL='admin@example.com' + SUPERUSER_PASSWORD='admin' + echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}" +fi +echo "from django.contrib.auth.models import User; User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')" | python /opt/netbox/netbox/manage.py shell + +# copy static files +/opt/netbox/netbox/manage.py collectstatic --no-input + +# start unicorn +gunicorn --log-level debug --debug --error-logfile /dev/stderr --log-file /dev/stdout -c /opt/netbox/gunicorn_config.py netbox.wsgi diff --git a/docker/gunicorn_config.py b/docker/gunicorn_config.py new file mode 100644 index 0000000..878841a --- /dev/null +++ b/docker/gunicorn_config.py @@ -0,0 +1,5 @@ +command = '/usr/bin/gunicorn' +pythonpath = '/opt/netbox/netbox' +bind = '0.0.0.0:8001' +workers = 3 +user = 'root' diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..2a794f3 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,35 @@ +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + sendfile on; + tcp_nopush on; + keepalive_timeout 65; + gzip on; + server_tokens off; + + server { + listen 80; + + server_name localhost; + + access_log off; + + location /static/ { + alias /opt/netbox/netbox/static/; + } + + location / { + proxy_pass http://netbox:8001; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; + } + } +}