Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow influxdb to run as a configurable uid/gid #389

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions influxdb/1.8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ FROM buildpack-deps:stretch-curl

RUN set -ex && \
for key in \
05CE15085FC09D18E99EFB22684A14CF2582E0C5 ; \
05CE15085FC09D18E99EFB22684A14CF2582E0C5 B42F6819007F00F88E364FD4036A9C25BF357DD4 ; \
do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" || \
gpg --keyserver pgp.mit.edu --recv-keys "$key" || \
gpg --keyserver keyserver.pgp.com --recv-keys "$key" ; \
done

ENV INFLUXDB_VERSION 1.8.0
ENV GOSU_VERSION 1.12
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) ARCH='amd64';; \
Expand All @@ -22,7 +23,14 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
wget --no-verbose https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUXDB_VERSION}_${ARCH}.deb && \
gpg --batch --verify influxdb_${INFLUXDB_VERSION}_${ARCH}.deb.asc influxdb_${INFLUXDB_VERSION}_${ARCH}.deb && \
dpkg -i influxdb_${INFLUXDB_VERSION}_${ARCH}.deb && \
rm -f influxdb_${INFLUXDB_VERSION}_${ARCH}.deb*
rm -f influxdb_${INFLUXDB_VERSION}_${ARCH}.deb* && \
wget --no-verbose https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${ARCH}.asc && \
wget --no-verbose https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${ARCH} && \
gpg --batch --verify gosu-${ARCH}.asc gosu-${ARCH} && \
rm -f gosu-${ARCH}.asc && \
mv gosu-${ARCH} /usr/local/bin && \
chmod +x /usr/local/bin/gosu-${ARCH} && \
ln -s /usr/local/bin/gosu-${ARCH} /usr/local/bin/gosu
COPY influxdb.conf /etc/influxdb/influxdb.conf

EXPOSE 8086
Expand Down
34 changes: 32 additions & 2 deletions influxdb/1.8/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
#!/bin/bash
set -e

USER_ID=${INFLUXDB_RUNAS_USER_ID:-0}
GROUP_ID=${INFLUXDB_RUNAS_GROUP_ID:-0}

if [ $USER_ID != 0 ]; then
if [ $USER_ID != $(id -u influxdb) ]; then
echo "Changing uid of influxdb to $USER_ID"
usermod -u $USER_ID influxdb
fi
fi

if [ $GROUP_ID != 0 ]; then
if [ $GROUP_ID != $(id -g influxdb) ]; then
echo "Changing gid of influxdb to $GROUP_ID"
groupmod -o -g $GROUP_ID influxdb
fi
fi

if [ $USER_ID != 0 ]; then
echo "Changing ownership of /var/lib/influxdb to $USER_ID:$GROUP_ID"
chown -R ${USER_ID}:${GROUP_ID} /var/lib/influxdb
fi

if [ $USER_ID != 0 ]; then
GOSU_CMD="gosu influxdb"
else
GOSU_CMD=
fi

echo "Starting influxdb as uid $USER_ID and gid $GROUP_ID"

if [ "${1:0:1}" = '-' ]; then
set -- influxd "$@"
fi

if [ "$1" = 'influxd' ]; then
/init-influxdb.sh "${@:2}"
$GOSU_CMD /init-influxdb.sh "${@:2}"
fi

exec "$@"
exec $GOSU_CMD "$@"