Skip to content

Commit

Permalink
Merge pull request #265 from netbox-community/develop
Browse files Browse the repository at this point in the history
Release 0.23.0
  • Loading branch information
cimnine committed Mar 30, 2020
2 parents 80f514f + 23e2da5 commit 5769684
Show file tree
Hide file tree
Showing 38 changed files with 742 additions and 874 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ build*
docker-compose.override.yml
.netbox/.git*
.netbox/.travis.yml
.netbox/docs
.netbox/scripts
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
[The Github repository](netbox-docker-github) houses the components needed to build Netbox as a Docker container.
Images are built using this code and are released to [Docker Hub][netbox-dockerhub] once a day.

Do you have any questions? Before opening an issue on Github, please join the [Network To Code][ntc-slack] Slack and ask for help in our [`#netbox-docker`][netbox-docker-slack] channel.
Do you have any questions?
Before opening an issue on Github, please join the [Network To Code][ntc-slack] Slack and ask for help in our [`#netbox-docker`][netbox-docker-slack] channel.

[github-stargazers]: https://github.com/netbox-community/netbox-docker/stargazers
[github-release]: https://github.com/netbox-community/netbox-docker/releases
Expand All @@ -25,16 +26,18 @@ Do you have any questions? Before opening an issue on Github, please join the [N

## Docker Tags

* `vX.Y.Z`: Release builds, built from [releases of Netbox][netbox-releases].
* `latest`: Release builds, built from [`master` branch of Netbox][netbox-master].
* `snapshot`: Pre-release builds, built from the [`develop` branch of Netbox][netbox-develop].
* `develop-X.Y`: Pre-release builds, built from the corresponding [branch of Netbox][netbox-branches].
* `vX.Y.Z`: These are release builds, automatically built from [the corresponding releases of Netbox][netbox-releases].
* `latest`: These are release builds, automatically built from [the `master` branch of Netbox][netbox-master].
* `snapshot`: These are pre-release builds, automatically built from the [`develop` branch of Netbox][netbox-develop].
* `develop-X.Y`: These are pre-release builds, automatically built from the corresponding [branch of Netbox][netbox-branches].

Then there is currently one extra tags for each of the above labels:
Then there is currently one extra tags for each of the above tags:

* `-ldap`: Contains additional dependencies and configurations for connecting Netbox to an LDAP directroy.
[Learn more about that in our wiki][netbox-docker-ldap].

New images are built and published automatically every ~24h.

[netbox-releases]: https://github.com/netbox-community/netbox/releases
[netbox-master]: https://github.com/netbox-community/netbox/tree/master
[netbox-develop]: https://github.com/netbox-community/netbox/tree/develop
Expand All @@ -43,42 +46,50 @@ Then there is currently one extra tags for each of the above labels:

## Quickstart

To get Netbox up and running in Docker:
To get Netbox Docker up and running run the following commands.
There is a more complete [_Getting Started_ guide on our wiki][wiki-getting-started] which explains every step.

```bash
git clone -b release https://github.com/netbox-community/netbox-docker.git
cd netbox-docker
tee netbox-docker.override.yml <<EOF
version: '3.4'
services:
nginx:
ports:
- 8000:8080
EOF
docker-compose pull
docker-compose up -d
```

The application will be available after a few minutes.
Use `docker-compose port nginx 8080` to find out where to connect to.

```bash
$ echo "http://$(docker-compose port nginx 8080)/"
http://0.0.0.0:32768/

# Open netbox in your default browser on macOS:
$ open "http://$(docker-compose port nginx 8080)/"

# Open netbox in your default browser on (most) linuxes:
$ xdg-open "http://$(docker-compose port nginx 8080)/" &>/dev/null &
docker-compose up
```

Alternatively, use something like [Reception][docker-reception] to connect to _docker-compose_ projects.

The whole application will be available after a few minutes.
Open the URL `http://0.0.0.0:8000/` in a web-browser.
You should see the Netbox homepage.
In the top-right corner you can login.
The default credentials are:

* Username: **admin**
* Password: **admin**
* API Token: **0123456789abcdef0123456789abcdef01234567**

There is a more complete [Getting Started guide on our Wiki][wiki-getting-started].

[wiki-getting-started]: https://github.com/netbox-community/netbox-docker/wiki/Getting-Started
[docker-reception]: https://github.com/nxt-engineering/reception

## Documentation

Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
It covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.

[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/

## Getting Help

Please join [our Slack channel `#netbox-docker`][netbox-docker-slack] on the [Network To Code Slack][ntc-slack].
It's free to use and there are almost always people online that can help.

If you need help with using Netbox or developing for it or against it's API you may find the `#netbox` channel on the same Slack instance very helpful.

## Dependencies

This project relies only on *Docker* and *docker-compose* meeting these requirements:
Expand All @@ -88,17 +99,10 @@ This project relies only on *Docker* and *docker-compose* meeting these requirem

To check the version installed on your system run `docker --version` and `docker-compose --version`.

## Documentation

Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
It covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.

[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/
## Use a Specific Netbox Version

## Netbox Version

The `docker-compose.yml` file is prepared to run a specific version of Netbox.
To use this feature, set the environment-variable `VERSION` before launching `docker-compose`, as shown below.
The `docker-compose.yml` file is prepared to run a specific version of Netbox, instead of `latest`.
To use this feature, set and export the environment-variable `VERSION` before launching `docker-compose`, as shown below.
`VERSION` may be set to the name of
[any tag of the `netboxcommunity/netbox` Docker image on Docker Hub][netbox-dockerhub].

Expand Down Expand Up @@ -141,10 +145,6 @@ For more details on custom builds [consult our wiki][netbox-docker-wiki-build].

[netbox-docker-wiki-build]: https://github.com/netbox-community/netbox-docker/wiki/Build

### Pre-made Docker Images

New Docker images are built and published every 24h.

## Tests

We have a test script.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.22.0
0.23.0
9 changes: 9 additions & 0 deletions configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ def read_secret(secret_name):
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
# prefer IPv4 instead.
PREFER_IPV4 = os.environ.get('PREFER_IPV4', 'False').lower() == 'true'

# This determines how often the GitHub API is called to check the latest release of NetBox in seconds. Must be at least 1 hour.
RELEASE_CHECK_TIMEOUT = os.environ.get('RELEASE_CHECK_TIMEOUT', 24 * 3600)

# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
# version check or use the URL below to check for release in the official NetBox repository.
# https://api.github.com/repos/netbox-community/netbox/releases
RELEASE_CHECK_URL = os.environ.get('RELEASE_CHECK_URL', None)

# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
# this setting is derived from the installed location.
REPORTS_ROOT = os.environ.get('REPORTS_ROOT', '/etc/netbox/reports')
Expand Down
10 changes: 9 additions & 1 deletion docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
depends_on:
- postgres
- redis
- redis-cache
env_file: env/netbox.env
user: '101'
volumes:
Expand Down Expand Up @@ -34,8 +35,15 @@ services:
command:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
env_file: env/redis.env
redis-cache:
image: redis:5-alpine
command:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
env_file: env/redis-cache.env
volumes:
netbox-static-files:
driver: local
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
- sh
- -c # this is to evaluate the $REDIS_PASSWORD from the env
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
env_file: env/redis.env
env_file: env/redis-cache.env
volumes:
netbox-static-files:
driver: local
Expand Down
3 changes: 2 additions & 1 deletion env/netbox.env
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ REDIS_DATABASE=0
REDIS_SSL=false
REDIS_CACHE_HOST=redis-cache
REDIS_CACHE_PASSWORD=t4Ph722qJ5QHeQ1qfu36
REDIS_CACHE_DATABASE=0
REDIS_CACHE_DATABASE=1
REDIS_CACHE_SSL=false
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
SKIP_STARTUP_SCRIPTS=false
Expand All @@ -30,3 +30,4 @@ SUPERUSER_EMAIL=admin@example.com
SUPERUSER_PASSWORD=admin
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
WEBHOOKS_ENABLED=true
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
51 changes: 16 additions & 35 deletions startup_scripts/000_users.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
from django.contrib.auth.models import Permission, Group, User
from users.models import Token

from ruamel.yaml import YAML
from pathlib import Path
import sys

file = Path('/opt/netbox/initializers/users.yml')
if not file.is_file():
sys.exit()
from django.contrib.auth.models import Group, User
from startup_script_utils import load_yaml, set_permissions
from users.models import Token

with file.open('r') as stream:
yaml=YAML(typ='safe')
users = yaml.load(stream)
users = load_yaml('/opt/netbox/initializers/users.yml')
if users is None:
sys.exit()

if users is not None:
for username, user_details in users.items():
if not User.objects.filter(username=username):
user = User.objects.create_user(
username = username,
password = user_details.get('password', 0) or User.objects.make_random_password)
for username, user_details in users.items():
if not User.objects.filter(username=username):
user = User.objects.create_user(
username = username,
password = user_details.get('password', 0) or User.objects.make_random_password)

print("👤 Created user",username)
print("👤 Created user",username)

if user_details.get('api_token', 0):
Token.objects.create(user=user, key=user_details['api_token'])
if user_details.get('api_token', 0):
Token.objects.create(user=user, key=user_details['api_token'])

yaml_permissions = user_details.get('permissions', [])
if yaml_permissions:
subject = user.user_permissions
subject.clear()
for yaml_permission in yaml_permissions:
if '*' in yaml_permission:
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
permissions = Permission.objects.filter(codename__iregex=permission_filter)
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
else:
permissions = Permission.objects.filter(codename=yaml_permission)
print(" ⚿ Granting permission", yaml_permission)

for permission in permissions:
subject.add(permission)
yaml_permissions = user_details.get('permissions', [])
set_permissions(user.user_permissions, yaml_permissions)
48 changes: 15 additions & 33 deletions startup_scripts/010_groups.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
from django.contrib.auth.models import Permission, Group, User
from ruamel.yaml import YAML
from pathlib import Path
import sys

file = Path('/opt/netbox/initializers/groups.yml')
if not file.is_file():
sys.exit()

with file.open('r') as stream:
yaml=YAML(typ='safe')
groups = yaml.load(stream)
from django.contrib.auth.models import Group, User
from startup_script_utils import load_yaml, set_permissions

if groups is not None:
for groupname, group_details in groups.items():
group, created = Group.objects.get_or_create(name=groupname)
groups = load_yaml('/opt/netbox/initializers/groups.yml')
if groups is None:
sys.exit()

if created:
print("👥 Created group", groupname)
for groupname, group_details in groups.items():
group, created = Group.objects.get_or_create(name=groupname)

for username in group_details.get('users', []):
user = User.objects.get(username=username)
if created:
print("👥 Created group", groupname)

if user:
user.groups.add(group)
for username in group_details.get('users', []):
user = User.objects.get(username=username)

yaml_permissions = group_details.get('permissions', [])
if yaml_permissions:
subject = group.permissions
subject.clear()
for yaml_permission in yaml_permissions:
if '*' in yaml_permission:
permission_filter = '^' + yaml_permission.replace('*','.*') + '$'
permissions = Permission.objects.filter(codename__iregex=permission_filter)
print(" ⚿ Granting", permissions.count(), "permissions matching '" + yaml_permission + "'")
else:
permissions = Permission.objects.filter(codename=yaml_permission)
print(" ⚿ Granting permission", yaml_permission)
if user:
user.groups.add(group)

for permission in permissions:
subject.add(permission)
yaml_permissions = group_details.get('permissions', [])
set_permissions(group.permissions, yaml_permissions)
Loading

0 comments on commit 5769684

Please sign in to comment.