From 4ef420d4435b91b9c77992290cb5e4a43814a900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Fri, 1 Feb 2019 09:58:07 +0100 Subject: [PATCH 1/2] Build system for hub.docker.com --- DOCKER_HUB.md | 66 ++++++++++++++++++++++++++++ build-all.sh | 108 ++++++++++++++++++++++------------------------ build-branches.sh | 2 +- build-latest.sh | 2 +- build.sh | 28 ++++++------ hooks/build | 5 +++ hooks/common | 82 +++++++++++++++++++++++++++++++++++ hooks/push | 5 +++ hooks/test | 12 ++++++ 9 files changed, 240 insertions(+), 70 deletions(-) create mode 100644 DOCKER_HUB.md create mode 100755 hooks/build create mode 100755 hooks/common create mode 100755 hooks/push create mode 100755 hooks/test diff --git a/DOCKER_HUB.md b/DOCKER_HUB.md new file mode 100644 index 0000000..6149c3c --- /dev/null +++ b/DOCKER_HUB.md @@ -0,0 +1,66 @@ +# cloud.docker.com Configuration + +The automatic build is configured in cloud.docker.com. + +The following build configuration is expected: + +```yaml +Source Repository: github.com/netbox-community/netbox-docker +Build Location: Build on Docker Hub's infrastructure +Autotest: Internal and External Pull Requests +Repository Links: Enable for Base Image +Build Rules: +- Source Type: Branch + Source: master + Docker Tag: branches-main + Dockerfile location: Dockerfile +- Source Type: Branch + Source: master + Docker Tag: branches-ldap + Dockerfile location: Dockerfile.ldap +- Source Type: Branch + Source: master + Docker Tag: prerelease-main + Dockerfile location: Dockerfile +- Source Type: Branch + Source: master + Docker Tag: prerelease-ldap + Dockerfile location: Dockerfile.ldap +- Source Type: Branch + Source: master + Docker Tag: release-main + Dockerfile location: Dockerfile +- Source Type: Branch + Source: master + Docker Tag: release-ldap + Dockerfile location: Dockerfile.ldap +Build Environment Variables: +# Create an app on Github and use it's OATH credentials here +- Key: GITHUB_OAUTH_CLIENT_ID + Value: +- Key: GITHUB_OAUTH_CLIENT_SECRET + Value: +Build Triggers: +- Name: Cron Trigger +# Use this trigger in combination with e.g. https://cron-job.org in order to regularly schedule builds +``` + +## Background Knowledge + +The build system of cloud.docker.com is not made for this kind of project. +But we found a way to make it work, and this is how: + +1. The docker hub build system [allows to overwrite the scripts that get executed + for `build`, `test` and `push`](overwrite). See `hooks/*`. +2. Shared functionality of the scripts `build`, `test` and `push` is extracted to `hooks/common`. +3. The `build` script runs `run_build()` from `hooks/common`. + This triggers either `build-branches.sh`, `build-latest.sh` or directly `build.sh`. +4. The `test` script just invokes `docker-compose` commands. +5. The `push` script runs `run_build()` from `hooks/common` with a `--push-only` flag. + This causes the `build.sh` script to not re-build the Docker image, but just the just built image. + +The _Docker Tag_ configuration setting is misused to select the type (_release_, _prerelease_, _branches_) of the build as well as the variant (_main_, _ldap_). + +The _Dockerfile location_ configuration setting is completely ignored by the build scripts. + +[overwrite]: https://docs.docker.com/docker-hub/builds/advanced/#override-build-test-or-push-commands diff --git a/build-all.sh b/build-all.sh index 0c1bd53..d88c5af 100755 --- a/build-all.sh +++ b/build-all.sh @@ -12,9 +12,9 @@ BUILDS=("${BUILD:-"${ALL_BUILDS[@]}"}") echo "⚙️ Configured builds: ${BUILDS[*]}" -VARIANTS=("" "ldap") +VARIANTS=("main" "ldap") -if [ ! -z "${DEBUG}" ]; then +if [ -n "${DEBUG}" ]; then export DEBUG fi @@ -22,67 +22,63 @@ ERROR=0 # Don't build if not on `master` and don't build if on a pull request, # but build when DEBUG is not empty -if [ ! -z "${DEBUG}" ] || \ - ( [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ] ); then - for VARIANT in "${VARIANTS[@]}"; do - export VARIANT +for VARIANT in "${VARIANTS[@]}"; do + export VARIANT - # Checking which VARIANT to build - if [ -z "$VARIANT" ]; then - DOCKERFILE="Dockerfile" - else - DOCKERFILE="Dockerfile.${VARIANT}" + # Checking which VARIANT to build + if [ "${VARIANT}" == "main" ]; then + DOCKERFILE="${DOCKERFILE_PATH-Dockerfile}" + else + DOCKERFILE="${DOCKERFILE_PATH-Dockerfile}.${VARIANT}" - # Fail fast - if [ ! -f "${DOCKERFILE}" ]; then - echo "🚨 The Dockerfile '${DOCKERFILE}' for variant '${VARIANT}' doesn't exist." - ERROR=1 + # Fail fast + if [ ! -f "${DOCKERFILE}" ]; then + echo "🚨 The Dockerfile '${DOCKERFILE}' for variant '${VARIANT}' doesn't exist." + ERROR=1 - if [ -z "$DEBUG" ]; then - continue - else - echo "⚠️ Would skip this, but DEBUG is enabled." - fi + if [ -z "$DEBUG" ]; then + continue + else + echo "⚠️ Would skip this, but DEBUG is enabled." fi fi + fi - for BUILD in "${BUILDS[@]}"; do - echo "🛠 Building '$BUILD' from '$DOCKERFILE'" - case $BUILD in - release) - # build the latest release - # shellcheck disable=SC2068 - ./build-latest.sh $@ || ERROR=1 - ;; - prerelease) - # build the latest pre-release - # shellcheck disable=SC2068 - PRERELEASE=true ./build-latest.sh $@ || ERROR=1 - ;; - branches) - # build all branches - # shellcheck disable=SC2068 - ./build-branches.sh $@ || ERROR=1 - ;; - special) - # special build - # shellcheck disable=SC2068 - #SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@ || ERROR=1 - ;; - *) - echo "🚨 Unrecognized build '$BUILD'." + for BUILD in "${BUILDS[@]}"; do + echo "🛠 Building '$BUILD' from '$DOCKERFILE'" + case $BUILD in + release) + # build the latest release + # shellcheck disable=SC2068 + ./build-latest.sh $@ || ERROR=1 + ;; + prerelease) + # build the latest pre-release + # shellcheck disable=SC2068 + PRERELEASE=true ./build-latest.sh $@ || ERROR=1 + ;; + branches) + # build all branches + # shellcheck disable=SC2068 + ./build-branches.sh $@ || ERROR=1 + ;; + special) + # special build + # shellcheck disable=SC2068 + #SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@ || ERROR=1 + echo "✅ No special builds today." + ;; + *) + echo "🚨 Unrecognized build '$BUILD'." - if [ -z "$DEBUG" ]; then - exit 1 - else - echo "⚠️ Would exit here with code '1', but DEBUG is enabled." - fi - ;; - esac - done + if [ -z "$DEBUG" ]; then + exit 1 + else + echo "⚠️ Would exit here with code '1', but DEBUG is enabled." + fi + ;; + esac done -else - echo "❎ Not building anything." -fi +done exit $ERROR diff --git a/build-branches.sh b/build-branches.sh index 3bd93a9..91dbf22 100755 --- a/build-branches.sh +++ b/build-branches.sh @@ -3,7 +3,7 @@ echo "▶️ $0 $*" -if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then +if [ -n "${GITHUB_OAUTH_CLIENT_ID}" ] && [ -n "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then echo "🗝 Performing authenticated Github API calls." GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}" else diff --git a/build-latest.sh b/build-latest.sh index d903f8f..5732bd2 100755 --- a/build-latest.sh +++ b/build-latest.sh @@ -3,7 +3,7 @@ echo "▶️ $0 $*" -if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then +if [ -n "${GITHUB_OAUTH_CLIENT_ID}" ] && [ -n "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then echo "🗝 Performing authenticated Github API calls." GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}" else diff --git a/build.sh b/build.sh index ecd680d..a400f6f 100755 --- a/build.sh +++ b/build.sh @@ -6,9 +6,10 @@ echo "▶️ $0 $*" set -e if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then - echo "Usage: ${0} [--push]" - echo " branch The branch or tag to build. Required." - echo " --push Pushes built Docker image to docker hub." + echo "Usage: ${0} [--push|--push-only]" + echo " branch The branch or tag to build. Required." + echo " --push Pushes built the Docker image to the registry." + echo " --push-only Does not build. Only pushes the Docker image to the registry." echo "" echo "You can use the following ENV variables to customize the build:" echo " DEBUG If defined, the script does not stop when certain checks are unsatisfied." @@ -49,8 +50,9 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then echo " ARG FROM_TAG=latest" echo " FROM \$DOCKER_ORG/\$DOCKER_REPO:\$FROM_TAG" echo " Example: VARIANT=ldap will result in the tag 'latest-ldap' and the" - echo " Dockerfile 'Dockerfile.ldap' being used." - echo " Default: empty" + echo " Dockerfile './Dockerfile.ldap' being used." + echo " Exception: VARIANT=main will use the './Dockerfile' Dockerfile" + echo " Default: main" echo " HTTP_PROXY The proxy to use for http requests." echo " Example: http://proxy.domain.tld:3128" echo " Default: empty" @@ -95,7 +97,7 @@ esac DOCKER_TAG="${DOCKER_TAG-${DOCKER_ORG}/${DOCKER_REPO}:${TAG}}" # Checking which VARIANT to build -if [ -z "$VARIANT" ]; then +if [ "$VARIANT" == "main" ]; then DOCKERFILE="Dockerfile" else DOCKERFILE="Dockerfile.${VARIANT}" @@ -117,8 +119,8 @@ DOCKER_OPTS=("${DOCKER_OPTS[@]}") # caching is only ok for version tags case "${TAG}" in - v*) ;; - *) DOCKER_OPTS+=( "--no-cache" ) ;; + v*) ;; + *) DOCKER_OPTS+=( "--no-cache" ) ;; esac DOCKER_OPTS+=( "--pull" ) @@ -152,11 +154,13 @@ else DOCKER_CMD="echo docker" fi -echo "🐳 Building the Docker image '${DOCKER_TAG}' from the url '${URL}'." -$DOCKER_CMD build -t "${DOCKER_TAG}" "${DOCKER_BUILD_ARGS[@]}" "${DOCKER_OPTS[@]}" -f "${DOCKERFILE}" . -echo "✅ Finished building the Docker images '${DOCKER_TAG}'" +if [ "${2}" != "--push-only" ] ; then + echo "🐳 Building the Docker image '${DOCKER_TAG}' from the url '${URL}'." + $DOCKER_CMD build -t "${DOCKER_TAG}" "${DOCKER_BUILD_ARGS[@]}" "${DOCKER_OPTS[@]}" -f "${DOCKERFILE}" . + echo "✅ Finished building the Docker images '${DOCKER_TAG}'" +fi -if [ "${2}" == "--push" ] ; then +if [ "${2}" == "--push" ] || [ "${2}" == "--push-only" ] ; then echo "⏫ Pushing '${DOCKER_TAG}" $DOCKER_CMD push "${DOCKER_TAG}" echo "✅ Finished pushing the Docker image '${DOCKER_TAG}'." diff --git a/hooks/build b/hooks/build new file mode 100755 index 0000000..85bad75 --- /dev/null +++ b/hooks/build @@ -0,0 +1,5 @@ +#!/bin/bash + +. hooks/common + +run_build diff --git a/hooks/common b/hooks/common new file mode 100755 index 0000000..ba9a3b8 --- /dev/null +++ b/hooks/common @@ -0,0 +1,82 @@ +#!/bin/bash + +ensure_jq() { + echo "🛠🛠🛠 Installing JQ via apt-get" + [ -x "$(command -v jq)" ] || ( apt-get update && apt-get install -y jq ) +} + +ensure_dockerfile_present() { + if [ "${VARIANT}" == "main" ]; then + DOCKERFILE="Dockerfile" + else + DOCKERFILE="Dockerfile.${VARIANT}" + + # Fail fast + if [ ! -f "${DOCKERFILE}" ]; then + echo "🚨 The Dockerfile '${DOCKERFILE}' for variant '${VARIANT}' doesn't exist." + + if [ -z "$DEBUG" ]; then + exit 1 + else + echo "⚠️ Would skip this, but DEBUG is enabled." + fi + fi + + if [ "${DOCKERFILE}" != "${DOCKERFILE_PATH}" ]; then + echo "⚠️ The specified Dockerfile '${DOCKERFILE_PATH}' does not match the expected Dockerfile '${DOCKERFILE}'." + echo " This script will use '${DOCKERFILE}' and ignore '${DOCKERFILE_PATH}'." + fi + fi +} + +# Passes args to the scripts +run_build() { + echo "🐳🐳🐳 Building '${BUILD}' images, the '${VARIANT:-main}' variant" + case $BUILD in + release) + # build the latest release + # shellcheck disable=SC2068 + ./build-latest.sh $@ + ;; + prerelease) + # build the latest pre-release + # shellcheck disable=SC2068 + PRERELEASE=true ./build-latest.sh $@ + ;; + branches) + # build all branches + # shellcheck disable=SC2068 + ./build-branches.sh $@ + ;; + special) + # special build + # shellcheck disable=SC2068 + #SRC_ORG=lampwins TAG=webhooks-backend ./build.sh "feature/webhooks-backend" $@ + echo "✅ No special builds today." + ;; + *) + echo "🚨 Unrecognized build '$BUILD'." + + if [ -z "$DEBUG" ]; then + exit 1 + else + echo "⚠️ Would exit here with code '1', but DEBUG is enabled." + fi + ;; + esac +} + +echo "🤖🤖🤖 Preparing build" +export DOCKER_ORG="index.docker.io/cimnine" +export DOCKER_REPO=netbox-test +export DOCKERHUB_REPO=cimnine/netbox-test + +# mis-using the "${DOCKER_TAG}" variable as "branch to build" +export BUILD="${DOCKER_TAG%-*}" +export VARIANT="${DOCKER_TAG#*-}" + +unset DOCKER_TAG + +ensure_dockerfile_present + +ensure_jq diff --git a/hooks/push b/hooks/push new file mode 100755 index 0000000..0c0b65f --- /dev/null +++ b/hooks/push @@ -0,0 +1,5 @@ +#!/bin/bash + +. hooks/common + +run_build --push-only diff --git a/hooks/test b/hooks/test new file mode 100755 index 0000000..6c89c87 --- /dev/null +++ b/hooks/test @@ -0,0 +1,12 @@ +#!/bin/bash + +. hooks/common + +if [ "${VARIANT}" == "main" ] && [ "${BUILD}" == "BRANCHES" ]; then + echo "🐳🐳🐳 Testing" + docker-compose pull --parallel + docker-compose build + docker-compose run netbox ./manage.py test +else + echo "🐳🐳🐳 No tests are implemented for build '${BUILD}' with variant '${VARIANT}'." +fi From 09b4937b357d054b279cdd2eb9bae8bf105bc0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Wed, 6 Feb 2019 11:24:01 +0100 Subject: [PATCH 2/2] Update README --- README.md | 99 +++++++++++++++++++++---------------------------------- 1 file changed, 37 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 9fa588f..59dbdf3 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,19 @@ # netbox-docker -[![Build Status](https://travis-ci.org/ninech/netbox-docker.svg?branch=master)][travis] - -This repository houses the components needed to build NetBox as a Docker container. +This repository houses the components needed to build Netbox as a Docker container. Images built using this code are released to [Docker Hub][netbox-dockerhub] every night. Questions? Before opening an issue on Github, please join the [Network To Code][ntc-slack] and ask for help in our `#netbox-docker` channel. -[travis]: https://travis-ci.org/ninech/netbox-docker -[netbox-dockerhub]: https://hub.docker.com/r/ninech/netbox/tags/ +[netbox-dockerhub]: https://hub.docker.com/r/netboxcommunity/netbox/tags/ [ntc-slack]: http://slack.networktocode.com/ ## Quickstart -To get NetBox up and running: +To get Netbox up and running: ``` -$ git clone -b master https://github.com/ninech/netbox-docker.git +$ git clone -b master https://github.com/netbox-community/netbox-docker.git $ cd netbox-docker $ docker-compose pull $ docker-compose up -d @@ -44,7 +41,7 @@ Default credentials: * Password: **admin** * API Token: **0123456789abcdef0123456789abcdef01234567** -[docker-reception]: https://github.com/ninech/reception +[docker-reception]: https://github.com/nxt-engineering/reception ## Dependencies @@ -63,9 +60,9 @@ Read [Environment Variables in Compose][compose-env] to understand about the var (The easiest solution being simply adjusting that file.) To find all possible variables, have a look at the [configuration.docker.py][docker-config] and [docker-entrypoint.sh][entrypoint] files. -Generally, the environment variables are called the same as their respective NetBox configuration variables. +Generally, the environment variables are called the same as their respective Netbox configuration variables. Variables which are arrays are usually composed by putting all the values into the same environment variables with the values separated by a whitespace ("` `"). -For example defining `ALLOWED_HOSTS=localhost ::1 127.0.0.1` would allows access to NetBox through `http://localhost:8080`, `http://[::1]:8080` and `http://127.0.0.1:8080`. +For example defining `ALLOWED_HOSTS=localhost ::1 127.0.0.1` would allows access to Netbox through `http://localhost:8080`, `http://[::1]:8080` and `http://127.0.0.1:8080`. [compose-env]: https://docs.docker.com/compose/environment-variables/ @@ -74,7 +71,7 @@ For example defining `ALLOWED_HOSTS=localhost ::1 127.0.0.1` would allows access The default settings are optimized for (local) development environments. You should therefore adjust the configuration for production setups, at least the following variables: -* `ALLOWED_HOSTS`: Add all URLs that lead to your NetBox instance, space separated. E.g. `ALLOWED_HOSTS=netbox.mycorp.com server042.mycorp.com 2a02:123::42 10.0.0.42 localhost ::1 127.0.0.1` (It's good advice to always allow localhost connections for easy debugging, i.e. `localhost ::1 127.0.0.1`.) +* `ALLOWED_HOSTS`: Add all URLs that lead to your Netbox instance, space separated. E.g. `ALLOWED_HOSTS=netbox.mycorp.com server042.mycorp.com 2a02:123::42 10.0.0.42 localhost ::1 127.0.0.1` (It's good advice to always allow localhost connections for easy debugging, i.e. `localhost ::1 127.0.0.1`.) * `DB_*`: Use your own persistent database. Don't use the default passwords! * `EMAIL_*`: Use your own mailserver. * `MAX_PAGE_SIZE`: Use the recommended default of 1000. @@ -85,7 +82,7 @@ You should therefore adjust the configuration for production setups, at least th You may run this image in a cluster such as Docker Swarm, Kubernetes or OpenShift, but this is advanced level. -In this case, we encourage you to statically configure NetBox by starting from [NetBox's example config file][default-config], and mounting it into your container in the directory `/etc/netbox/config/` using the mechanism provided by your container platform (i.e. [Docker Swarm configs][swarm-config], [Kubernetes ConfigMap][k8s-config], [OpenShift ConfigMaps][openshift-config]). +In this case, we encourage you to statically configure Netbox by starting from [Netbox's example config file][default-config], and mounting it into your container in the directory `/etc/netbox/config/` using the mechanism provided by your container platform (i.e. [Docker Swarm configs][swarm-config], [Kubernetes ConfigMap][k8s-config], [OpenShift ConfigMaps][openshift-config]). But if you rather continue to configure your application through environment variables, you may continue to use [the built-in configuration file][docker-config]. We discourage storing secrets in environment variables, as environment variable are passed on to all sub-processes and may leak easily into other systems, e.g. error collecting tools that often collect all environment variables whenever an error occurs. @@ -102,11 +99,11 @@ If a secret is defined by an environment variable and in the respective file at * `NAPALM_PASSWORD`: `/run/secrets/napalm_password` * `REDIS_PASSWORD`: `/run/secrets/redis_password` -Please also consider [the advice about running NetBox in production](#production) above! +Please also consider [the advice about running Netbox in production](#production) above! -[docker-config]: https://github.com/ninech/netbox-docker/blob/master/docker/configuration.docker.py +[docker-config]: https://github.com/netbox-community/netbox-docker/blob/master/docker/configuration.docker.py [default-config]: https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/configuration.example.py -[entrypoint]: https://github.com/ninech/netbox-docker/blob/master/docker/docker-entrypoint.sh +[entrypoint]: https://github.com/netbox-community/netbox-docker/blob/master/docker/docker-entrypoint.sh [swarm-config]: https://docs.docker.com/engine/swarm/configs/ [swarm-secrets]: https://docs.docker.com/engine/swarm/secrets/ [openshift-config]: https://docs.openshift.org/latest/dev_guide/configmaps.html @@ -116,9 +113,9 @@ Please also consider [the advice about running NetBox in production](#production ### NAPALM Configuration -Since v2.1.0 NAPALM has been tightly integrated into NetBox. -NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. -To learn more about what NAPALM is and how it works, please see the documentation from the [libary itself][napalm-doc] or the documentation from [NetBox][netbox-napalm-doc] on how it is integrated. +Since v2.1.0 NAPALM has been tightly integrated into Netbox. +NAPALM allows Netbox to fetch live data from devices and return it to a requester via its REST API. +To learn more about what NAPALM is and how it works, please see the documentation from the [libary itself][napalm-doc] or the documentation from [Netbox][netbox-napalm-doc] on how it is integrated. To enable this functionality, simply complete the following lines in `netbox.env` (or appropriate secrets mechanism) : @@ -133,13 +130,13 @@ However, if you don't need this functionality, leave these blank. ### Customizable Reporting -NetBox includes [customized reporting][netbox-reports-doc] that allows the user to write Python code and determine the validity of the data within NetBox. +Netbox includes [customized reporting][netbox-reports-doc] that allows the user to write Python code and determine the validity of the data within Netbox. The `REPORTS_ROOT` variable is setup as a mapped directory within this Docker container to `/reports/` and includes the example directly from the documentation for `devices.py`. -However, it has been renamed to `devices.py.example` which prevents NetBox from recognizing it as a valid report. +However, it has been renamed to `devices.py.example` which prevents Netbox from recognizing it as a valid report. This was done to avoid unnessary issues from being opened when the default does not work for someone's expectations. To re-enable this default report, simply rename `devices.py.example` to `devices.py` and browse within the WebUI to `/extras/reports/`. -You can also dynamically add any other report to this same directory and NetBox will be able to see it without restarting the container. +You can also dynamically add any other report to this same directory and Netbox will be able to see it without restarting the container. [netbox-reports-doc]: https://netbox.readthedocs.io/en/stable/additional-features/reports/ @@ -147,7 +144,7 @@ You can also dynamically add any other report to this same directory and NetBox When using `docker-compose`, all the python scripts present in `/opt/netbox/startup_scripts` will automatically be executed after the application boots in the context of `./manage.py`. -That mechanism can be used for many things, e.g. to create NetBox custom fields: +That mechanism can be used for many things, e.g. to create Netbox custom fields: ```python # docker/startup_scripts/load_custom_fields.py @@ -173,7 +170,7 @@ if created: #### Initializers -Initializers are built-in startup scripts for defining NetBox custom fields, groups, users and many other resources. +Initializers are built-in startup scripts for defining Netbox custom fields, groups, users and many other resources. All you need to do is to mount you own `initializers` folder ([see `docker-compose.yml`][netbox-docker-compose]). Look at the [`initializers` folder][netbox-docker-initializers] to learn how the files must look like. @@ -197,8 +194,8 @@ text_field: - virtualization.models.VirtualMachine ``` -[netbox-docker-initializers]: https://github.com/ninech/netbox-docker/tree/master/initializers -[netbox-docker-compose]: https://github.com/ninech/netbox-docker/blob/master/docker-compose.yml +[netbox-docker-initializers]: https://github.com/netbox-community/netbox-docker/tree/master/initializers +[netbox-docker-compose]: https://github.com/netbox-community/netbox-docker/blob/master/docker-compose.yml ##### Available Groups for User/Group initializers @@ -211,12 +208,12 @@ echo "from django.contrib.auth.models import Permission\nfor p in Permission.obj #### Custom Docker Image -You can also build your own NetBox Docker image containing your own startup scripts, custom fields, users and groups +You can also build your own Netbox Docker image containing your own startup scripts, custom fields, users and groups like this: ``` ARG VERSION=latest -FROM ninech/netbox:$VERSION +FROM netboxcommunity/netbox:$VERSION COPY startup_scripts/ /opt/netbox/startup_scripts/ COPY initializers/ /opt/netbox/initializers/ @@ -224,10 +221,10 @@ COPY initializers/ /opt/netbox/initializers/ ## Netbox Version -The `docker-compose.yml` file is prepared to run a specific version of NetBox. +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. `VERSION` may be set to the name of -[any tag of the `ninech/netbox` Docker image on Docker Hub][netbox-dockerhub]. +[any tag of the `netboxcommunity/netbox` Docker image on Docker Hub][netbox-dockerhub]. ``` $ export VERSION=v2.2.6 @@ -235,7 +232,7 @@ $ docker-compose pull netbox $ docker-compose up -d ``` -You can also build a specific version of the NetBox image. This time, `VERSION` indicates any valid +You can also build a specific version of the Netbox image. This time, `VERSION` indicates any valid [Git Reference][git-ref] declared on [the 'digitalocean/netbox' Github repository][netbox-github]. Most commonly you will specify a tag or branch name. @@ -262,7 +259,7 @@ Custom values can be injected using environment variables, similar to the main c This section is a collection of some common issues and how to resolve them. If your issue is not here, look through [the existing issues][issues] and eventually create a new issue. -[issues]: (https://github.com/ninech/netbox-docker/issues) +[issues]: (https://github.com/netbox-community/netbox-docker/issues) ### Docker Compose basics @@ -271,7 +268,7 @@ If your issue is not here, look through [the existing issues][issues] and eventu Running `docker-compose logs -f netbox` will just show the logs for netbox. * You can stop everything using `docker-compose stop`. * You can clean up everything using `docker-compose down -v --remove-orphans`. **This will also remove any related data.** -* You can enter the shell of the running NetBox container using `docker-compose exec netbox /bin/bash`. Now you have access to `./manage.py`, e.g. to reset a password. +* You can enter the shell of the running Netbox container using `docker-compose exec netbox /bin/bash`. Now you have access to `./manage.py`, e.g. to reset a password. * To access the database run `docker-compose exec postgres sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'` * To create a database backup run `docker-compose exec postgres sh -c 'pg_dump -cU $POSTGRES_USER $POSTGRES_DB' | gzip > db_dump.sql.gz` * To restore that database backup run `gunzip -c db_dump.sql.gz | docker exec -i $(docker-compose ps -q postgres) sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'`. @@ -304,7 +301,7 @@ $ docker-compose logs -f nginx ### Getting a "Bad Request (400)" -> When connecting to the NetBox instance, I get a "Bad Request (400)" error. +> When connecting to the Netbox instance, I get a "Bad Request (400)" error. This usually happens when the `ALLOWED_HOSTS` variable is not set correctly. @@ -375,7 +372,7 @@ If you don't see anything happening after you triggered a webhook, double-check From time to time it might become necessary to re-engineer the structure of this setup. Things like the `docker-compose.yml` file or your Kubernetes or OpenShift configurations have to be adjusted as a consequence. Since April 2018 each image built from this repo contains a `NETBOX_DOCKER_PROJECT_VERSION` label. -You can check the label of your local image by running `docker inspect ninech/netbox:v2.3.1 --format "{{json .ContainerConfig.Labels}}"`. +You can check the label of your local image by running `docker inspect netboxcommunity/netbox:v2.3.1 --format "{{json .ContainerConfig.Labels}}"`. Compare the version with the list below to check whether a breaking change was introduced with that version. The following is a list of breaking changes of the `netbox-docker` project: @@ -386,41 +383,21 @@ The following is a list of breaking changes of the `netbox-docker` project: * 0.5.0: Alpine was updated to 3.8, `*.env` moved to `/env` folder * 0.4.0: In order to use Netbox webhooks you need to add Redis and a netbox-worker to your docker-compose.yml. * 0.3.0: Field `filterable: /etc/netbox/config` and `/etc/reports -> /etc/netbox/reports`. Fixes [#54](https://github.com/ninech/netbox-docker/issues/54). +* 0.2.0: Re-organized paths: `/etc/netbox -> /etc/netbox/config` and `/etc/reports -> /etc/netbox/reports`. Fixes [#54](https://github.com/netbox-community/netbox-docker/issues/54). * 0.1.0: Introduction of the `NETBOX_DOCKER_PROJECT_VERSION`. (Not a breaking change per se.) ## Rebuilding & Publishing images -`./build.sh` is used to rebuild the Docker image: - -``` -$ ./build.sh --help -Usage: ./build.sh [--push] - branch The branch or tag to build. Required. - --push Pushes built Docker image to docker hub. - -You can use the following ENV variables to customize the build: - BRANCH The branch to build. - Also used for tagging the image. - DOCKER_REPO The Docker registry (i.e. hub.docker.com/r/DOCKER_REPO/netbox) - Also used for tagging the image. - Default: ninech - SRC_REPO Which fork of netbox to use (i.e. github.com//netbox). - Default: digitalocean - URL Where to fetch the package from. - Must be a tar.gz file of the source code. - Default: https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz -``` +`./build.sh` can be used to rebuild the Docker image. See `./build.sh --help` for more information. ### Publishing Docker Images -New Docker Images are built and published every 24h by using travis: - -[![Build Status](https://travis-ci.org/ninech/netbox-docker.svg?branch=master)][travis] +New Docker Images are built and published every 24h on the [Docker Build Infrastructure](https://hub.docker.com/r/netboxcommunity/netbox/builds/). +`DOCKER_HUB.md` contains more information about the build infrastructure. ## Tests -To run the tests coming with NetBox, use the `docker-compose.yml` file as such: +To run the tests coming with Netbox, use the `docker-compose.yml` file as such: ``` $ docker-compose run netbox ./manage.py test @@ -428,6 +405,4 @@ $ docker-compose run netbox ./manage.py test ## About -This repository is currently maintained and funded by [nine](https://nine.ch), your cloud navigator. - -[![logo of the company 'nine'](https://logo.apps.at-nine.ch/Dmqied_eSaoBMQwk3vVgn4UIgDo=/trim/500x0/logo_claim.png)](https://www.nine.ch) +This repository is currently maintained and funded by [nxt](https://nxt.engineering).