fixes Dockerfile and updates README

refs: #168
This commit is contained in:
ricardo.bartels@telekom.de
2022-04-07 22:41:55 +02:00
parent c0e1895382
commit e5d4225cad
3 changed files with 30 additions and 18 deletions
+11 -6
View File
@@ -4,20 +4,25 @@ FROM python:3.9-slim-bullseye
RUN apt-get update && apt-get -y upgrade && apt-get install -y git-core
# Prepare the application
COPY . /opt
RUN cd /opt && \
pip3 install --upgrade pip setuptools && \
COPY . /app
# disable upgrading setup tools due to bug in setuptools and automation sdk
# once this is fixed, switch back to: pip3 install --upgrade pip setuptools
RUN cd /app && \
pip3 install --upgrade pip && \
pip3 install --force-reinstall 'setuptools==60.10.0' && \
pip3 install -r requirements.txt && \
pip3 install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
# Run the application
WORKDIR /opt
WORKDIR /app
RUN set -eux; \
addgroup --gid 1000 netbox-sync; \
adduser --uid 1000 --ingroup netbox-sync --shell /bin/sh --home /home/netbox-sync --disabled-password netbox-sync
adduser --uid 1000 --ingroup netbox-sync --shell /bin/sh --home /home/netbox-sync --disabled-password \
--gecos "netbox-sync,0815,2342,9001" netbox-sync
RUN chown -R netbox-sync:netbox-sync /opt
RUN chown -R netbox-sync:netbox-sync /app
USER netbox-sync
+17 -10
View File
@@ -49,18 +49,18 @@ This ensures stale objects are removed from NetBox keeping an accurate current s
## RedHat based OS
* on RedHat/CentOS 7 you need to install python3.6 and pip from EPEL first
* on RedHat/CentOS 8 systems the package name changed to `python3-pip`
```
```shell
yum install python36-pip
```
## Ubuntu 18.04 & 20.04
```
```shell
apt-get update && apt-get install python3-venv
```
## Clone repo and install dependencies
* download and setup of virtual environment
```
```shell
cd /opt
git clone https://github.com/bb-Ricardo/netbox-sync.git
cd netbox-sync
@@ -72,34 +72,41 @@ pip3 install -r requirements.txt || pip install -r requirements.txt
### VMware tag sync (if necessary)
The `vsphere-automation-sdk` must be installed if tags should be synced from vCenter to NetBox
* assuming we are still in an activated virtual env
```
```shell
pip install --upgrade pip setuptools
pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
```
## Docker
Run the application in docker container
Run the application in a docker container. You can build it yourself or use the ones from docker hub.
* The application working directory is ```/opt```
Available here: bbricardo/netbox-sync
* The application working directory is ```/app```
* Required to mount your ```settings.ini```
To build it by yourself just run:
```shell
docker build -t bbricardo/netbox-sync:latest .
```
docker build -t netbox-sync .
docker run --rm -it -v $(pwd)/settings.ini:/opt/settings.ini netbox-sync [some args...]
To start the container just use:
```shell
docker run --rm -it -v $(pwd)/settings.ini:/app/settings.ini bbricardo/netbox-sync:latest
```
## Kubernetes
Run the containerized application in a kubernetes cluster
* Build the container image following the docker instructions above
* Build the container image
* Tag and push the image to a container registry you have access to
* Create a secret from the settings.ini
* Update the image field in the manifest
* Deploy the manifest to your k8s cluster and check the job is running
```
```shell
docker build -t netbox-vsphere-sync .
docker image tag netbox-vsphere-sync your-registry.host/netbox-vsphere-sync:v1.2.0
docker image push your-registry.host/netbox-vsphere-sync:v1.2.0
+2 -2
View File
@@ -12,11 +12,11 @@ spec:
spec:
containers:
- name: netbox-vsphere-sync
image: your.container.registry/netbox-vsphere-sync:v1.2.0
image: bbricardo/netbox-sync:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: netbox-vsphere-sync
mountPath: /opt/settings.ini
mountPath: /app/settings.ini
subPath: settings.ini
volumes:
- name: netbox-vsphere-sync