Skip to content

Commit

Permalink
test: Add script to load netbox-docker variables
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed Feb 10, 2021
1 parent 4e3d637 commit e167ef6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/netbox_docker_variables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

TMP_JSON_FILE="/tmp/docker.json"

if ! which jq > /dev/null; then
echo "This script need jq binary to work"
fi

curl -sq --unix-socket /var/run/docker.sock http://localhost/containers/json -o ${TMP_JSON_FILE}

DOCKER_COUNT=$(cat ${TMP_JSON_FILE} | jq ".[] | length" | uniq)

for ((i = 0 ; i < ${DOCKER_COUNT} ; i++)); do
IMAGE_NAME=$(cat /tmp/docker.json | jq .[$i].Image | xargs | cut -d":" -f1)

if [ "${IMAGE_NAME}" == "nginx" ]; then
PORTS_COUNT=$(cat /tmp/docker.json | jq ".[$i].Ports | length")

for ((j = 0 ; j < ${PORTS_COUNT} ; j++)); do
PORT=$(cat /tmp/docker.json | jq .[$i].Ports[$j].PublicPort | xargs)
if [ "$PORT" != "null" ]; then
PUBLIC_PORT=$PORT
fi
done
fi
done

export NETBOX_URL="127.0.0.1:$PUBLIC_PORT"
export NETBOX_SCHEME="http"
export NETBOX_TOKEN="0123456789abcdef0123456789abcdef01234567"

0 comments on commit e167ef6

Please sign in to comment.