From fee1eed522f28d3f8afbdd0423e2653ab9909bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 21 Apr 2017 13:43:44 +0200 Subject: [PATCH 1/3] Checks if the superuser exists before creating it --- docker/docker-entrypoint.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 53e52ef..8f1bd3f 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -13,7 +13,12 @@ if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} 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 + +python netbox/manage.py shell --plain << END +from django.contrib.auth.models import User +if not User.objects.filter(username='${SUPERUSER_NAME}'): + User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}') +END # copy static files /opt/netbox/netbox/manage.py collectstatic --no-input From 1e96f5a191c1fad89ceabd2aef0b4f9989f1efca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 21 Apr 2017 13:45:34 +0200 Subject: [PATCH 2/3] Reworked the Dockerfile with alpinelinux --- Dockerfile | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 70032b5..238ab88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,35 @@ -FROM python:2.7-wheezy +FROM python:2.7-alpine -WORKDIR /opt/netbox +RUN apk add --no-cache \ + bash \ + build-base \ + ca-certificates \ + cyrus-sasl-dev \ + graphviz \ + jpeg-dev \ + libffi-dev \ + libxml2-dev \ + libxslt-dev \ + openldap-dev \ + openssl-dev \ + postgresql-dev \ + wget \ + && pip install gunicorn==17.5 django-auth-ldap + +WORKDIR /opt 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 +ARG URL=https://github.com/digitalocean/netbox/archive/$BRANCH.tar.gz +RUN wget -q -O - "${URL}" | tar xz \ + && ln -s netbox* netbox -ADD docker/docker-entrypoint.sh /docker-entrypoint.sh -ADD netbox/netbox/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py +WORKDIR /opt/netbox +RUN pip install -r requirements.txt +RUN ln -s configuration.docker.py netbox/netbox/configuration.py +COPY docker/gunicorn_config.py /opt/netbox/ + +COPY docker/docker-entrypoint.sh /docker-entrypoint.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] -ADD docker/gunicorn_config.py /opt/netbox/ -ADD docker/nginx.conf /etc/netbox-nginx/ VOLUME ["/etc/netbox-nginx/"] From ecb5ecd1a4c6cbcbb22bfab5154d052e9187d568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 21 Apr 2017 13:46:15 +0200 Subject: [PATCH 3/3] Restructured docker-compose.yml --- docker-compose.yml | 55 ++++++++++++++-------------------------------- netbox.env | 17 ++++++++++++++ 2 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 netbox.env diff --git a/docker-compose.yml b/docker-compose.yml index d435066..dcc95b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,53 +1,32 @@ -version: '2' - +version: '3' 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 + image: digitalocean/netbox:v2.0-beta2 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 + env_file: netbox.env volumes: + - netbox-nginx-config:/etc/netbox-nginx/ - netbox-static-files:/opt/netbox/netbox/static nginx: - image: nginx:1.11.1-alpine - links: - - netbox - container_name: nginx + image: nginx:1.11-alpine command: nginx -g 'daemon off;' -c /etc/netbox-nginx/nginx.conf depends_on: - netbox ports: - - 80:80 - volumes_from: - - netbox + - 80 + volumes: + - netbox-static-files:/opt/netbox/netbox/static + - netbox-nginx-config:/etc/netbox-nginx/ + postgres: + image: postgres:9.6-alpine + environment: + POSTGRES_USER: netbox + POSTGRES_PASSWORD: J5brHrAXFLQSif0K + POSTGRES_DB: netbox volumes: netbox-static-files: driver: local + netbox-nginx-config: + driver: local diff --git a/netbox.env b/netbox.env new file mode 100644 index 0000000..4bc812f --- /dev/null +++ b/netbox.env @@ -0,0 +1,17 @@ +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