Skip to content

Commit b833361

Browse files
authored
Merge pull request #1 from oliverisaac/dockerize
Dockerize the script
2 parents 83ffa56 + 3a67144 commit b833361

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.yml
2+
*.csv
3+
script/__pycache__**

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.9-slim
2+
3+
COPY requirements.txt /requirements.txt
4+
5+
RUN pip install -r /requirements.txt && mkdir /app
6+
7+
WORKDIR /app
8+
9+
COPY LICENSE run.py /app/
10+
COPY script /app/script
11+
12+
ENTRYPOINT [ "python3", "./run.py" ]

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
DOCKER_REPO ?= DOCKERHUB_USER/grafana-ldap-sync-script
2+
DOCKER_TAG ?= v1.0
3+
14
init:
25
pip install -r requirements.txt
36

@@ -15,3 +18,17 @@ bundle:
1518

1619
test:
1720
nosetests tests
21+
22+
docker-build:
23+
docker build -t ${DOCKER_REPO}:latest .
24+
docker tag ${DOCKER_REPO}:latest ${DOCKER_REPO}:${DOCKER_TAG}
25+
26+
docker-push: docker-build
27+
docker push ${DOCKER_REPO}:latest
28+
docker push ${DOCKER_REPO}:${DOCKER_TAG}
29+
30+
docker-run: docker-build
31+
docker run --mount 'type=bind,source=${PWD},target=/data' ${DOCKER_REPO}:${DOCKER_TAG} --config /data/config.yml --bind /data/example.csv
32+
33+
docker-explore: docker-build
34+
docker run -it --entrypoint /bin/bash --mount 'type=bind,source=${PWD},target=/data' ${DOCKER_REPO}:${DOCKER_TAG} -o vi

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ config:
33

44
# URL of the target grafana-server.
55
url: localhost:3000
6+
# Protocol to use when connecting to grafana (http, https)
7+
protocol: http
68
# User account name with admin rights on target grafana-server.
79
user: admin
810
# Password of account with admin rights on target grafana-server.

run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setup_logger():
3535
)
3636
handler = logging.StreamHandler()
3737
handler.setFormatter(formatter)
38-
logger.setLevel(logging.INFO)
38+
logger.setLevel(logging.DEBUG)
3939
logger.addHandler(handler)
4040

4141
if __name__ == "__main__":

script/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def __init__(self, config_path):
1414

1515
GRAFANA_AUTH = ""
1616
GRAFANA_URL = ""
17+
GRAFANA_PROTOCOL = "http"
1718

1819
LDAP_SERVER_URL = ""
1920
LDAP_PORT = ""
@@ -46,6 +47,8 @@ def load_config(self, config_path):
4647
config["grafana"]["password"]
4748
)
4849
self.GRAFANA_URL = config["grafana"]["url"]
50+
if config["grafana"]["protocol"]:
51+
self.GRAFANA_PROTOCOL = config["grafana"]["protocol"]
4952

5053
self.LDAP_SERVER_URL = config["ldap"]["url"]
5154
self.LDAP_PORT = config["ldap"]["port"]

script/grafana.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def setup_grafana(config_dict):
1515
configuration = config_dict
1616
grafana_api = GrafanaApi(
1717
auth=configuration.GRAFANA_AUTH,
18-
host=configuration.GRAFANA_URL
18+
host=configuration.GRAFANA_URL,
19+
protocol=configuration.GRAFANA_PROTOCOL
1920
)
2021

2122

0 commit comments

Comments
 (0)