mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
CR changes
This commit is contained in:
parent
7dcb74ab7c
commit
54e24aa6ff
@ -39,11 +39,9 @@ RUN mkdir /docker-entrypoint-initdb.d
|
||||
|
||||
COPY docker_related_config.xml /etc/clickhouse-server/config.d/
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
COPY init-defaults.sh /docker-entrypoint-initdb.d/init-defaults.sh
|
||||
|
||||
RUN chmod +x \
|
||||
/entrypoint.sh \
|
||||
/docker-entrypoint-initdb.d/init-defaults.sh \
|
||||
/bin/gosu
|
||||
|
||||
EXPOSE 9000 8123 9009
|
||||
|
@ -47,10 +47,10 @@ $ docker run --rm -e CLICKHOUSE_UID=0 -e CLICKHOUSE_GID=0 --name clickhouse-serv
|
||||
|
||||
### How to create default database and user on starting
|
||||
|
||||
Sometimes you may want to create default user and database on image starting. You can do it using environment variables `CLICKHOUSE_DEFAULT_DB`, `CLICKHOUSE_DEFAULT_USER` and `CLICKHOUSE_DEFAULT_PASSWORD`:
|
||||
Sometimes you may want to create user (user named `default` is used by default) and database on image starting. You can do it using environment variables `CLICKHOUSE_DB`, `CLICKHOUSE_USER` and `CLICKHOUSE_PASSWORD`:
|
||||
|
||||
```
|
||||
$ docker run --rm -e CLICKHOUSE_DEFAULT_DB=my_database -e CLICKHOUSE_DEFAULT_USER=username -e CLICKHOUSE_DEFAULT_PASSWORD=password -p 9000:9000/tcp yandex/clickhouse-server
|
||||
$ docker run --rm -e CLICKHOUSE_DB=my_database -e CLICKHOUSE_USER=username -e CLICKHOUSE_PASSWORD=password -p 9000:9000/tcp yandex/clickhouse-server
|
||||
```
|
||||
|
||||
## How to extend this image
|
||||
|
@ -35,7 +35,10 @@ LOG_DIR="$(dirname $LOG_PATH || true)"
|
||||
ERROR_LOG_PATH="$(clickhouse extract-from-config --config-file $CLICKHOUSE_CONFIG --key=logger.errorlog || true)"
|
||||
ERROR_LOG_DIR="$(dirname $ERROR_LOG_PATH || true)"
|
||||
FORMAT_SCHEMA_PATH="$(clickhouse extract-from-config --config-file $CLICKHOUSE_CONFIG --key=format_schema_path || true)"
|
||||
|
||||
CLICKHOUSE_USER="${CLICKHOUSE_USER:-default}"
|
||||
CLICKHOUSE_PASSWORD="${CLICKHOUSE_PASSWORD:-}"
|
||||
CLICKHOUSE_DB="${CLICKHOUSE_DB:-}"
|
||||
|
||||
for dir in "$DATA_DIR" \
|
||||
"$ERROR_LOG_DIR" \
|
||||
@ -61,7 +64,40 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
# if clickhouse user is defined - create it (user "default" already exists out of box)
|
||||
if [ -n "$CLICKHOUSE_USER" ] && [ "$CLICKHOUSE_USER" != "default" ]; then
|
||||
echo "Create user '$CLICKHOUSE_USER' instead default"
|
||||
cat <<EOT >> /etc/clickhouse-server/users.d/default-user.xml
|
||||
<yandex>
|
||||
<!-- Docs: <https://clickhouse.tech/docs/en/operations/settings/settings_users/> -->
|
||||
<users>
|
||||
<!-- Remove default user -->
|
||||
<default remove="remove">
|
||||
</default>
|
||||
|
||||
<${CLICKHOUSE_USER}>
|
||||
<profile>default</profile>
|
||||
<networks>
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
<password>${CLICKHOUSE_PASSWORD}</password>
|
||||
<quota>default</quota>
|
||||
</${CLICKHOUSE_USER}>
|
||||
</users>
|
||||
</yandex>
|
||||
EOT
|
||||
fi
|
||||
|
||||
# define password argument for clickhouse client
|
||||
if [ -n "$CLICKHOUSE_PASSWORD" ]; then
|
||||
printf -v WITH_PASSWORD '%s %q' "--password" "$CLICKHOUSE_PASSWORD"
|
||||
fi
|
||||
|
||||
# create default database, if defined
|
||||
if [ -n "$CLICKHOUSE_DB" ]; then
|
||||
echo "Create database '$CLICKHOUSE_DB'"
|
||||
clickhouse-client --query -u "$CLICKHOUSE_USER" $WITH_PASSWORD "CREATE DATABASE IF NOT EXISTS $CLICKHOUSE_DB";
|
||||
fi
|
||||
|
||||
if [ -n "$(ls /docker-entrypoint-initdb.d/)" ]; then
|
||||
$gosu /usr/bin/clickhouse-server --config-file=$CLICKHOUSE_CONFIG &
|
||||
@ -74,10 +110,6 @@ if [ -n "$(ls /docker-entrypoint-initdb.d/)" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -z "$CLICKHOUSE_PASSWORD" ]; then
|
||||
printf -v WITH_PASSWORD '%s %q' "--password" "$CLICKHOUSE_PASSWORD"
|
||||
fi
|
||||
|
||||
clickhouseclient=( clickhouse-client --multiquery -u $CLICKHOUSE_USER $WITH_PASSWORD )
|
||||
|
||||
echo
|
||||
|
@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# define defaults
|
||||
CLICKHOUSE_DEFAULT_DB="${CLICKHOUSE_DEFAULT_DB:-}";
|
||||
CLICKHOUSE_DEFAULT_USER="${CLICKHOUSE_DEFAULT_USER:-}";
|
||||
CLICKHOUSE_DEFAULT_PASSWORD="${CLICKHOUSE_DEFAULT_PASSWORD:-secret}";
|
||||
|
||||
# if default user is defined - create it
|
||||
if [ -n "$CLICKHOUSE_DEFAULT_USER" ]; then
|
||||
cat <<EOT >> /etc/clickhouse-server/users.d/default-user.xml
|
||||
<yandex>
|
||||
<!-- Docs: <https://clickhouse.tech/docs/en/operations/settings/settings_users/> -->
|
||||
<users>
|
||||
<${CLICKHOUSE_DEFAULT_USER}>
|
||||
<profile>default</profile>
|
||||
<networks>
|
||||
<ip>::/0</ip>
|
||||
</networks>
|
||||
<password>${CLICKHOUSE_DEFAULT_PASSWORD}</password>
|
||||
<quota>default</quota>
|
||||
</${CLICKHOUSE_DEFAULT_USER}>
|
||||
</users>
|
||||
</yandex>
|
||||
EOT
|
||||
fi
|
||||
|
||||
# create default database, if defined
|
||||
if [ -n "$CLICKHOUSE_DEFAULT_DB" ]; then
|
||||
clickhouse-client --query "CREATE DATABASE IF NOT EXISTS ${CLICKHOUSE_DEFAULT_DB}";
|
||||
fi
|
Loading…
Reference in New Issue
Block a user