Merge pull request #2 from ninech/add_tests

Add tests
This commit is contained in:
Christian Mäder 2017-08-30 12:53:28 +02:00 committed by GitHub
commit dd5da7afbc
6 changed files with 54 additions and 14 deletions

View File

@ -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"]

View File

@ -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
```

23
docker-compose.test.yml Normal file
View File

@ -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

View File

@ -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

View File

@ -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 ${@}

3
postgres.env Normal file
View File

@ -0,0 +1,3 @@
POSTGRES_USER=netbox
POSTGRES_PASSWORD=J5brHrAXFLQSif0K
POSTGRES_DB=netbox