-
Notifications
You must be signed in to change notification settings - Fork 379
Image improvements #146
Image improvements #146
Changes from 8 commits
f99b597
62edf50
7ac9c65
fbdd3cd
1b7cf82
b42f62f
3dd301d
ef9f232
e2872ea
bdfc434
3796995
515cc79
db076d7
61f3782
dc7e754
766ad7d
f5da2bf
1710405
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
FROM debian:jessie | ||
|
||
ARG DOWNLOAD_URL="https://s3-us-west-2.amazonaws.com/grafana-releases/master/grafana_latest_amd64.deb" | ||
ARG GRAFANA_VERSION="latest" | ||
ARG GF_HOME="/usr/share/grafana" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of defining defaults in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Should make it easier to change in the future. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO you can add build argument for architecture - see https://github.com/monitoringartist/grafana-xxl/pull/8/files. Then you can build also arm images easily. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jangaraj It's a bit out of scope for this PR but that's definitely something to look into when we have inhouse ARM builds of Grafana. |
||
RUN apt-get update && \ | ||
apt-get -y --no-install-recommends install libfontconfig curl ca-certificates && \ | ||
apt-get clean && \ | ||
curl ${DOWNLOAD_URL} > /tmp/grafana.deb && \ | ||
dpkg -i /tmp/grafana.deb && \ | ||
rm /tmp/grafana.deb && \ | ||
curl -L https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 > /usr/sbin/gosu && \ | ||
chmod +x /usr/sbin/gosu && \ | ||
RUN apt-get update && apt-get install -qq -y wget tar sqlite libfontconfig curl ca-certificates && \ | ||
wget -O /tmp/grafana.tar.gz https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-$GRAFANA_VERSION.linux-x64.tar.gz && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You install both curl and wget? Just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of puting the tar in a file, use
Skips writing the file to a file and need to cleanup, as well as directly extracts in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. We need tools though. May change in the future. |
||
tar -zxvf /tmp/grafana.tar.gz -C /tmp && rm /tmp/grafana.tar.gz && \ | ||
mv /tmp/grafana-* $GF_HOME && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN mkdir -p /etc/grafana/provisioning/datasources && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Not sure why I didn't do that originally. |
||
mkdir -p /etc/grafana/provisioning/dashboards && \ | ||
mkdir -p /var/lib/grafana/plugins && \ | ||
mkdir -p /var/log/grafana && \ | ||
cp $GF_HOME/conf/sample.ini /etc/grafana/grafana.ini && \ | ||
cp $GF_HOME/conf/ldap.toml /etc/grafana/ldap.toml && \ | ||
cp $GF_HOME/bin/grafana-server /usr/sbin/grafana-server && \ | ||
cp $GF_HOME/bin/grafana-cli /usr/sbin/grafana-cli && \ | ||
chown -R nobody:nogroup /var/lib/grafana && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There doesn't seem to be a good way to solve this problem when you're trying to mount directories from the host filesystem as volumes, because you need to ensure that there is a matching uid & gid between the process running in the container and on the host. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After some discussion with @xlson the proposed solution is to explicitly set a uid and gid (exact value tbd) for the If the uid and gid are specified with |
||
chown -R nobody:nogroup $GF_HOME && \ | ||
chown -R nobody:nogroup /var/log/grafana | ||
|
||
VOLUME ["/var/lib/grafana", "/var/log/grafana", "/etc/grafana"] | ||
VOLUME ["/var/lib/grafana"] | ||
|
||
EXPOSE 3000 | ||
|
||
COPY ./run.sh /run.sh | ||
|
||
ENTRYPOINT ["/run.sh"] | ||
USER nobody | ||
|
||
ENTRYPOINT [ "/run.sh" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rather use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm like that too. Will have to check if there are any good reasons to keep it as an entrypoint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I agree that CMD would have been a better option it would be a breaking change and as such I don't think its enough of an improvement to warrant it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,18 +43,22 @@ More information in the grafana configuration documentation: http://docs.grafana | |
## Grafana container with persistent storage (recommended) | ||
|
||
``` | ||
# create /var/lib/grafana as persistent volume storage | ||
docker run -d -v /var/lib/grafana --name grafana-storage busybox:latest | ||
# create a persistent volume for your data in /var/lib/grafana (database and plugins) | ||
docker volume create grafana-storage | ||
|
||
# start grafana | ||
docker run \ | ||
-d \ | ||
-p 3000:3000 \ | ||
--name=grafana \ | ||
--volumes-from grafana-storage \ | ||
-v grafana-storage:/var/lib/grafana \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never seen that one before. Will look into it. Thanks for reviewing the container, much appreciated. |
||
grafana/grafana | ||
``` | ||
|
||
Note: An unnamed volume will be created for you when you boot Grafana, | ||
using `docker volume create grafana-storage` just makes it easier to find | ||
by giving it a name. | ||
|
||
## Installing plugins for Grafana 3 | ||
|
||
Pass the plugins you want installed to docker with the `GF_INSTALL_PLUGINS` environment variable as a comma seperated list. This will pass each plugin name to `grafana-cli plugins install ${plugin}`. | ||
|
@@ -72,22 +76,25 @@ docker run \ | |
|
||
Dockerfile: | ||
```Dockerfile | ||
FROM grafana/grafana:5.0.0 | ||
FROM grafana/grafana:master | ||
ENV GF_PATHS_PLUGINS=/opt/grafana-plugins | ||
RUN mkdir -p $GF_PATHS_PLUGINS | ||
RUN grafana-cli --pluginsDir $GF_PATHS_PLUGINS plugins install grafana-clock-panel | ||
USER root | ||
RUN mkdir -p $GF_PATHS_PLUGINS && chown nobody:nogroup $GF_PATHS_PLUGINS | ||
USER nobody | ||
RUN grafana-cli --pluginsDir $GF_PATHS_PLUGINS plugins install grafana-clock-panel && \ | ||
grafana-cli --pluginsDir $GF_PATHS_PLUGINS plugins install grafana-simple-json-datasource | ||
``` | ||
|
||
Add lines with `RUN grafana-cli ...` for each plugin you wish to install in your custom image. Don't forget to specify what version of Grafana you wish to build from (replace 5.0.0 in the example). | ||
Add lines with `grafana-cli ...` for each plugin you wish to install in your custom image. Don't forget to specify what version of Grafana you wish to build from (replace master in the example). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add support for passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that something you think we might use ourselves? Without someone with that explicit need I don't see a big advantage over just extending our Dockerfile instead as actually using this feature would require forking our repo instead of just creating a new file. |
||
|
||
Example of how to build and run: | ||
```bash | ||
docker build -t grafana:5.0.0-custom . | ||
docker build -t grafana:master-with-plugins . | ||
docker run \ | ||
-d \ | ||
-p 3000:3000 \ | ||
--name=grafana \ | ||
grafana:5.0.0-custom | ||
grafana:master-with-plugins | ||
``` | ||
|
||
## Running specific version of Grafana | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,50 +2,70 @@ | |
|
||
: "${GF_PATHS_CONFIG:=/etc/grafana/grafana.ini}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll put the defaults in the Dockerfile using |
||
: "${GF_PATHS_DATA:=/var/lib/grafana}" | ||
: "${GF_PATHS_HOME:=/usr/share/grafana}" | ||
: "${GF_PATHS_LOGS:=/var/log/grafana}" | ||
: "${GF_PATHS_PLUGINS:=/var/lib/grafana/plugins}" | ||
: "${GF_PATHS_PROVISIONING:=/etc/grafana/provisioning}" | ||
|
||
chown -R grafana:grafana "$GF_PATHS_DATA" "$GF_PATHS_LOGS" || true | ||
PERMISSIONS_OK=0 | ||
|
||
if [ ! -r "$GF_PATHS_CONFIG" ]; then | ||
echo "GF_PATHS_CONFIG='$GF_PATHS_CONFIG' is not readable." | ||
PERMISSIONS_OK=1 | ||
fi | ||
|
||
if [ ! -w "$GF_PATHS_DATA" ]; then | ||
echo "GF_PATHS_DATA='$GF_PATHS_DATA' is not writable." | ||
PERMISSIONS_OK=1 | ||
fi | ||
|
||
if [ ! -r "$GF_PATHS_HOME" ]; then | ||
echo "GF_PATHS_HOME='$GF_PATHS_HOME' is not readable." | ||
PERMISSIONS_OK=1 | ||
fi | ||
|
||
if [ $PERMISSIONS_OK -eq 1 ]; then | ||
echo "You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migration-from-a-previous-version-of-the-docker-container-to-5-1-or-later" | ||
fi | ||
|
||
|
||
if [ ! -z ${GF_AWS_PROFILES+x} ]; then | ||
mkdir -p ~grafana/.aws/ | ||
> ~grafana/.aws/credentials | ||
mkdir -p "$GF_PATHS_HOME/.aws/" | ||
> "$GF_PATHS_HOME/.aws/credentials" | ||
|
||
for profile in ${GF_AWS_PROFILES}; do | ||
access_key_varname="GF_AWS_${profile}_ACCESS_KEY_ID" | ||
secret_key_varname="GF_AWS_${profile}_SECRET_ACCESS_KEY" | ||
region_varname="GF_AWS_${profile}_REGION" | ||
|
||
if [ ! -z "${!access_key_varname}" -a ! -z "${!secret_key_varname}" ]; then | ||
echo "[${profile}]" >> ~grafana/.aws/credentials | ||
echo "aws_access_key_id = ${!access_key_varname}" >> ~grafana/.aws/credentials | ||
echo "aws_secret_access_key = ${!secret_key_varname}" >> ~grafana/.aws/credentials | ||
echo "[${profile}]" >> "$GF_PATHS_HOME/.aws/credentials" | ||
echo "aws_access_key_id = ${!access_key_varname}" >> "$GF_PATHS_HOME/.aws/credentials" | ||
echo "aws_secret_access_key = ${!secret_key_varname}" >> "$GF_PATHS_HOME/.aws/credentials" | ||
if [ ! -z "${!region_varname}" ]; then | ||
echo "region = ${!region_varname}" >> ~grafana/.aws/credentials | ||
echo "region = ${!region_varname}" >> "$GF_PATHS_HOME/.aws/credentials" | ||
fi | ||
fi | ||
done | ||
|
||
chown grafana:grafana -R ~grafana/.aws | ||
chmod 600 ~grafana/.aws/credentials | ||
chmod 600 "$GF_PATHS_HOME/.aws/credentials" | ||
fi | ||
|
||
if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then | ||
OLDIFS=$IFS | ||
IFS=',' | ||
for plugin in ${GF_INSTALL_PLUGINS}; do | ||
IFS=$OLDIFS | ||
gosu grafana grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin} | ||
grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin} | ||
done | ||
fi | ||
|
||
exec gosu grafana /usr/sbin/grafana-server \ | ||
--homepath=/usr/share/grafana \ | ||
--config="$GF_PATHS_CONFIG" \ | ||
cfg:default.log.mode="console" \ | ||
cfg:default.paths.data="$GF_PATHS_DATA" \ | ||
cfg:default.paths.logs="$GF_PATHS_LOGS" \ | ||
cfg:default.paths.plugins="$GF_PATHS_PLUGINS" \ | ||
cfg:default.paths.provisioning=$GF_PATHS_PROVISIONING \ | ||
exec /usr/sbin/grafana-server \ | ||
--homepath="$GF_PATHS_HOME" \ | ||
--config="$GF_PATHS_CONFIG" \ | ||
cfg:default.log.mode="console" \ | ||
cfg:default.paths.data="$GF_PATHS_DATA" \ | ||
cfg:default.paths.logs="$GF_PATHS_LOGS" \ | ||
cfg:default.paths.plugins="$GF_PATHS_PLUGINS" \ | ||
cfg:default.paths.provisioning="$GF_PATHS_PROVISIONING" \ | ||
"$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we try something like
debian:9.3-slim
while at it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, forgot about that. Will look into it.