Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init-influxdb.sh: Fix #224 and support keywords as database name #244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions influxdb/1.5/alpine/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.5/data/alpine/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.5/data/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.5/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.6/alpine/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.6/data/alpine/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.6/data/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/1.6/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
29 changes: 20 additions & 9 deletions influxdb/circle-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,29 @@ test_default_without_auth_enabled() {
cleanup
}

test_default_with_auth_enabled() {
log_msg 'Executing test_default_with_auth_enabled'
test_default_with_auth_enabled_by_true() {
log_msg 'Executing test_default_with_auth_enabled_by_true'
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'
test_default_with_auth_enabled_by_1() {
log_msg 'Executing test_default_with_auth_enabled_by_1'
setup '--env INFLUXDB_HTTP_AUTH_ENABLED=1'

assert_contains "$(influx 'SHOW DATABASES')" 'test_db' 'test_create_db: influxdb should contain a test_db database'
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_with_keyword_name() {
log_msg 'Executing test_create_db_with_keyword_name'
setup '--env INFLUXDB_DB=database'

assert_contains "$(influx 'SHOW DATABASES')" 'database' 'test_create_db_with_keyword_name: influxdb should contain a database with name "database"'

cleanup
}
Expand Down Expand Up @@ -186,7 +195,7 @@ test_create_db_on_non_default_port() {
cleanup
}

influxdb_dockerfiles=$(find 'influxdb' -name nightly -prune -o -name Dockerfile -print0 | xargs -0 -I{} dirname {} | sed 's@^./@@' | sed 's@//*@/@g')
influxdb_dockerfiles=$(find 'influxdb' -name nightly -prune -o -name data -prune -o -name meta -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.
Expand All @@ -196,9 +205,11 @@ for path in $influxdb_dockerfiles; do

test_default_without_auth_enabled

test_default_with_auth_enabled
test_default_with_auth_enabled_by_true

test_default_with_auth_enabled_by_1

test_create_db
test_create_db_with_keyword_name

test_create_admin

Expand Down
6 changes: 3 additions & 3 deletions influxdb/nightly/alpine/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down
6 changes: 3 additions & 3 deletions influxdb/nightly/init-influxdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ 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)"
AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*(true|1)' /etc/influxdb/influxdb.conf | grep -ioE '(true|1)' | cat)"
else
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -io 'true' | cat)"
AUTH_ENABLED="$(echo "$INFLUXDB_HTTP_AUTH_ENABLED" | grep -ioE '(true|1)' | cat)"
fi

INIT_USERS=$([ ! -z "$AUTH_ENABLED" ] && [ ! -z "$INFLUXDB_ADMIN_USER" ] && echo 1 || echo)

if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -d /var/lib/influxdb/meta 2>/dev/null)" ]; then

INIT_QUERY=""
CREATE_DB_QUERY="CREATE DATABASE $INFLUXDB_DB"
CREATE_DB_QUERY="CREATE DATABASE \"$INFLUXDB_DB\""

if [ ! -z "$INIT_USERS" ]; then

Expand Down