From c6b3081b12e220a084f43fe370db1ab5f6169c2b Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:01:29 +0100 Subject: [PATCH 1/7] Add gunicorn library --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 912bbf4..fac9f13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ requests ttp textfsm jinja2 +gunicorn From 78e7c25ebc4ae62eb2f8a32958cc983baffd989f Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:01:45 +0100 Subject: [PATCH 2/7] Update Dockerfile --- Dockerfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6483f88..a6c19f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine +FROM python:3.9-slim -COPY requirements.txt /app -RUN pip3 install -r requirements.txt +WORKDIR /app +COPY requirements.txt /app COPY . /app + +RUN pip3 install -r requirements.txt + +CMD ./run.sh From d3c71f6f834286e00df9ef47ae221ecf2be0d45c Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:02:01 +0100 Subject: [PATCH 3/7] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 02d0308..1dc0b9d 100644 --- a/README.md +++ b/README.md @@ -27,5 +27,20 @@ for ```netbox inventory``` ensure ```config.json``` has the following lines ``` configure ```"inventory_netbox.json"``` with your netbox params accordingly + +### docker +to use ```docker``` you can either use the default ```config.json``` file or set some env vars: +``` + "export NPA_NETPALM_API_KEY=API_KEY_HERE" + export NPA_NETPALM_SERVER=SERVER_HERE" + export NPA_NETPALM_PORT=PORT_HERE + export NPA_INVENTORY_FILE=INVENTORY_FILE_DIR_HERE + export NPA_INVENTORY_TYPE=INVENTORY_TYPE_HERE +``` +build/run: +``` +sudo docker-compose up -d --build +``` + ### notice - project currently just a poc in progress, use at your own leisure From 731a28a012e797f27106abf4f1efa5d0df41205f Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:02:49 +0100 Subject: [PATCH 4/7] Add ENV var support for inventory type/file --- backend/confload/confload.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/confload/confload.py b/backend/confload/confload.py index 2093203..5097e78 100644 --- a/backend/confload/confload.py +++ b/backend/confload/confload.py @@ -1,7 +1,7 @@ import json -import requests -import os +import os +import requests DEFAULT_CONFIG_FILENAME = "config.json" DEFAULT_INVENTORY_FILENAME = "inventory_local.json" @@ -33,8 +33,8 @@ def __init__(self, config_filename=None, inventory_filename=None): def get_inventory(self): """ load the inventory """ - inv_type = self.config_data.get("inventory_type") - inv_file = self.config_data.get("inventory_file") + inv_type = self.load_value("inventory_type") + inv_file = self.load_value("inventory_file") if inv_type == "local": if self.inventory_filename is None: From 9b8a472409dd1195e258d6a24aebd6ebc8b82284 Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:03:15 +0100 Subject: [PATCH 5/7] Add docker-compose.yml --- docker-compose.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1755176 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +--- +version: "3.7" +services: + netpalm-admin: + build: + context: "." + dockerfile: "Dockerfile" + image: "netpalm-admin" + container_name: "netpalm-admin" + environment: + - "PUID=1000" + - "PGID=1000" + - "TZ=UTC" + - "UMASK_SET=022" + - "NPA_NETPALM_API_KEY" + - "NPA_NETPALM_SERVER" + - "NPA_NETPALM_PORT" + - "NPA_INVENTORY_FILE" + - "NPA_INVENTORY_TYPE" + ports: + - "10001:10001" + restart: "unless-stopped" From e0973491b78e937ba2035fd201274fbcb016c257 Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:03:38 +0100 Subject: [PATCH 6/7] Add run.sh for docker --- run.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..c0a5b16 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh +gunicorn -w 4 ` +`--bind 0.0.0.0:10001 ` +`netpalm-admin:app --log-level debug From ece4f35040826656d68025c1d2262d4f68f51534 Mon Sep 17 00:00:00 2001 From: tom0010 <41154665+tom0010@users.noreply.github.com> Date: Thu, 20 May 2021 15:06:44 +0100 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dc0b9d..0c67acf 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ configure ```"inventory_netbox.json"``` with your netbox params accordingly ### docker to use ```docker``` you can either use the default ```config.json``` file or set some env vars: ``` - "export NPA_NETPALM_API_KEY=API_KEY_HERE" + export NPA_NETPALM_API_KEY=API_KEY_HERE export NPA_NETPALM_SERVER=SERVER_HERE" export NPA_NETPALM_PORT=PORT_HERE export NPA_INVENTORY_FILE=INVENTORY_FILE_DIR_HERE