Skip to content

Instantly share code, notes, and snippets.

@andsens andsens/Dockerfile
Last active Jun 6, 2019

Embed
What would you like to do?
Kibana docker container with pre-optimized bundles
ARG KIBANA_VERSION
FROM docker.elastic.co/kibana/kibana:${KIBANA_VERSION}
ARG KIBANA_VERSION
ARG LOGTRAIL_VERSION
USER root
RUN NODE_OPTIONS="--max_old_space_size=4096" kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v${LOGTRAIL_VERSION}/logtrail-${KIBANA_VERSION}-${LOGTRAIL_VERSION}.zip
COPY kibana.yaml /usr/share/kibana/config/kibana.yml
COPY elasticsearch.repo /etc/yum.repos.d/elasticsearch.repo
RUN \
set -e; \
yum install -y sudo java-11-openjdk-headless.x86_64 elasticsearch; \
( \
set -e; \
sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch &>/tmp/elasticsearch & \
line=0; \
until grep -qm 1 'LicenseService.*license.*mode \[basic\] - valid' /tmp/elasticsearch; do \
sleep 1; \
tail -qn +$((line+1)) /tmp/elasticsearch; \
line=$(wc -l /tmp/elasticsearch | cut -d' ' -f1); \
pgrep -u elasticsearch >/dev/null; \
done; \
echo 'Elasticsearch started' \
); \
( \
set -e; \
NODE_OPTIONS="--max_old_space_size=4096" sudo -u kibana /usr/local/bin/kibana-docker &>/tmp/kibana & \
line=0; \
until grep -qm 1 'Optimization of bundles for .* complete in .* seconds' /tmp/kibana; do \
sleep 1; \
tail -qn +$((line+1)) /tmp/kibana; \
line=$(wc -l /tmp/kibana | cut -d' ' -f1); \
pgrep -u kibana >/dev/null; \
done \
); \
pkill -u elasticsearch; \
pkill -u kibana; \
until pgrep -u elasticsearch >/dev/null; do sleep 1; done; \
until pgrep -u kibana >/dev/null; do sleep 1; done; \
yum remove -y sudo java-11-openjdk-headless.x86_64 elasticsearch; \
rm /etc/yum.repos.d/elasticsearch.repo; \
yum -y autoremove; \
yum clean all; \
rm -rf /var/cache/yum
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
elasticsearch.hosts: http://127.0.0.1:9200
server.name: kibana
server.host: 0.0.0.0
xpack.apm.ui.enabled: false
xpack.graph.enabled: false
xpack.grokdebugger.enabled: false
xpack.searchprofiler.enabled: false
xpack.ml.enabled: false
xpack.monitoring.enabled: false
xpack.reporting.enabled: false
xpack.security.enabled: false
@andsens

This comment has been minimized.

Copy link
Owner Author

commented Jun 5, 2019

The optimization can take from 5 minutes up to 30 minutes in my experience, so when building the container be patient.
You can throw some echos in there to give you a status, but the optimization process itself is pretty silent so you won't be able to see the progress of the job that takes the most amount of time anyways.

The COPY --from=0 /usr/share/kibana /usr/share/kibana could probably be optimized, especially because it overwrites existing kibana assets that do not need overwriting. This of course causes the resulting image to balloon in size. Still, better than waiting ~30 mins. when starting a new pod :-)

@andsens

This comment has been minimized.

Copy link
Owner Author

commented Jun 5, 2019

Updated. Fixes:

  • The script fails when ES or kibana dies
  • ES & Kibana logs are now written to stdout
  • Cleaner exit

Make sure to check the Kibana output! Things like an ES version mismatch will not cause the script to fail.

@andsens

This comment has been minimized.

Copy link
Owner Author

commented Jun 6, 2019

Updated. Reduced size by not using a build container and instead simply uninstall ES after optimization is done.
This reduces the image size from ~1.6GB to 794MB, only 60MB more than the elastico base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.