Skip to content

Commit

Permalink
Merge pull request #1 from oliverisaac/dockerize
Browse files Browse the repository at this point in the history
Dockerize the script
  • Loading branch information
MariusBrill authored Feb 4, 2022
2 parents 83ffa56 + 3a67144 commit b833361
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.yml
*.csv
script/__pycache__**
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.9-slim

COPY requirements.txt /requirements.txt

RUN pip install -r /requirements.txt && mkdir /app

WORKDIR /app

COPY LICENSE run.py /app/
COPY script /app/script

ENTRYPOINT [ "python3", "./run.py" ]
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
DOCKER_REPO ?= DOCKERHUB_USER/grafana-ldap-sync-script
DOCKER_TAG ?= v1.0

init:
pip install -r requirements.txt

Expand All @@ -15,3 +18,17 @@ bundle:

test:
nosetests tests

docker-build:
docker build -t ${DOCKER_REPO}:latest .
docker tag ${DOCKER_REPO}:latest ${DOCKER_REPO}:${DOCKER_TAG}

docker-push: docker-build
docker push ${DOCKER_REPO}:latest
docker push ${DOCKER_REPO}:${DOCKER_TAG}

docker-run: docker-build
docker run --mount 'type=bind,source=${PWD},target=/data' ${DOCKER_REPO}:${DOCKER_TAG} --config /data/config.yml --bind /data/example.csv

docker-explore: docker-build
docker run -it --entrypoint /bin/bash --mount 'type=bind,source=${PWD},target=/data' ${DOCKER_REPO}:${DOCKER_TAG} -o vi
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ config:

# URL of the target grafana-server.
url: localhost:3000
# Protocol to use when connecting to grafana (http, https)
protocol: http
# User account name with admin rights on target grafana-server.
user: admin
# Password of account with admin rights on target grafana-server.
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setup_logger():
)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)

if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions script/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, config_path):

GRAFANA_AUTH = ""
GRAFANA_URL = ""
GRAFANA_PROTOCOL = "http"

LDAP_SERVER_URL = ""
LDAP_PORT = ""
Expand Down Expand Up @@ -46,6 +47,8 @@ def load_config(self, config_path):
config["grafana"]["password"]
)
self.GRAFANA_URL = config["grafana"]["url"]
if config["grafana"]["protocol"]:
self.GRAFANA_PROTOCOL = config["grafana"]["protocol"]

self.LDAP_SERVER_URL = config["ldap"]["url"]
self.LDAP_PORT = config["ldap"]["port"]
Expand Down
3 changes: 2 additions & 1 deletion script/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def setup_grafana(config_dict):
configuration = config_dict
grafana_api = GrafanaApi(
auth=configuration.GRAFANA_AUTH,
host=configuration.GRAFANA_URL
host=configuration.GRAFANA_URL,
protocol=configuration.GRAFANA_PROTOCOL
)


Expand Down

0 comments on commit b833361

Please sign in to comment.