Skip to content

Commit

Permalink
Merge pull request #772 from influxdata/BNP_release-influxdb-v1.11.7
Browse files Browse the repository at this point in the history
feat(influxdb): build InfluxDB v1.11.7-alpine OSS
  • Loading branch information
bnpfeife authored Oct 25, 2024
2 parents 39d3092 + 2561dca commit 1636524
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 13 deletions.
15 changes: 2 additions & 13 deletions influxdb/1.11/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
FROM buildpack-deps:bookworm-curl

RUN set -ex && \
mkdir ~/.gnupg; \
echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf; \
for key in \
9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E ; \
do \
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys "$key" ; \
done

ARG TARGETARCH
ARG INFLUXDB_VERSION=1.11.7
ARG INFLUXDB_DEB=influxdb-${INFLUXDB_VERSION}-${TARGETARCH}.deb
ARG INFLUXDB_ASC=influxdb-${INFLUXDB_VERSION}-${TARGETARCH}.deb.asc
RUN export DEBIAN_FRONTEND=noninteractive && \
RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
curl -fLO "https://dl.influxdata.com/influxdb/releases/${INFLUXDB_DEB}" && \
curl -fLO "https://dl.influxdata.com/influxdb/releases/${INFLUXDB_ASC}" && \
Expand All @@ -25,12 +17,9 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
COPY influxdb.conf /etc/influxdb/influxdb.conf

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"]
45 changes: 45 additions & 0 deletions influxdb/1.11/alpine/Dockerfile
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"]
12 changes: 12 additions & 0 deletions influxdb/1.11/alpine/entrypoint.sh
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 "$@"
7 changes: 7 additions & 0 deletions influxdb/1.11/alpine/influxdb.conf
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"
128 changes: 128 additions & 0 deletions influxdb/1.11/alpine/init-influxdb.sh
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

0 comments on commit 1636524

Please sign in to comment.