From 5978c6a589ec27ca5d58fa5d8b5afba95f815d57b620539104db8e4120a91c9f Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Mon, 16 Jan 2023 14:29:03 +0000 Subject: [PATCH] Accepting request 1058659 from home:kukuk:container Container with influxdb v1 database OBS-URL: https://build.opensuse.org/request/show/1058659 OBS-URL: https://build.opensuse.org/package/show/devel:microos:containers/influxdb-image?expand=0&rev=1 --- .gitattributes | 23 ++++++++ .gitignore | 1 + Dockerfile | 29 ++++++++++ LICENSE | 21 ++++++++ _service | 16 ++++++ entrypoint.sh | 12 +++++ influxdb-image.changes | 4 ++ init-influxdb.sh | 120 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 226 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 _service create mode 100644 entrypoint.sh create mode 100644 influxdb-image.changes create mode 100644 init-influxdb.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,23 @@ +## Default LFS +*.7z filter=lfs diff=lfs merge=lfs -text +*.bsp filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.gem filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.lz filter=lfs diff=lfs merge=lfs -text +*.lzma filter=lfs diff=lfs merge=lfs -text +*.obscpio filter=lfs diff=lfs merge=lfs -text +*.oxt filter=lfs diff=lfs merge=lfs -text +*.pdf filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.rpm filter=lfs diff=lfs merge=lfs -text +*.tbz filter=lfs diff=lfs merge=lfs -text +*.tbz2 filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.ttf filter=lfs diff=lfs merge=lfs -text +*.txz filter=lfs diff=lfs merge=lfs -text +*.whl filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aaf9163 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Defines the tag for OBS and build script builds: +#!BuildTag: opensuse/influxdb:latest +#!BuildTag: opensuse/influxdb:%%MINOR%% +#!BuildTag: opensuse/influxdb:%%PKG_VERSION%% +#!BuildTag: opensuse/influxdb:%%PKG_VERSION%%-%RELEASE% + +FROM opensuse/tumbleweed +LABEL maintainer="Thorsten Kukuk " + +# labelprefix=org.opensuse.influxdb +PREFIXEDLABEL org.opencontainers.image.title="InfluxDB v1.x container" +PREFIXEDLABEL org.opencontainers.image.description="InfluxDB v1.x container" +PREFIXEDLABEL org.opencontainers.image.created="%BUILDTIME%" +PREFIXEDLABEL org.opencontainers.image.version="%%PKG_VERSION%%-%RELEASE%" +PREFIXEDLABEL org.opencontainers.image.vendor="openSUSE Project" +PREFIXEDLABEL org.openbuildservice.disturl="%DISTURL%" +PREFIXEDLABEL org.opensuse.reference="registry.opensuse.org/opensuse/influxdb:%%PKG_VERSION%%-%RELEASE%" + +COPY entrypoint.sh /entrypoint.sh +COPY init-influxdb.sh /init-influxdb.sh + +RUN zypper --non-interactive install --no-recommends influxdb && zypper clean && chmod 755 /entrypoint.sh /init-influxdb.sh + +EXPOSE 8086 +EXPOSE 6060 +VOLUME /var/lib/influxdb + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["influxd"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6e04b54 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 openSUSE + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/_service b/_service new file mode 100644 index 0000000..76ddd97 --- /dev/null +++ b/_service @@ -0,0 +1,16 @@ + + + Dockerfile + %%PKG_VERSION%% + patch + influxdb + + + Dockerfile + %%MINOR%% + minor + influxdb + + + + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..c6799fd --- /dev/null +++ b/entrypoint.sh @@ -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 "$@" diff --git a/influxdb-image.changes b/influxdb-image.changes new file mode 100644 index 0000000..773afb8 --- /dev/null +++ b/influxdb-image.changes @@ -0,0 +1,4 @@ +------------------------------------------------------------------- +Fri Jan 13 14:50:23 UTC 2023 - Thorsten Kukuk + +- Initial version, scripts are from v1.11 branch diff --git a/init-influxdb.sh b/init-influxdb.sh new file mode 100644 index 0000000..61f2b17 --- /dev/null +++ b/init-influxdb.sh @@ -0,0 +1,120 @@ +#!/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) + +if ( [ ! -z "$INIT_USERS" ] || [ ! -z "$INFLUXDB_DB" ] || [ "$(ls -A /docker-entrypoint-initdb.d 2> /dev/null)" ] ) && [ ! "$(ls -A /var/lib/influxdb)" ]; 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