-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #772 from influxdata/BNP_release-influxdb-v1.11.7
feat(influxdb): build InfluxDB v1.11.7-alpine OSS
- Loading branch information
Showing
5 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM alpine:3.20 | ||
|
||
RUN apk add --no-cache \ | ||
bash \ | ||
ca-certificates \ | ||
tzdata && \ | ||
update-ca-certificates | ||
|
||
ARG TARGETARCH | ||
ARG INFLUXDB_VERSION=1.11.7 | ||
ARG INFLUXDB_TAR=influxdb-${INFLUXDB_VERSION}-linux-${TARGETARCH}.tar.gz | ||
ARG INFLUXDB_ASC=influxdb-${INFLUXDB_VERSION}-linux-${TARGETARCH}.tar.gz.asc | ||
RUN apk add --no-cache --virtual .build-deps \ | ||
curl \ | ||
gnupg \ | ||
tar && \ | ||
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E && \ | ||
curl -fLO "https://dl.influxdata.com/influxdb/releases/${INFLUXDB_ASC}" && \ | ||
curl -fLO "https://dl.influxdata.com/influxdb/releases/${INFLUXDB_TAR}" && \ | ||
gpg --batch --verify "${INFLUXDB_ASC}" "${INFLUXDB_TAR}" && \ | ||
tar -xf "${INFLUXDB_TAR}" -C /usr/bin \ | ||
./influx \ | ||
./influx_inspect \ | ||
./influxd && \ | ||
rm -rf "${INFLUXDB_TAR}" \ | ||
"${INFLUXDB_ASC}" && \ | ||
apk del .build-deps | ||
COPY influxdb.conf /etc/influxdb/influxdb.conf | ||
|
||
RUN addgroup influxdb && \ | ||
adduser -S -s /bin/false -h /var/lib/influxdb -G influxdb influxdb && \ | ||
mkdir -p /var/lib/influxdb && \ | ||
mkdir -p /var/log/influxdb && \ | ||
chown influxdb:influxdb /var/lib/influxdb && \ | ||
chown influxdb:influxdb /var/log/influxdb && \ | ||
chmod 0750 /var/lib/influxdb && \ | ||
chmod 0750 /var/log/influxdb | ||
|
||
EXPOSE 8086 | ||
VOLUME /var/lib/influxdb | ||
COPY entrypoint.sh /entrypoint.sh | ||
COPY init-influxdb.sh /init-influxdb.sh | ||
USER influxdb | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD ["influxd"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
if [ "${1:0:1}" = '-' ]; then | ||
set -- influxd "$@" | ||
fi | ||
|
||
if [ "$1" = 'influxd' ]; then | ||
/init-influxdb.sh "${@:2}" | ||
fi | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[meta] | ||
dir = "/var/lib/influxdb/meta" | ||
|
||
[data] | ||
dir = "/var/lib/influxdb/data" | ||
engine = "tsm1" | ||
wal-dir = "/var/lib/influxdb/wal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/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 |