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 diff --git a/README.md b/README.md index 02d0308..0c67acf 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 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: 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" 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 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