diff --git a/docker-compose.yml b/docker-compose.yml index ca17e39..e7a7795 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,13 +23,14 @@ services: volumes: - influx-data:/var/lib/influxdb2 - ./influxdb/startup:/docker-entrypoint-initdb.d - - server-config:/server-config + - server-config:/configs + - grafana-provisioning:/grafana env_file: - ./internal/configs/db.env environment: - DOCKER_INFLUXDB_INIT_MODE=setup - DOCKER_INFLUXDB_INIT_USERNAME=admin - - DOCKER_INFLUXDB_INIT_PASSWORD=admin + - DOCKER_INFLUXDB_INIT_PASSWORD=F0r3l1ght - DOCKER_INFLUXDB_INIT_ORG=ForeLight - DOCKER_INFLUXDB_INIT_BUCKET=default grafana: @@ -37,8 +38,10 @@ services: ports: - "3000:3000" volumes: + - grafana-provisioning:/etc/grafana/provisioning - grafana-data:/var/lib/grafana volumes: grafana-data: + grafana-provisioning: influx-data: server-config: diff --git a/influxdb/startup/influxsetup.sh b/influxdb/startup/influxsetup.sh index 90474c8..222a838 100755 --- a/influxdb/startup/influxsetup.sh +++ b/influxdb/startup/influxsetup.sh @@ -1,16 +1,12 @@ #!/bin/bash TOKEN=$(influx auth list --user ${DOCKER_INFLUXDB_INIT_USER_ID} --hide-headers | cut -f 3) +ORG=$(influx org list | grep ${DOCKER_INFLUXDB_INIT_ORG_ID} | awk '{print $2}') +# creating starting server YAML +echo -e "server:\n\tdb-url:${INFLUX_HOST}\n\tdb-org:${ORG}\n\tdb-token:${TOKEN}" >/configs/server.yaml; -export db_url=$INFLUX_HOST -export db_org=$DOCKER_INFLUXDB_INIT_ORG_ID -export db_token=$TOKEN - -rm -f temp.yaml -( echo "cat <final.yaml"; - cat template.yaml; - echo "EOF"; -) >temp.yaml -. temp.yaml -cat final.yaml -mv final.yaml /server-config/server.yaml +# creating grafana yaml +influx user create -n grafana -o ${ORG} +GRAFANA_USER_ID=$(influx user list --hide-headers --name grafana) +GRAFANA_TOKEN=$(influx auth list --user ${GRAFANA_USER_ID} --hide-headers | cut -f 3) +echo -e "datasources:\n\t- name: INFLUXDB\n\ttype: influxdb\n\turl:${INFLUX_HOST}\n\tdatabase: test\n\t jsonData:\n\t\thttpMode: GET\n\t\thttpHeaderName1: 'Authorization'\n\tsecureJsonData:\n\t\thttpHeaderValue1: 'Token ${GRAFANA_TOKEN}'"