diff --git a/Dockerfile b/Dockerfile index 8a63ef8..8a6273a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,12 +13,13 @@ RUN apk add --no-cache \ openldap-dev \ openssl-dev \ postgresql-dev \ - wget \ - && pip install gunicorn==17.5 + wget + +RUN pip install gunicorn 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 @@ -26,11 +27,15 @@ 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" ] VOLUME ["/etc/netbox-nginx/"] + +CMD ["gunicorn", "--log-level debug", "-c /opt/netbox/gunicorn_config.py", "netbox.wsgi"] 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..978de00 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,23 @@ +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 + env_file: postgres.env + +volumes: + netbox-static-files: + driver: local + netbox-nginx-config: + driver: local diff --git a/docker-compose.yml b/docker-compose.yml index df7859b..117925f 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 @@ -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/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index e65c648..f830bd5 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,17 @@ 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 +echo "✅ Initialisation is done. Launching CMD:" +echo "exec ${@}" + +# launch whatever is passed by docker via RUN +exec ${@} 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