From 4ce4373eb02320a4dec4fe395f52f189fd6efaa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 30 Aug 2017 11:07:28 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=B3=20By=20default,=20build=20`lat?= =?UTF-8?q?est`=20from=20the=20`master`=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a63ef8..d0cf439 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN apk add --no-cache \ WORKDIR /opt -ARG BRANCH=v2.0.7 +ARG BRANCH=master ARG URL=https://github.com/digitalocean/netbox/archive/$BRANCH.tar.gz RUN wget -q -O - "${URL}" | tar xz \ && mv netbox* netbox diff --git a/docker-compose.yml b/docker-compose.yml index df7859b..93edfbc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: context: . args: - BRANCH=${BRANCH-master} - image: ninech/netbox:${BRANCH-master} + image: ninech/netbox:${BRANCH-latest} depends_on: - postgres env_file: netbox.env From 822350d666e2d3a39ca223c5168d3c858d6ad381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 30 Aug 2017 11:08:21 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=BC=20Introduces=20a=20more=20rece?= =?UTF-8?q?nt=20gunicorn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0cf439..cc80c33 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,9 @@ RUN apk add --no-cache \ openldap-dev \ openssl-dev \ postgresql-dev \ - wget \ - && pip install gunicorn==17.5 + wget + +RUN pip install gunicorn WORKDIR /opt From ab0c25504043bc7f9b8ae081dfac1e88dab6ae9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 30 Aug 2017 11:09:24 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=B3=20Change=20to=20the=20actual?= =?UTF-8?q?=20workdir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +++- docker/docker-entrypoint.sh | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index cc80c33..b79efd4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,10 +27,12 @@ RUN wget -q -O - "${URL}" | tar xz \ WORKDIR /opt/netbox RUN pip install -r requirements.txt -RUN ln -s configuration.docker.py netbox/netbox/configuration.py +RUN ln -s configuration.docker.py /opt/netbox/netbox/netbox/configuration.py COPY docker/gunicorn_config.py /opt/netbox/ COPY docker/nginx.conf /etc/netbox-nginx/nginx.conf +WORKDIR /opt/netbox/netbox + COPY docker/docker-entrypoint.sh /docker-entrypoint.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index e65c648..d921de0 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -2,7 +2,7 @@ set -e # run db migrations (retry on error) -while ! /opt/netbox/netbox/manage.py migrate 2>&1; do +while ! ./manage.py migrate 2>&1; do sleep 5 done @@ -14,14 +14,14 @@ if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}" fi -python netbox/manage.py shell --plain << END +./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 +./manage.py collectstatic --no-input # start unicorn gunicorn --log-level debug --debug -c /opt/netbox/gunicorn_config.py netbox.wsgi From d58930ab670cddf975a1f2715dc7860c2904f5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 30 Aug 2017 11:09:56 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=90=B3=20Adds=20the=20possibility=20t?= =?UTF-8?q?o=20overwrite=20the=20CMD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ docker/docker-entrypoint.sh | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b79efd4..8a6273a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,3 +37,5 @@ COPY docker/docker-entrypoint.sh /docker-entrypoint.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] VOLUME ["/etc/netbox-nginx/"] + +CMD ["gunicorn", "--log-level debug", "-c /opt/netbox/gunicorn_config.py", "netbox.wsgi"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index d921de0..f830bd5 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -23,5 +23,8 @@ END # copy static files ./manage.py collectstatic --no-input -# start unicorn -gunicorn --log-level debug --debug -c /opt/netbox/gunicorn_config.py netbox.wsgi +echo "✅ Initialisation is done. Launching CMD:" +echo "exec ${@}" + +# launch whatever is passed by docker via RUN +exec ${@} From f9d60692f427374304b6ec4fb5daa4b428f44b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 30 Aug 2017 11:10:55 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=90=B3=20Adds=20a=20sample=20on=20how?= =?UTF-8?q?=20to=20run=20netbox=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ docker-compose.test.yml | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 docker-compose.test.yml diff --git a/README.md b/README.md index 5d54171..dd31333 100644 --- a/README.md +++ b/README.md @@ -51,3 +51,11 @@ You can configure the app at runtime using variables (see `docker-compose.yml`). * SHORT_TIME_FORMAT * DATETIME_FORMAT * SHORT_DATETIME_FORMAT + +## Tests + +To run the bundled test, use the `docker-compose.test.yml` file. + +``` +# docker-compose -f docker-compose.test.yml run --rm app +``` diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..c2b7508 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,25 @@ +version: '3' +services: + app: + build: + context: . + args: + - BRANCH=${BRANCH-master} + image: ninech/netbox:${BRANCH-latest} + depends_on: + - postgres + env_file: netbox.env + command: + - ./manage.py + - test + 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 From de9b6a853d547de933465fc7014503bcf55b8520 Mon Sep 17 00:00:00 2001 From: misazr Date: Wed, 30 Aug 2017 11:45:14 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=90=B3=20Extracted=20postgres=20env?= =?UTF-8?q?=20into=20new=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.test.yml | 6 ++---- docker-compose.yml | 6 ++---- postgres.env | 3 +++ 3 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 postgres.env diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c2b7508..978de00 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -14,10 +14,8 @@ services: - test postgres: image: postgres:9.6-alpine - environment: - POSTGRES_USER: netbox - POSTGRES_PASSWORD: J5brHrAXFLQSif0K - POSTGRES_DB: netbox + env_file: postgres.env + volumes: netbox-static-files: driver: local diff --git a/docker-compose.yml b/docker-compose.yml index 93edfbc..117925f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,10 +24,8 @@ services: - netbox-nginx-config:/etc/netbox-nginx/ postgres: image: postgres:9.6-alpine - environment: - POSTGRES_USER: netbox - POSTGRES_PASSWORD: J5brHrAXFLQSif0K - POSTGRES_DB: netbox + env_file: postgres.env + volumes: netbox-static-files: driver: local diff --git a/postgres.env b/postgres.env new file mode 100644 index 0000000..8bc8d28 --- /dev/null +++ b/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=netbox +POSTGRES_PASSWORD=J5brHrAXFLQSif0K +POSTGRES_DB=netbox