├── .dockerignore ├── .github └── issue_template.md ├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── netdisco-backend └── Dockerfile ├── netdisco-base ├── Dockerfile ├── deployment.yml └── wait_to_start.sh ├── netdisco-demo ├── Dockerfile └── deployment.yml ├── netdisco-do └── Dockerfile ├── netdisco-postgresql ├── Dockerfile ├── netdisco-db-entrypoint.sh ├── netdisco-initdb.sh └── netdisco-updatedb.sh └── netdisco-web └── Dockerfile /.dockerignore: -------------------------------------------------------------------------------- 1 | .dockerignore 2 | .git 3 | docker-compose.yml 4 | LICENSE 5 | netdisco 6 | README.md 7 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 27 | 28 | ## Expected Behavior 29 | 30 | 31 | 32 | ## Current Behavior 33 | 34 | 35 | 36 | ## Possible Solution 37 | 38 | 39 | 40 | ## Steps to Reproduce (for bugs) 41 | 42 | 43 | 1. 44 | 2. 45 | 3. 46 | 4. 47 | 48 | ## Context 49 | 50 | 51 | 52 | ## Your Environment 53 | 54 | * netdisco container versions: 55 | * netdisco-postgresql: 56 | * netdisco-backend: 57 | * netdisco-web: 58 | * docker engine version: 59 | * docker-compose version: 60 | * host operating system: 61 | 62 | ## Config info (deployment.yml and docker env settings) 63 | 64 | 65 | 66 | ## Device information 67 | 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.pid 3 | test.pl 4 | *.tar.gz 5 | netdisco 6 | !netdisco-*/hooks/* 7 | .idea 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, Netdisco Project 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CPAN version](https://badge.fury.io/pl/App-Netdisco.svg)](https://metacpan.org/pod/App::Netdisco) 2 | [![Docker Image](https://img.shields.io/badge/docker%20images-ready-blue.svg)](https://store.docker.com/community/images/netdisco/netdisco) 3 | 4 | **Netdisco** is a web-based network management tool suitable for small to very large networks. IP and MAC address data is collected into a PostgreSQL database using SNMP, CLI, or device APIs. Some of the things you can do with Netdisco: 5 | 6 | * Locate a machine on the network by MAC or IP and show the switch port it lives at 7 | * Turn off a switch port, or change the VLAN or PoE status of a port 8 | * Inventory your network hardware by model, vendor, software and operating system 9 | * Pretty pictures of your network 10 | 11 | See the demo at: [https://netdisco2-demo.herokuapp.com/](https://netdisco2-demo.herokuapp.com/) 12 | 13 | Netdisco includes a lightweight web server for the interface, a backend daemon to gather data from your network, and a command line interface for troubleshooting. There is a simple configuration file in YAML format. 14 | 15 | ## Docker Deployment 16 | 17 | The containers need some directories present in the mounted volume. In a directory of your choice, create this structure and allow the netdisco uid in the container (901) to write into it: 18 | 19 | cd $directory_of_your_choice 20 | mkdir -p netdisco/{logs,config,nd-site-local} 21 | sudo chown -R 901:901 netdisco 22 | 23 | *(this step is necessary on Linux hosts and can be omitted in the OS X and Windows versions of Docker)* 24 | 25 | Download docker-compose.yml into the same directory and start everything 26 | 27 | curl -Ls -o docker-compose.yml https://tinyurl.com/nd2-dockercompose 28 | docker-compose up 29 | 30 | This will start the database, backend daemon, and web frontend listening on port 5000. If you have a device using the SNMP community `public`, enter it in the Netdisco homepage and click "Discover". 31 | 32 | The default configuration is available in `netdisco/config/deployment.yml`. The backend and web daemons will automatically restart when you save changes to this file. Logs are available in `netdisco/logs/`. 33 | 34 | The [netdisco-do](https://metacpan.org/dist/App-Netdisco/view/bin/netdisco-do) utility can be run like this (run it without `` to get help): 35 | 36 | docker-compose run netdisco-do 37 | 38 | Local web or backend plugins can be installed into `netdisco/nd-site-local/` as per [our documentation](https://github.com/netdisco/netdisco/wiki). Finally, the PostgreSQL data files are stored in `netdisco/pgdata/` and we do not advise touching them (unless you wish to reinitialize the system). 39 | 40 | The web frontend is initally configured to allow unauthenticated access with full admin rights. We suggest you visit the `Admin -> User Management` menu item, and set `no_auth: false` in `deployment.yml`, to remove this guest account and set up authenticated user access. 41 | 42 | Other username, password, database connection, and file locations, can all be set using [environment variables](https://github.com/netdisco/netdisco/wiki/Environment-Variables) described in our wiki. Of course the database container is optional and you can connect to an existing or external PostgreSQL server instead. 43 | 44 | You can change the password of the netdisco PostgreSQL user with `docker-compose exec netdisco-postgresql psql -U postgres -c "alter role netdisco password 'your new password';"` and updating it in `docker-compose.yml`. 45 | 46 | ## Docker Requirements 47 | 48 | * Docker 20.10.0 (Linux) or Docker Desktop 3.3.0 (Win/Mac) 49 | * docker-compose 1.28 50 | 51 | ## Getting Support 52 | 53 | We have several other pages with tips for [understanding and troubleshooting Netdisco](https://github.com/netdisco/netdisco/wiki/Troubleshooting), [tips and tricks for specific platforms](https://github.com/netdisco/netdisco/wiki/Vendor-Tips), and [all the configuration options](https://github.com/netdisco/netdisco/wiki/Configuration). 54 | 55 | You can also speak to someone in the [`#netdisco@libera`](https://kiwiirc.com/nextclient/irc.libera.chat/netdisco) IRC channel, or on the [community email list](https://lists.sourceforge.net/lists/listinfo/netdisco-users). 56 | 57 | ## Upgrading 58 | 59 | Pulling new images and recreating the containers with `docker-compose down ; docker-compose pull ; docker-compose up --force-recreate` is all there is to it. When our database image starts it always updates the DB schema to the latest release. To upgrade your own PostgreSQL database, run: 60 | 61 | docker-compose run --entrypoint=bin/netdisco-db-deploy netdisco-backend 62 | 63 | ## Credits 64 | 65 | Thanks to Ira W. Snyder and LBegnaud for inspiration. Thanks also to the PostgreSQL project for great examples of docker magic. We build with the support of the excellent GitHub Actions service. 66 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | netdisco-postgresql: 4 | image: netdisco/netdisco:latest-postgresql 5 | hostname: netdisco-postgresql 6 | volumes: 7 | - "./netdisco/pgdata:/var/lib/postgresql/data" 8 | 9 | netdisco-backend: 10 | image: netdisco/netdisco:latest-backend 11 | hostname: netdisco-backend 12 | init: true 13 | volumes: 14 | - "./netdisco/nd-site-local:/home/netdisco/nd-site-local" 15 | - "./netdisco/config:/home/netdisco/environments" 16 | - "./netdisco/logs:/home/netdisco/logs" 17 | environment: 18 | NETDISCO_DOMAIN: discover 19 | NETDISCO_DB_HOST: netdisco-postgresql 20 | depends_on: 21 | - netdisco-postgresql 22 | dns_opt: 23 | - 'ndots:0' 24 | - 'timeout:1' 25 | - 'retries:0' 26 | - 'attempts:1' 27 | - edns0 28 | - trustad 29 | 30 | netdisco-web: 31 | image: netdisco/netdisco:latest-web 32 | hostname: netdisco-web 33 | init: true 34 | volumes: 35 | - "./netdisco/nd-site-local:/home/netdisco/nd-site-local" 36 | - "./netdisco/config:/home/netdisco/environments" 37 | environment: 38 | NETDISCO_DOMAIN: discover 39 | NETDISCO_DB_HOST: netdisco-postgresql 40 | IPV: 4 41 | ports: 42 | - "5000:5000" 43 | depends_on: 44 | - netdisco-postgresql 45 | dns_opt: 46 | - 'ndots:0' 47 | - 'timeout:1' 48 | - 'retries:0' 49 | - 'attempts:1' 50 | - edns0 51 | - trustad 52 | 53 | netdisco-do: 54 | image: netdisco/netdisco:latest-do 55 | # use same hostname as backend to satisfy skiplist check (#68) 56 | hostname: netdisco-backend 57 | volumes: 58 | - "./netdisco/nd-site-local:/home/netdisco/nd-site-local" 59 | - "./netdisco/config:/home/netdisco/environments" 60 | environment: 61 | NETDISCO_DOMAIN: discover 62 | NETDISCO_DB_HOST: netdisco-postgresql 63 | depends_on: 64 | - netdisco-postgresql 65 | profiles: 66 | - cli-manual 67 | 68 | -------------------------------------------------------------------------------- /netdisco-backend/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | ARG TAG=latest 3 | FROM docker.io/netdisco/netdisco:${TAG}-base 4 | 5 | LABEL org.label-schema.name="netdisco-backend" \ 6 | org.label-schema.description="Polling Daemon for Netdisco" 7 | 8 | USER root 9 | RUN apk add --no-cache \ 10 | ca-certificates \ 11 | curl \ 12 | openssh-client \ 13 | tar 14 | 15 | WORKDIR /home/netdisco/netdisco-mibs 16 | RUN curl -sL https://api.github.com/repos/netdisco/netdisco-mibs/releases/latest | \ 17 | grep browser_download_url | xargs printf "curl -sL %s\n" | tail -1 | \ 18 | sh | tar --strip-components=1 -zxf - && \ 19 | chown -R netdisco:netdisco /home/netdisco/netdisco-mibs 20 | 21 | USER netdisco:netdisco 22 | WORKDIR /home/netdisco 23 | ENTRYPOINT ["/home/netdisco/bin/netdisco-backend"] 24 | CMD ["foreground"] 25 | -------------------------------------------------------------------------------- /netdisco-base/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | FROM docker.io/alpine:latest AS netdisco-builder-image 3 | 4 | ARG COMMITTISH=HEAD 5 | 6 | RUN apk add --no-cache \ 7 | ca-certificates \ 8 | curl \ 9 | findutils \ 10 | g++ \ 11 | gcc \ 12 | git \ 13 | jq \ 14 | libc6-compat \ 15 | musl-dev \ 16 | musl-obstack-dev \ 17 | make \ 18 | net-snmp-perl \ 19 | openssl-dev \ 20 | perl-crypt-rijndael \ 21 | perl-dbd-pg \ 22 | perl-dev \ 23 | perl-io-socket-ssl \ 24 | perl-ldap \ 25 | postgresql-client \ 26 | python3 \ 27 | tzdata \ 28 | openssh-client \ 29 | wget && \ 30 | apk fix --no-cache perl perl-dev 31 | 32 | WORKDIR /tmp 33 | RUN curl -sL -o /tmp/cpanm https://cpanmin.us/ && \ 34 | chmod +x /tmp/cpanm 35 | 36 | WORKDIR /home/netdisco 37 | RUN PERL5LIB='.' \ 38 | /tmp/cpanm --quiet --notest --local-lib ./perl5 \ 39 | "https://github.com/netdisco/netdisco.git@${COMMITTISH}" \ 40 | Dancer::Debug \ 41 | URL::Encode \ 42 | REST::Client && \ 43 | mv /home/netdisco /home/netdisco-build 44 | 45 | # ---------------------------------------------------------------------------- 46 | FROM docker.io/alpine:latest 47 | 48 | ARG BUILD_DATE 49 | ARG COMMITTISH=HEAD 50 | 51 | LABEL org.label-schema.docker.schema-version="1.0" \ 52 | org.label-schema.vendor="The Netdisco Project" \ 53 | org.label-schema.url="http://netdisco.org" \ 54 | org.label-schema.name="Netdisco Base" \ 55 | org.label-schema.description="Base Image for Netdisco" \ 56 | org.label-schema.usage="https://github.com/netdisco/netdisco-docker/blob/master/README.md" \ 57 | org.label-schema.version=${COMMITTISH} \ 58 | org.label-schema.vcs-ref=${COMMITTISH} \ 59 | org.label-schema.vcs-url="git://github.com/netdisco/netdisco.git" \ 60 | org.label-schema.build-date=${BUILD_DATE} \ 61 | org.netdisco.maintainer="The Netdisco Project" \ 62 | org.netdisco.version=${COMMITTISH} 63 | 64 | RUN apk add --no-cache \ 65 | findutils \ 66 | jq \ 67 | libc6-compat \ 68 | musl-dev \ 69 | musl-obstack-dev \ 70 | net-snmp-perl \ 71 | expect \ 72 | expect-dev \ 73 | perl-crypt-rijndael \ 74 | perl-dbd-pg \ 75 | perl-io-socket-ssl \ 76 | perl-ldap \ 77 | perl-json \ 78 | perl-lwp-protocol-https \ 79 | perl-file-slurp \ 80 | perl-regexp-common \ 81 | perl-regexp-common-net-cidr \ 82 | perl-regexp-ipv6 \ 83 | perl-file-sharedir \ 84 | postgresql-client \ 85 | python3 \ 86 | tzdata \ 87 | shadow 88 | 89 | RUN groupadd -r netdisco -g 901 && \ 90 | useradd -u 901 -r -p x -g netdisco -m -d /home/netdisco -s /bin/ash -c "netdisco user" netdisco 91 | 92 | USER netdisco:netdisco 93 | RUN for tgt in bin environments nd-site-local logs; \ 94 | do mkdir /home/netdisco/$tgt; done && \ 95 | ln -s /dev/stdout /home/netdisco/logs/netdisco-backend.log && \ 96 | ln -s /dev/stdout /home/netdisco/logs/netdisco-web.log 97 | 98 | 99 | COPY --chown=netdisco:netdisco --from=netdisco-builder-image \ 100 | /home/netdisco-build /home/netdisco/ 101 | 102 | # replace default config with one that works better for docker install 103 | COPY --chown=netdisco:netdisco deployment.yml \ 104 | /home/netdisco/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml 105 | COPY --chown=netdisco:netdisco wait_to_start.sh /home/netdisco/bin/ 106 | 107 | RUN for tgt in /home/netdisco/perl5/bin/netdisco-*; \ 108 | do ln -sf $tgt /home/netdisco/bin/; done && \ 109 | ln -sf /home/netdisco/perl5/bin/localenv /home/netdisco/bin/ 110 | 111 | RUN `/home/netdisco/bin/localenv perl -MAlien::ultraviolet -e 'print Alien::ultraviolet->uv'` \ 112 | --no-cache --no-progress --quiet --project \ 113 | `/home/netdisco/bin/localenv perl -MFile::ShareDir -e 'print File::ShareDir::dist_dir("App-Netdisco") ."/python/netdisco"'` \ 114 | sync 115 | 116 | WORKDIR /home/netdisco 117 | ENV PATH="/home/netdisco/bin:$PATH" 118 | ENV SHELL=/bin/ash 119 | 120 | ## volumes can be optional, and controlled by docker-compose file 121 | # VOLUME ["/home/netdisco/environments", "/home/netdisco/nd-site-local", "/home/netdisco/logs"] 122 | 123 | CMD ["ash"] 124 | -------------------------------------------------------------------------------- /netdisco-base/deployment.yml: -------------------------------------------------------------------------------- 1 | # 2 | # NETDISCO 2 CONFIGURATION FILE 3 | # 4 | # Settings in this file override share/config.yml 5 | # 6 | # https://github.com/netdisco/netdisco/wiki/Configuration has 7 | # in depth explanations about each setting. 8 | 9 | # ------------------ 10 | # ESSENTIAL SETTINGS 11 | # ------------------ 12 | 13 | database: 14 | name: 'netdisco' 15 | user: 'netdisco' 16 | pass: 'netdisco' 17 | #host: 'localhost' 18 | 19 | # ------------------------ 20 | # DOCKER SPECIFIC SETTINGS 21 | # ------------------------ 22 | 23 | # Allows you to put plugin code in /lib, and templates in /share/views, 24 | # within the nd-site-local directory. 25 | site_local_files: true 26 | 27 | # set to true to globally disable authentication/login. 28 | # the user called "guest" has full admin/port-control rights. 29 | # this user will be created by default on your first deploy. 30 | no_auth: true 31 | 32 | # -------------------- 33 | # RECOMMENDED SETTINGS 34 | # -------------------- 35 | 36 | # Device authentication settings 37 | # define snmp communities and ssh credentials here 38 | # ```````````````````````````````````````````````` 39 | device_auth: 40 | - tag: 'default_v2_readonly' 41 | community: 'public' 42 | read: true 43 | write: false 44 | # - tag: 'default_v2_for_write' 45 | # community: 'private' 46 | # read: false 47 | # write: true 48 | 49 | 50 | 51 | # will be stripped from fqdn when displayed in the web UI 52 | # also, do not forget the leading dot. 53 | # ``````````````````````````````````````````````````````` 54 | #domain_suffix: ['.example.com'] 55 | 56 | 57 | # ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸ 58 | # ¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸ 59 | 60 | 61 | # --------------------------------------------------------------- 62 | # OTHER INTERESTING SETTINGS WHERE THE DEFAULTS ARE PROBABLY OKAY 63 | # --------------------------------------------------------------- 64 | 65 | # discover Wireless Access Points, but not IP Phones 66 | # usually these are visible as device neighbors but don't support 67 | # SNMP, which just clogs up the job queue. 68 | # ``````````````````````````````````````````````````````````````` 69 | #discover_waps: true 70 | #discover_phones: false 71 | 72 | # this is the schedule for automatically keeping netdisco up-to-date; 73 | # these are good defaults, so only uncomment if needing to change. 74 | # (or set "schedule: null" if you wish to disable the scheduler) 75 | # ```````````````````````````````````````````````````````````````````` 76 | #schedule: 77 | # discoverall: 78 | # when: '5 7 * * *' 79 | # macwalk: 80 | # when: 81 | # min: 20 82 | # arpwalk: 83 | # when: 84 | # min: 50 85 | # nbtwalk: 86 | # when: '0 8,13,21 * * *' 87 | # expire: 88 | # when: '30 23 * * *' 89 | 90 | # number of SNMP workers to run in parallel (in netdisco-backend). 91 | # the default is twice the number of CPU cores. increase this if 92 | # your system has few cores and the schedule is taking too long. 93 | # ``````````````````````````````````````````````````````````````` 94 | #workers: 95 | # tasks: 'AUTO * 2' 96 | 97 | # number of parallel DNS queries for node names 98 | # ````````````````````````````````````````````` 99 | #dns: 100 | # max_outstanding: 50 101 | -------------------------------------------------------------------------------- /netdisco-base/wait_to_start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo $WAIT_COMMAND 4 | echo $WAIT_START_CMD 5 | 6 | is_ready() { 7 | eval "$WAIT_COMMAND" 8 | } 9 | 10 | # wait until is ready 11 | i=0 12 | while ! is_ready; do 13 | i=`expr $i + 1` 14 | if [ $i -ge $WAIT_LOOPS ]; then 15 | echo "$(date) - still not ready, giving up" 16 | exit 1 17 | fi 18 | echo "$(date) - waiting to be ready" 19 | sleep $WAIT_SLEEP 20 | done 21 | 22 | #start the script 23 | exec $WAIT_START_CMD 24 | -------------------------------------------------------------------------------- /netdisco-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | ARG TAG=latest 3 | FROM docker.io/netdisco/netdisco:${TAG}-web 4 | 5 | LABEL org.label-schema.name="netdisco-demo" \ 6 | org.label-schema.description="Heroku Demo instance for Netdisco" 7 | 8 | COPY --chown=netdisco:netdisco deployment.yml \ 9 | /home/netdisco/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml 10 | 11 | ENTRYPOINT ["/home/netdisco/bin/netdisco-web"] 12 | CMD ["foreground"] 13 | -------------------------------------------------------------------------------- /netdisco-demo/deployment.yml: -------------------------------------------------------------------------------- 1 | # 2 | # NETDISCO 2 CONFIGURATION FILE 3 | # 4 | 5 | # allow environment variables to be used instead 6 | database: {} 7 | 8 | # heroku hosts in https 9 | session_secure: true 10 | 11 | host_groups: 12 | spines: 13 | - 192.168.0.21 14 | - 192.168.0.22 15 | leaves: 16 | - 192.168.0.11 17 | - 192.168.0.12 18 | - 192.168.0.13 19 | - 192.168.0.14 20 | 21 | host_group_displaynames: 22 | spines: 'Spine Routers' 23 | leaves: 'Leaf Routers' 24 | 25 | # disable authentication/login. 26 | no_auth: true 27 | check_userlog: false 28 | 29 | # disable user account actions and device delete 30 | defanged_admin: 'false_admin' 31 | -------------------------------------------------------------------------------- /netdisco-do/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | ARG TAG=latest 3 | FROM docker.io/netdisco/netdisco:${TAG}-backend 4 | 5 | LABEL org.label-schema.name="netdisco-do" \ 6 | org.label-schema.description="CLI App for Netdisco" 7 | 8 | ENTRYPOINT ["/home/netdisco/bin/netdisco-do"] 9 | CMD [""] 10 | -------------------------------------------------------------------------------- /netdisco-postgresql/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | FROM docker.io/postgres:13.4-alpine 3 | 4 | ARG BUILD_DATE 5 | ARG COMMITTISH=HEAD 6 | 7 | LABEL org.label-schema.docker.schema-version="1.0" \ 8 | org.label-schema.vendor="The Netdisco Project" \ 9 | org.label-schema.url="http://netdisco.org" \ 10 | org.label-schema.name="Netdisco's PostgreSQL" \ 11 | org.label-schema.description="Database for Netdisco" \ 12 | org.label-schema.usage="https://github.com/netdisco/netdisco-docker/blob/master/README.md" \ 13 | org.label-schema.version=${COMMITTISH} \ 14 | org.label-schema.vcs-ref=${COMMITTISH} \ 15 | org.label-schema.vcs-url="git://github.com/netdisco/netdisco.git" \ 16 | org.label-schema.build-date=${BUILD_DATE} \ 17 | org.netdisco.maintainer="The Netdisco Project" \ 18 | org.netdisco.version=${COMMITTISH} 19 | 20 | RUN apk add --no-cache \ 21 | curl \ 22 | tzdata \ 23 | tar 24 | 25 | COPY netdisco-initdb.sh /docker-entrypoint-initdb.d/ 26 | COPY netdisco-db-entrypoint.sh netdisco-updatedb.sh /usr/local/bin/ 27 | RUN chmod +x /usr/local/bin/netdisco-* 28 | 29 | WORKDIR /var/lib/postgresql/netdisco-sql 30 | RUN curl -sL "https://api.github.com/repos/netdisco/netdisco/tarball/${COMMITTISH}" | \ 31 | tar --wildcards --strip-components=3 -zx '*App-Netdisco-DB-*' && \ 32 | curl -sLO "https://raw.githubusercontent.com/netdisco/upstream-sources/refs/heads/master/bootstrap/netdisco-lookup-tables.sql" && \ 33 | curl -sLO "https://raw.githubusercontent.com/netdisco/netdisco/master/lib/App/Netdisco/DB.pm" 34 | 35 | VOLUME ["/var/lib/postgresql/data"] 36 | 37 | WORKDIR / 38 | ENTRYPOINT ["/usr/local/bin/netdisco-db-entrypoint.sh"] 39 | CMD ["postgres"] 40 | -------------------------------------------------------------------------------- /netdisco-postgresql/netdisco-db-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export COL='\033[0;35m' 4 | export NC='\033[0m' 5 | 6 | su=( su-exec "${PGUSER:-postgres}" ) 7 | 8 | if [ ! -s "${PGDATA}/PG_VERSION" ]; then 9 | exec env POSTGRES_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) \ 10 | /usr/local/bin/docker-entrypoint.sh "$@" 11 | fi 12 | 13 | if [ "$1" = 'postgres' ]; then 14 | echo >&2 -e "${COL}netdisco-db-entrypoint: starting pg privately to container${NC}" 15 | "${su[@]}" pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost' -c log_min_error_statement=LOG -c log_min_messages=LOG" -w start 16 | 17 | /usr/local/bin/netdisco-updatedb.sh 18 | 19 | echo >&2 -e "${COL}netdisco-db-entrypoint: shutting down pg (will restart, listening for clients)${NC}" 20 | "${su[@]}" pg_ctl -D "$PGDATA" -m fast -w stop 21 | fi 22 | 23 | exec /usr/local/bin/docker-entrypoint.sh "$@" 24 | -------------------------------------------------------------------------------- /netdisco-postgresql/netdisco-initdb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NETDISCO_DB_NAME="${NETDISCO_DB_NAME:-netdisco}" 4 | NETDISCO_DB_USER="${NETDISCO_DB_USER:-netdisco}" 5 | NETDISCO_DB_PASS="${NETDISCO_DB_PASS:-netdisco}" 6 | 7 | export COL='\033[0;35m' 8 | export NC='\033[0m' 9 | 10 | PGUSER="${PGUSER:-postgres}" 11 | psql=( psql -X -v ON_ERROR_STOP=0 -v ON_ERROR_ROLLBACK=on ) 12 | psql+=( --username=${PGUSER} ) 13 | 14 | echo >&2 -e "${COL}netdisco-db-entrypoint: configuring Netdisco user and db${NC}" 15 | "${psql[@]}" -c "CREATE ROLE ${NETDISCO_DB_USER} WITH LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE PASSWORD '${NETDISCO_DB_PASS}'" 16 | createdb --username=${PGUSER} -O ${NETDISCO_DB_USER} ${NETDISCO_DB_NAME} 17 | 18 | echo >&2 -e "${COL}netdisco-db-entrypoint: restarting pg privately to container${NC}" 19 | "${su[@]}" pg_ctl -D "$PGDATA" -m fast -w stop 20 | "${su[@]}" pg_ctl -D "$PGDATA" -o "-c listen_addresses='localhost' -c log_min_error_statement=LOG -c log_min_messages=LOG" -w start 21 | 22 | /usr/local/bin/netdisco-updatedb.sh 23 | -------------------------------------------------------------------------------- /netdisco-postgresql/netdisco-updatedb.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NETDISCO_DB_NAME="${NETDISCO_DB_NAME:-netdisco}" 4 | NETDISCO_DB_USER="${NETDISCO_DB_USER:-netdisco}" 5 | NETDISCO_DB_PASS="${NETDISCO_DB_PASS:-netdisco}" 6 | NETDISCO_ADMIN_USER="${NETDISCO_ADMIN_USER:-guest}" 7 | NETDISCO_DB_CONNSTR="${NETDISCO_DB_CONNSTR:-''}" 8 | 9 | export COL='\033[0;35m' 10 | export NC='\033[0m' 11 | 12 | psql=( psql -X -v ON_ERROR_STOP=0 -v ON_ERROR_ROLLBACK=on ) 13 | if [[ -z "$NETDISCO_DB_CONNSTR" ]]; then 14 | psql+=( ${NETDISCO_DB_CONNSTR} ) 15 | else 16 | psql+=( --username ${NETDISCO_DB_USER} --dbname ${NETDISCO_DB_NAME} ) 17 | fi 18 | 19 | echo >&2 -e "${COL}netdisco-db-entrypoint: bringing schema up-to-date${NC}" 20 | ls -1 /var/lib/postgresql/netdisco-sql/App-Netdisco-DB-* | \ 21 | xargs -n1 basename | sort -n -t '-' -k4 | \ 22 | while read file; do 23 | "${psql[@]}" -f "/var/lib/postgresql/netdisco-sql/$file" >/dev/null 2>&1 24 | done 25 | 26 | echo >&2 -e "${COL}netdisco-db-entrypoint: importing OUI${NC}" 27 | "${psql[@]}" -f /var/lib/postgresql/netdisco-sql/netdisco-lookup-tables.sql 28 | 29 | echo >&2 -e "${COL}netdisco-db-entrypoint: marking schema as up-to-date${NC}" 30 | MAXSCHEMA=$(grep VERSION /var/lib/postgresql/netdisco-sql/DB.pm | sed 's/[^0-9]//g') 31 | STAMP=$(date '+v%Y%m%d_%H%M%S.000') 32 | "${psql[@]}" -c "CREATE TABLE dbix_class_schema_versions (version varchar(10) PRIMARY KEY, installed varchar(20) NOT NULL)" >/dev/null 2>&1 33 | "${psql[@]}" -c "INSERT INTO dbix_class_schema_versions VALUES ('${MAXSCHEMA}', '${STAMP}')" >/dev/null 2>&1 34 | 35 | echo >&2 -e "${COL}netdisco-db-entrypoint: adding admin user if none exists${NC}" 36 | if [ -z $("${psql[@]}" -A -t -c "SELECT 1 FROM users WHERE admin") ]; then 37 | "${psql[@]}" -c "INSERT INTO users (username, port_control, admin) VALUES ('${NETDISCO_ADMIN_USER}', true, true)" 38 | fi 39 | 40 | echo >&2 -e "${COL}netdisco-db-entrypoint: adding session key if none exists${NC}" 41 | if [ -z $("${psql[@]}" -A -t -c "SELECT 1 FROM sessions WHERE id = 'dancer_session_cookie_key'") ]; then 42 | "${psql[@]}" -c "INSERT INTO sessions (id, a_session) VALUES ('dancer_session_cookie_key', md5(random()::text))" 43 | fi 44 | 45 | echo >&2 -e "${COL}netdisco-db-entrypoint: queueing stats job${NC}" 46 | "${psql[@]}" -c "INSERT INTO admin (action, status) VALUES ('stats', 'queued')" 47 | -------------------------------------------------------------------------------- /netdisco-web/Dockerfile: -------------------------------------------------------------------------------- 1 | # vim: ft=Dockerfile 2 | ARG TAG=latest 3 | FROM docker.io/netdisco/netdisco:${TAG}-base 4 | 5 | LABEL org.label-schema.name="netdisco-web" \ 6 | org.label-schema.description="Web Frontend for Netdisco" 7 | 8 | EXPOSE 5000 9 | ENTRYPOINT ["/home/netdisco/bin/netdisco-web"] 10 | CMD ["foreground"] 11 | --------------------------------------------------------------------------------