Skip to content

Instantly share code, notes, and snippets.

@dev-head
Last active August 11, 2021 17:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dev-head/9ba1dfe3b3a038aa479e4288d8062157 to your computer and use it in GitHub Desktop.
Save dev-head/9ba1dfe3b3a038aa479e4288d8062157 to your computer and use it in GitHub Desktop.
Looker : Docker : Docker Compose : Staging
#!/usr/bin/env bash
setHostname() {
# If we're in ECS land, lets get host name from the meta data on the ec2 node
if [[ ! -z "${ECS_CONTAINER_METADATA_FILE}" ]]; then
_HOSTNAME=$(curl -s -XGET http://169.254.169.254/latest/meta-data/local-hostname)
else
_HOSTNAME=${HOSTNAME:-$(hostname)}
fi
sudo hostname ${_HOSTNAME}
}
_HOSTNAME=""
setHostname
echo "hostname:[${_HOSTNAME}]"
# dynamic looker args created at run time for the container.
# this is needed for proper clustering.
if [[ "$(cat /home/looker/looker/lookerstart.cfg)" != *"--hostname"* ]]; then
echo "[Appending hostname]::[${_HOSTNAME}]::[/home/looker/looker/lookerstart.cfg]"
echo "" >> /home/looker/looker/lookerstart.cfg
echo "LOOKERARGS=\"\${LOOKERARGS} --hostname=${_HOSTNAME}\"" >> /home/looker/looker/lookerstart.cfg
fi
# the exit process isn't cleaning itself up, so we'll purge these if we see them.
if [[ -f "/home/looker/looker/.deploying" ]]; then
echo "Removing [/home/looker/looker/.deploying] file"
rm /home/looker/looker/.deploying
fi
if [[ -f "/home/looker/looker/.starting" ]]; then
echo "Removing [/home/looker/looker/.starting] file"
rm /home/looker/looker/.starting
fi
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo "starting up container for [looker] service"
echo "[startup args configured]++++++++++++++++++++++++++++++++++++++"
cat /home/looker/looker/lookerstart.cfg
exec $@
dialect: mysql
host: mysql
username: looker
password: passwordsareyourenemy
database: looker
port: 3306
#
# Custom docker runtime options.
#
LOOKERARGS=""
LOOKERARGS="${LOOKERARGS} --no-daemonize"
LOOKERARGS="${LOOKERARGS} --log-level=debug"
LOOKERARGS="${LOOKERARGS} --internal-db-creds=/home/looker/looker/database.yml"
LOOKERARGS="${LOOKERARGS} --shared-storage-dir=/srv/data/looker"
LOOKERARGS="${LOOKERARGS} --disable-db-log"
LOOKERARGS="${LOOKERARGS} --error-emails-to=happy@go.lucky"
LOOKERARGS="${LOOKERARGS} --unlimited-scheduler-threads=0 --scheduler-threads=0 --scheduler-query-limit=0 --scheduler-query-timeout=1"
LOOKERARGS="${LOOKERARGS} --clustered"
LOOKERARGS="${LOOKERARGS} --no-ssl"
LOOKERARGS="${LOOKERARGS} --staging"
JAVAMEM="4096m"
license_key: "USEA-STAG-ELIC-ENCE-HERE"
host_url: "https://looker.oh.yeah"
user:
first_name: "jane"
last_name: "mc jane"
email: "janes@here.now"
password: "supernotsecurepasswordherehuh"

Looker Docker

Description

This is meant and used for local development environment for looker; not really designed for production. (though the image is the same one we use) The files listed in here with the __config__ prefix should exist in a config directory off the root. (Github doesn't allow slashes in the name) This configuration has a load balancer service that automatically discoveres new looker containers, so you can just scale up once you let a single container get started and fully configured.

Directory structure

models will be saved in data/looker/model*

bin/docker-entrypoint.sh
config/database.yml
config/lookerstart.cfg
config/provision.yml
data/looker
data/mysql
Dockerfile
Dockerfile.mysql
docker-compose.yml

Run looker

docker-compose up -d 
docker-compose logs -f --tail 100

Scale looker

docker-compose scale looker=2

Mysql

Do you need to Seed your database? Forget everything above (ish)

in order to seed your database you'll need to do some manual work to get your data into the database, before running looker container. If you don't do this, looker will generate it's database on it's own.

start up mysql and do your import first

docker-compose up -d mysql 

start up the remaining services, after you've seeded the database

docker-compose up -d lb looker
docker-compose logs -f --tail 100 

Links / References

version: '2.1'
services:
lb:
image: dockercloud/haproxy:latest
links:
- looker
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
looker:
image: hey/looker:latest
build:
context: .
dockerfile: Dockerfile
volumes:
- ./data/looker:/srv/data/looker
links:
- "mysql"
depends_on:
- mysql
#
# Need to build in order to remap the user ids for mounted volumes.
#
mysql:
image: ue/looker-mysql:latest
build:
context: .
dockerfile: Dockerfile.mysql
ports:
- "3306:3306"
volumes:
- ./data/mysql/data:/var/lib/mysql:rw
environment:
MYSQL_ROOT_PASSWORD: blahblahblah
MYSQL_DATABASE: looker
MYSQL_USER: looker
MYSQL_PASSWORD: bleepbloop
MYSQL_ALLOW_EMPTY_PASSWORD: 0
FROM ubuntu:16.04
RUN echo "[INFO]::[installing]::[base packages]" \
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
software-properties-common libssl-dev libmcrypt-dev openssl ca-certificates \
git ntp curl tzdata bzip2 libfontconfig1 phantomjs mysql-client sudo jq \
&& apt-get autoclean && apt-get clean && apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN echo "[INFO]::[installing]::[java packages]" \
&& apt-get update \
&& add-apt-repository -y ppa:webupd8team/java \
&& apt-get update \
&& echo oracle-java8-installer shared/accepted-oracle-license-v1-1 boolean true | debconf-set-selections \
&& echo oracle-java8-installer shared/present-oracle-license-v1-1 note | debconf-set-selections \
&& yes | DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes --no-install-recommends --no-install-suggests oracle-java8-installer \
&& apt-get remove -y software-properties-common && apt-get remove -y software-properties-common && apt-get autoclean && apt-get clean && apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
ARG LOOKER_VERSION="5.0"
RUN echo "[INFO]::[configure]::[misc]" \
&& cp /etc/sysctl.conf /etc/sysctl.conf.dist \
&& echo "net.ipv4.tcp_keepalive_time=200" | tee -a /etc/sysctl.conf \
&& echo "net.ipv4.tcp_keepalive_intvl=200" | tee -a /etc/sysctl.conf \
&& echo "net.ipv4.tcp_keepalive_probes=5" | tee -a /etc/sysctl.conf \
&& groupadd -g 1002 "looker" || true \
&& useradd -m -u 1002 -g "looker" "looker" || true\
&& cp /etc/launchd.conf /etc/launchd.conf.dist || true \
&& echo "limit maxfiles 8192 8192" | tee -a /etc/launchd.conf \
&& echo "looker soft nofile 8192" | tee -a /etc/launchd.conf \
&& echo "looker hard nofile 8192" | tee -a /etc/launchd.conf \
&& echo '%looker ALL=(ALL) NOPASSWD:ALL' | tee -a /etc/sudoers
#
# insecure download should be validated.
#
RUN echo "[INFO]::[install]::[looker]" \
&& mkdir -p /home/looker/looker \
&& curl -o /home/looker/looker/looker.jar https://s3.amazonaws.com/download.looker.com/aeHee2HiNeekoh3uIu6hec3W/looker-${LOOKER_VERSION}-latest.jar \
&& curl -o /home/looker/looker/looker-service https://raw.githubusercontent.com/looker/customer-scripts/master/startup_scripts/looker
COPY ./config /tmp/build-configs
RUN echo "[INFO]::[configure]::[looker]" \
&& chmod 0750 /home/looker/looker/looker-service \
&& mv /tmp/build-configs/lookerstart.cfg /home/looker/looker/lookerstart.cfg \
&& mv /tmp/build-configs/database.yml /home/looker/looker/database.yml \
&& mv /tmp/build-configs/provision.yml /home/looker/looker/provision.yml \
&& chown -R looker:looker /home/looker/looker
#
# Move in standard entrypoint script and configure to run through TINI for safety.
#
COPY bin/docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ARG TINI_VERSION="v0.14.0"
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
USER looker
EXPOSE 9999
ENTRYPOINT ["/tini", "--"]
CMD ["/entrypoint.sh", "/home/looker/looker/looker-service", "start"]
FROM percona:5.7
RUN usermod -u 1000 mysql \
&& groupmod -g 1002 staff \
&& groupmod -g 50 mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment