diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..345828e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM google/golang + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends libreadline-gplv2-dev + +WORKDIR /gopath/src/influx-cli +ADD . /gopath/src/influx-cli/ +RUN go get influx-cli + +CMD [] +ENTRYPOINT ["/gopath/bin/influx-cli"] diff --git a/README.md b/README.md index da7fb31..619ed53 100644 --- a/README.md +++ b/README.md @@ -138,3 +138,37 @@ ANY command above can be subject to: > : redirect the output into a file ``` + +docker +------ + +If you don't have a golang environment available, you can also use influx-cli +from a docker container: + +``` +$ docker build -t dieterbe/influx-cli . + +$ docker run --rm -ti dieterbe/influx-cli +``` + +Once the `dieterbe/influx-cli` container has been built, you can also use the +`docker-influx-cli.sh` script to run influx-cli through docker. + +By default, `docker-influx-cli.sh` will use InfluxDB configuration from +`~/.influxrc` config file, but you can provide your own InfluxDB config file to +the script. + +Here are some usage examples: +``` +# enter influx-cli prompt with default config file +$ ./docker-influx-cli.sh + +# enter influx-cli prompt with custom my.influxrc config file +$ ./docker-influx-cli.sh my.influxrc + +# run a single query +$ echo "select * from /pattern/ limit 10" | ./docker-influx-cli.sh + +# drop all series that match a request +$ echo "list series /pattern/" | ./docker-influx-cli.sh | sed 's/.*/drop series "&"/' | ./docker-influx-cli.sh +``` diff --git a/docker-influx-cli.sh b/docker-influx-cli.sh new file mode 100755 index 0000000..c3e768b --- /dev/null +++ b/docker-influx-cli.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +DOCKER_OPTIONS="--rm -i" +CFG="${1:-$HOME/.influxrc}" +CFGPATH=$(readlink -f "$CFG") + +if [ -f "$CFGPATH" ] +then + # add volume to influx-cli config file + DOCKER_OPTIONS="$DOCKER_OPTIONS -v $CFGPATH:/root/.influxrc" +else + >&2 echo "Cannot find influx-cli config file: $CFGPATH" +fi + +if [[ -t 0 ]] +then + # stdin is coming from the terminal + DOCKER_OPTIONS="$DOCKER_OPTIONS -t" +fi + +docker run $DOCKER_OPTIONS dieterbe/influx-cli