diff --git a/Jenkinsfile.nightly b/Jenkinsfile.nightly deleted file mode 100644 index 163ab5b1a..000000000 --- a/Jenkinsfile.nightly +++ /dev/null @@ -1,27 +0,0 @@ -pipeline { - agent any - - stages { - stage('Build influxdb nightly') { - steps { - script { - docker.withRegistry('https://quay.io', 'quay.io') { - def image = docker.build("quay.io/influxdb/influxdb:nightly", "influxdb/nightly") - try { - image.push() - } finally { - sh "docker rmi ${image.id}" - } - - def alpine = docker.build("quay.io/influxdb/influxdb:nightly-alpine", "influxdb/nightly/alpine") - try { - alpine.push() - } finally { - sh "docker rmi ${alpine.id}" - } - } - } - } - } - } -} diff --git a/circle-test.sh b/circle-test.sh index 42055bfb7..c4528d4f9 100755 --- a/circle-test.sh +++ b/circle-test.sh @@ -32,7 +32,7 @@ tags=() # Gather directories with a Dockerfile and sanitize the path to remove leading # a leading ./ and multiple slashes into a single slash. -dockerfiles=$(find "$dir" -name nightly -prune -o -name Dockerfile -print0 | xargs -0 -I{} dirname {} | grep -v dockerlib | sed 's@^./@@' | sed 's@//*@/@g') +dockerfiles=$(find "$dir" -name Dockerfile -print0 | xargs -0 -I{} dirname {} | grep -v dockerlib | sed 's@^./@@' | sed 's@//*@/@g') for path in $dockerfiles; do # Generate a tag by replacing the first slash with a colon and all remaining slashes with a dash. tag=$(echo $path | sed 's@/@:@' | sed 's@/@-@g') diff --git a/influxdb/circle-test.sh b/influxdb/circle-test.sh deleted file mode 100755 index d64dc3859..000000000 --- a/influxdb/circle-test.sh +++ /dev/null @@ -1,217 +0,0 @@ -#!/bin/bash - -container_counter=1 - -influx() { - ./.tests/influx -host 127.0.0.1 -port 8086 -format=csv -execute "$@" -} - -setup() { - - mkdir -p ./.tests/var/lib/influxdb - - local rm_flag='--rm' - - if [ ! -z "$CIRCLE_BUILD_NUM" ]; then - rm_flag='' - fi - - PORT=$2 - - if [ -z "$PORT" ]; then - PORT=8086 - fi - - local init_cmd="docker run -it $rm_flag -p 8086:$PORT --user=$(id -u):0 -v $(pwd)/.tests/var/lib/influxdb:/var/lib/influxdb $1 ""$tag"" /init-influxdb.sh" - - if ! $init_cmd > /dev/null; then - failed_tests+=("Failed to execute '$init_cmd'") - fi - - docker run -d --name influxdb-test$container_counter -p 8086:$PORT --user=$(id -u):0 -v $(pwd)/.tests/var/lib/influxdb:/var/lib/influxdb $1 "$tag" > /dev/null - - # Copy cli from started container - docker cp influxdb-test$container_counter:/usr/bin/influx ./.tests/influx - - # Wait until influxdb is healthy - for i in {30..0}; do - if curl -s -i -XHEAD http://127.0.0.1:8086/ping > /dev/null; then - break - fi - sleep 1 - done -} - -cleanup() { - docker stop influxdb-test$container_counter > /dev/null - - if [ -z "$CIRCLE_BUILD_NUM" ]; then - docker rm influxdb-test$container_counter > /dev/null - fi - - container_counter=$((container_counter + 1)) - - rm -r ./.tests -} - -test_default_without_auth_enabled() { - log_msg 'Executing test_default_without_auth_enabled' - setup - - assert_equals "$(influx 'SHOW DATABASES' | wc -l)" '1' "test_default_without_auth_enabled: influxdb should contain no databases" - - assert_equals "$(influx 'SHOW USERS' | wc -l)" '1' "test_default_without_auth_enabled: influxdb should contain no users" - - cleanup -} - -test_default_with_auth_enabled() { - log_msg 'Executing test_default_with_auth_enabled' - setup '--env INFLUXDB_HTTP_AUTH_ENABLED=true' - - assert_contains "$(influx 'SHOW DATABASES' 2> /dev/null)" 'create admin user first or disable authentication' 'test_default_with_auth_enabled: influxdb should not be initialized' - - cleanup -} - -test_create_db() { - log_msg 'Executing test_create_db' - setup '--env INFLUXDB_DB=test_db' - - assert_contains "$(influx 'SHOW DATABASES')" 'test_db' 'test_create_db: influxdb should contain a test_db database' - - cleanup -} - -test_create_admin() { - log_msg 'Executing test_create_admin' - setup '--env INFLUXDB_HTTP_AUTH_ENABLED=true --env INFLUXDB_ADMIN_USER=test_admin --env INFLUXDB_ADMIN_PASSWORD=123' - - influx 'SHOW USERS' -username test_admin -password=123 > /dev/null - - local exit_code="$?" - - assert_equals "$exit_code" '0' 'test_create_admin: influxdb should contain a test_admin user' - - cleanup -} - -test_create_user() { - log_msg 'Executing test_create_user' - setup '--env INFLUXDB_DB=test_db --env INFLUXDB_HTTP_AUTH_ENABLED=true --env INFLUXDB_ADMIN_USER=admin --env INFLUXDB_USER=test_user --env INFLUXDB_USER_PASSWORD=123' - - local result="$(influx 'INSERT test_measurement value=1' -database=test_db -username test_user -password=123)" - - assert_equals "$result" '' 'test_create_user: influxdb user ''test_user'' should exist and have write privileges' - - local success=$(influx 'SELECT * FROM test_measurement;' -database=test_db -username test_user -password=123 > /dev/null && echo 'true') - - assert_equals "$success" 'true' 'test_create_user: influxdb user ''test_user'' should have read privileges' - - cleanup -} - -test_create_write_user() { - log_msg 'Executing test_create_write_user' - setup '--env INFLUXDB_DB=test_db --env INFLUXDB_HTTP_AUTH_ENABLED=true --env INFLUXDB_ADMIN_USER=admin --env INFLUXDB_WRITE_USER=test_write_user --env INFLUXDB_WRITE_USER_PASSWORD=123' - - local result="$(influx 'INSERT test_measurement value=1' -database=test_db -username test_write_user -password=123)" - - assert_equals "$result" '' 'test_create_write_user: influxdb user ''test_write_user'' should exist and have write privileges' - - local success=$(influx 'SELECT * FROM test_measurement' -database=test_db -username test_write_user -password=123 &> /dev/null || echo 'true') - - assert_equals "$success" 'true' 'test_create_write_user: influxdb user ''test_write_user'' should not have read privileges' - - cleanup -} - -test_create_read_user() { - log_msg 'Executing test_create_read_user' - setup '--env INFLUXDB_DB=test_db --env INFLUXDB_HTTP_AUTH_ENABLED=true --env INFLUXDB_ADMIN_USER=admin --env INFLUXDB_READ_USER=test_read_user --env INFLUXDB_READ_USER_PASSWORD=123' - - local result="$(influx 'INSERT test_measurement value=1' -database=test_db -username test_read_user -password=123)" - - assert_contains "$result" 'not authorized' 'test_create_read_user: influxdb user ''test_read_user'' should not have write privileges' - - local success=$(influx 'SELECT * FROM test_measurement' -database=test_db -username test_read_user -password=123 > /dev/null && echo 'true') - - assert_equals "$success" 'true' 'test_create_read_user: influxdb user ''test_read_user'' should exist and have read privileges' - - cleanup -} - -test_custom_shell_script() { - log_msg 'Executing test_custom_shell_script' - - mkdir -p ./.tests - - echo 'echo ''success'' > /var/lib/influxdb/test_result' > ./.tests/custom_script.sh - - chmod 755 ./.tests/custom_script.sh - - setup "-v $(pwd)/.tests/custom_script.sh:/docker-entrypoint-initdb.d/custom_script.sh" - - local result=$(cat ./.tests/var/lib/influxdb/test_result) - - assert_equals "$result" 'success' 'test_custom_shell_script: test failed' - - cleanup -} - -test_custom_iql_script() { - log_msg 'Executing test_custom_iql_script' - - mkdir -p ./.tests - - local cmd="CREATE USER test_user WITH PASSWORD '123'" - - echo "$cmd" > ./.tests/custom_script.iql - - setup "-v $(pwd)/.tests/custom_script.iql:/docker-entrypoint-initdb.d/custom_script.iql --env INFLUXDB_HTTP_AUTH_ENABLED=true --env INFLUXDB_ADMIN_USER=admin --env INFLUXDB_ADMIN_PASSWORD=123" - - local result=$(influx 'SHOW USERS' -username admin -password=123) - - assert_contains "$result" 'test_user' 'test_custom_iql_script: test failed' - - cleanup -} - -test_create_db_on_non_default_port() { - log_msg 'Executing test_create_db_on_non_default_port' - setup '--env INFLUXDB_DB=test_db --env INFLUXDB_HTTP_BIND_ADDRESS=:8083' 8083 - - assert_contains "$(influx 'SHOW DATABASES')" 'test_db' 'test_create_db: influxdb should contain a test_db database' - - cleanup -} - -influxdb_dockerfiles=$(find 'influxdb' -name nightly -prune -o -name Dockerfile -print0 | xargs -0 -I{} dirname {} | sed 's@^./@@' | sed 's@//*@/@g') - -for path in $influxdb_dockerfiles; do - # Generate a tag by replacing the first slash with a colon and all remaining slashes with a dash. - tag=$(echo $path | sed 's@/@:@' | sed 's@/@-@g') - - log_msg "Testing docker image $tag" - - test_default_without_auth_enabled - - test_default_with_auth_enabled - - test_create_db - - test_create_admin - - test_create_user - - test_create_write_user - - test_create_read_user - - test_custom_shell_script - - test_custom_iql_script - - test_create_db_on_non_default_port - -done diff --git a/influxdb/nightly/Dockerfile b/influxdb/nightly/Dockerfile deleted file mode 100644 index 56442edf2..000000000 --- a/influxdb/nightly/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM buildpack-deps:jessie-curl - -RUN set -ex && \ - for key in \ - 05CE15085FC09D18E99EFB22684A14CF2582E0C5 ; \ - do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \ - gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ - gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \ - done - -RUN wget --no-verbose https://dl.influxdata.com/influxdb/nightlies/influxdb_nightly_amd64.deb.asc && \ - wget --no-verbose https://dl.influxdata.com/influxdb/nightlies/influxdb_nightly_amd64.deb && \ - gpg --batch --verify influxdb_nightly_amd64.deb.asc influxdb_nightly_amd64.deb && \ - dpkg -i influxdb_nightly_amd64.deb && \ - rm -f influxdb_nightly_amd64.deb* -COPY influxdb.conf /etc/influxdb/influxdb.conf - -EXPOSE 8083 8086 - -VOLUME /var/lib/influxdb - -COPY entrypoint.sh /entrypoint.sh -COPY init-influxdb.sh /init-influxdb.sh -ENTRYPOINT ["/entrypoint.sh"] -CMD ["influxd"] diff --git a/influxdb/nightly/alpine/Dockerfile b/influxdb/nightly/alpine/Dockerfile deleted file mode 100644 index 24875412d..000000000 --- a/influxdb/nightly/alpine/Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM alpine:3.12 - -RUN apk add --no-cache bash - -RUN set -ex && \ - apk add --no-cache --virtual .build-deps wget gnupg tar ca-certificates && \ - update-ca-certificates && \ - for key in \ - 05CE15085FC09D18E99EFB22684A14CF2582E0C5 ; \ - do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \ - gpg --keyserver pgp.mit.edu --recv-keys "$key" || \ - gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \ - done && \ - wget --no-verbose https://dl.influxdata.com/influxdb/nightlies/influxdb-static-nightly_linux_amd64.tar.gz.asc && \ - wget --no-verbose https://dl.influxdata.com/influxdb/nightlies/influxdb-static-nightly_linux_amd64.tar.gz && \ - gpg --batch --verify influxdb-static-nightly_linux_amd64.tar.gz.asc influxdb-static-nightly_linux_amd64.tar.gz && \ - mkdir -p /usr/src && \ - tar -C /usr/src -xzf influxdb-static-nightly_linux_amd64.tar.gz && \ - rm -f /usr/src/influxdb-*/influxdb.conf && \ - chmod +x /usr/src/influxdb-*/* && \ - cp -a /usr/src/influxdb-*/* /usr/bin/ && \ - gpgconf --kill all && \ - rm -rf *.tar.gz* /usr/src /root/.gnupg && \ - apk del .build-deps -COPY influxdb.conf /etc/influxdb/influxdb.conf - -EXPOSE 8083 8086 - -VOLUME /var/lib/influxdb - -COPY entrypoint.sh /entrypoint.sh -COPY init-influxdb.sh /init-influxdb.sh -ENTRYPOINT ["/entrypoint.sh"] -CMD ["influxd"] diff --git a/influxdb/nightly/alpine/entrypoint.sh b/influxdb/nightly/alpine/entrypoint.sh deleted file mode 100755 index 6a0a01293..000000000 --- a/influxdb/nightly/alpine/entrypoint.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -set -e - -if [ "${1:0:1}" = '-' ]; then - set -- influxd "$@" -fi - -if [ "$1" = 'influxd' ]; then - /init-influxdb.sh "${@:2}" -fi - -exec "$@" diff --git a/influxdb/nightly/alpine/influxdb.conf b/influxdb/nightly/alpine/influxdb.conf deleted file mode 100644 index dec974284..000000000 --- a/influxdb/nightly/alpine/influxdb.conf +++ /dev/null @@ -1,10 +0,0 @@ -[meta] - dir = "/var/lib/influxdb/meta" - -[data] - dir = "/var/lib/influxdb/data" - engine = "tsm1" - wal-dir = "/var/lib/influxdb/wal" - -[admin] - enabled = true diff --git a/influxdb/nightly/alpine/init-influxdb.sh b/influxdb/nightly/alpine/init-influxdb.sh deleted file mode 100755 index 3f7349a08..000000000 --- a/influxdb/nightly/alpine/init-influxdb.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -set -e - -AUTH_ENABLED="$INFLUXDB_HTTP_AUTH_ENABLED" - -if [ -z "$AUTH_ENABLED" ]; then - AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*true' /etc/influxdb/influxdb.conf | grep -io 'true' | cat)" -else - AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)" -fi - -INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo) - -# Check if an environment variable for where to put meta is set. -# If so, then use that directory, otherwise use the default. -if [ -z "$INFLUXDB_META_DIR" ]; then - META_DIR="/var/lib/influxdb/meta" -else - META_DIR="$INFLUXDB_META_DIR" -fi - -if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d "$META_DIR" 2>/dev/null)" ]; then - - INIT_QUERY="" - CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB" - - if [ ! -z "$INIT_USERS" ]; then - - if [ -z "$INFLUXDB_ADMIN_PASSWORD" ]; then - INFLUXDB_ADMIN_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_ADMIN_PASSWORD:$INFLUXDB_ADMIN_PASSWORD" - fi - - INIT_QUERY="CREATE USER \"$INFLUXDB_ADMIN_USER\" WITH PASSWORD '$INFLUXDB_ADMIN_PASSWORD' WITH ALL PRIVILEGES" - elif [ ! -z "$INFLUXDB_DB" ]; then - INIT_QUERY="$CREATE_DB_QUERY" - else - INIT_QUERY="SHOW DATABASES" - fi - - INFLUXDB_INIT_PORT="8086" - - INFLUXDB_HTTP_BIND_ADDRESS=127.0.0.1:$INFLUXDB_INIT_PORT INFLUXDB_HTTP_HTTPS_ENABLED=false influxd "$@" & - pid="$!" - - INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -execute " - - for i in {30..0}; do - if $INFLUX_CMD "$INIT_QUERY" &> /dev/null; then - break - fi - echo 'influxdb init process in progress...' - sleep 1 - done - - if [ "$i" = 0 ]; then - echo >&2 'influxdb init process failed.' - exit 1 - fi - - if [ ! -z "$INIT_USERS" ]; then - - INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -username ${INFLUXDB_ADMIN_USER} -password ${INFLUXDB_ADMIN_PASSWORD} -execute " - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "$CREATE_DB_QUERY" - fi - - if [ ! -z "$INFLUXDB_USER" ] && [ -z "$INFLUXDB_USER_PASSWORD" ]; then - INFLUXDB_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_USER_PASSWORD:$INFLUXDB_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_USER\" WITH PASSWORD '$INFLUXDB_USER_PASSWORD'" - - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT ALL ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_USER\"" - fi - fi - - if [ ! -z "$INFLUXDB_WRITE_USER" ] && [ -z "$INFLUXDB_WRITE_USER_PASSWORD" ]; then - INFLUXDB_WRITE_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_WRITE_USER_PASSWORD:$INFLUXDB_WRITE_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_WRITE_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_WRITE_USER\" WITH PASSWORD '$INFLUXDB_WRITE_USER_PASSWORD'" - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_WRITE_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT WRITE ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_WRITE_USER\"" - fi - fi - - if [ ! -z "$INFLUXDB_READ_USER" ] && [ -z "$INFLUXDB_READ_USER_PASSWORD" ]; then - INFLUXDB_READ_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_READ_USER_PASSWORD:$INFLUXDB_READ_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_READ_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_READ_USER\" WITH PASSWORD '$INFLUXDB_READ_USER_PASSWORD'" - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_READ_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT READ ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_READ_USER\"" - fi - fi - - fi - - for f in /docker-entrypoint-initdb.d/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.iql) echo "$0: running $f"; $INFLUX_CMD "$(cat ""$f"")"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo - done - - if ! kill -s TERM "$pid" || ! wait "$pid"; then - echo >&2 'influxdb init process failed. (Could not stop influxdb)' - exit 1 - fi - -fi diff --git a/influxdb/nightly/entrypoint.sh b/influxdb/nightly/entrypoint.sh deleted file mode 100755 index 26e6bd7ad..000000000 --- a/influxdb/nightly/entrypoint.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e - -if [ "${1:0:1}" = '-' ]; then - set -- influxd "$@" -fi - -if [ "$1" = 'influxd' ]; then - /init-influxdb.sh "${@:2}" -fi - -exec "$@" diff --git a/influxdb/nightly/influxdb.conf b/influxdb/nightly/influxdb.conf deleted file mode 100644 index dec974284..000000000 --- a/influxdb/nightly/influxdb.conf +++ /dev/null @@ -1,10 +0,0 @@ -[meta] - dir = "/var/lib/influxdb/meta" - -[data] - dir = "/var/lib/influxdb/data" - engine = "tsm1" - wal-dir = "/var/lib/influxdb/wal" - -[admin] - enabled = true diff --git a/influxdb/nightly/init-influxdb.sh b/influxdb/nightly/init-influxdb.sh deleted file mode 100755 index 3f7349a08..000000000 --- a/influxdb/nightly/init-influxdb.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -set -e - -AUTH_ENABLED="$INFLUXDB_HTTP_AUTH_ENABLED" - -if [ -z "$AUTH_ENABLED" ]; then - AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*true' /etc/influxdb/influxdb.conf | grep -io 'true' | cat)" -else - AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)" -fi - -INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo) - -# Check if an environment variable for where to put meta is set. -# If so, then use that directory, otherwise use the default. -if [ -z "$INFLUXDB_META_DIR" ]; then - META_DIR="/var/lib/influxdb/meta" -else - META_DIR="$INFLUXDB_META_DIR" -fi - -if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d "$META_DIR" 2>/dev/null)" ]; then - - INIT_QUERY="" - CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB" - - if [ ! -z "$INIT_USERS" ]; then - - if [ -z "$INFLUXDB_ADMIN_PASSWORD" ]; then - INFLUXDB_ADMIN_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_ADMIN_PASSWORD:$INFLUXDB_ADMIN_PASSWORD" - fi - - INIT_QUERY="CREATE USER \"$INFLUXDB_ADMIN_USER\" WITH PASSWORD '$INFLUXDB_ADMIN_PASSWORD' WITH ALL PRIVILEGES" - elif [ ! -z "$INFLUXDB_DB" ]; then - INIT_QUERY="$CREATE_DB_QUERY" - else - INIT_QUERY="SHOW DATABASES" - fi - - INFLUXDB_INIT_PORT="8086" - - INFLUXDB_HTTP_BIND_ADDRESS=127.0.0.1:$INFLUXDB_INIT_PORT INFLUXDB_HTTP_HTTPS_ENABLED=false influxd "$@" & - pid="$!" - - INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -execute " - - for i in {30..0}; do - if $INFLUX_CMD "$INIT_QUERY" &> /dev/null; then - break - fi - echo 'influxdb init process in progress...' - sleep 1 - done - - if [ "$i" = 0 ]; then - echo >&2 'influxdb init process failed.' - exit 1 - fi - - if [ ! -z "$INIT_USERS" ]; then - - INFLUX_CMD="influx -host 127.0.0.1 -port $INFLUXDB_INIT_PORT -username ${INFLUXDB_ADMIN_USER} -password ${INFLUXDB_ADMIN_PASSWORD} -execute " - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "$CREATE_DB_QUERY" - fi - - if [ ! -z "$INFLUXDB_USER" ] && [ -z "$INFLUXDB_USER_PASSWORD" ]; then - INFLUXDB_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_USER_PASSWORD:$INFLUXDB_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_USER\" WITH PASSWORD '$INFLUXDB_USER_PASSWORD'" - - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT ALL ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_USER\"" - fi - fi - - if [ ! -z "$INFLUXDB_WRITE_USER" ] && [ -z "$INFLUXDB_WRITE_USER_PASSWORD" ]; then - INFLUXDB_WRITE_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_WRITE_USER_PASSWORD:$INFLUXDB_WRITE_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_WRITE_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_WRITE_USER\" WITH PASSWORD '$INFLUXDB_WRITE_USER_PASSWORD'" - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_WRITE_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT WRITE ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_WRITE_USER\"" - fi - fi - - if [ ! -z "$INFLUXDB_READ_USER" ] && [ -z "$INFLUXDB_READ_USER_PASSWORD" ]; then - INFLUXDB_READ_USER_PASSWORD="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo;)" - echo "INFLUXDB_READ_USER_PASSWORD:$INFLUXDB_READ_USER_PASSWORD" - fi - - if [ ! -z "$INFLUXDB_READ_USER" ]; then - $INFLUX_CMD "CREATE USER \"$INFLUXDB_READ_USER\" WITH PASSWORD '$INFLUXDB_READ_USER_PASSWORD'" - $INFLUX_CMD "REVOKE ALL PRIVILEGES FROM \"$INFLUXDB_READ_USER\"" - - if [ ! -z "$INFLUXDB_DB" ]; then - $INFLUX_CMD "GRANT READ ON \"$INFLUXDB_DB\" TO \"$INFLUXDB_READ_USER\"" - fi - fi - - fi - - for f in /docker-entrypoint-initdb.d/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.iql) echo "$0: running $f"; $INFLUX_CMD "$(cat ""$f"")"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo - done - - if ! kill -s TERM "$pid" || ! wait "$pid"; then - echo >&2 'influxdb init process failed. (Could not stop influxdb)' - exit 1 - fi - -fi