Skip to content

Commit 4e0817b

Browse files
committed
Add metabase stack
1 parent df61d49 commit 4e0817b

File tree

6 files changed

+93
-11
lines changed

6 files changed

+93
-11
lines changed

services/metabase/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
configure_metabase.sql
2+
docker-compose.yml

services/metabase/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ up: ${TEMP_COMPOSE} ## Deploys metabase stack
88

99
${TEMP_COMPOSE}: docker-compose.yml .env
1010
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
11+
12+
docker-compose.yml: docker-compose.yml.j2 .env .venv
13+
@$(call jinja, $<, .env, $@)
14+
15+
configure_metabase.sql: .env
16+
@set -o allexport; source $<; set +o allexport; \
17+
envsubst < $@.template > $@
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE USER ${METABASE_POSTGRES_USER} WITH PASSWORD '${METABASE_POSTGRES_PASSWORD}';
2+
3+
-- relies on readonly role aldready existing in the database
4+
GRANT ${POSTGRES_DB}_readonly TO ${METABASE_POSTGRES_USER};
5+
6+
CREATE DATABASE ${METABASE_POSTGRES_DB}
7+
WITH OWNER ${METABASE_POSTGRES_USER};

services/metabase/docker-compose.yml renamed to services/metabase/docker-compose.yml.j2

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ services:
88
- public
99
- monitored
1010
environment:
11+
# Metabase logsd doc: https://www.metabase.com/docs/v0.54/configuring-metabase/log-configuration
12+
- JAVA_OPTS=-Dlog4j.configurationFile=file:/tmp/my_log4j2.xml
1113
# https://www.metabase.com/docs/v0.54/installation-and-operation/configuring-application-database
1214
- MB_DB_TYPE=postgres
1315
- MB_DB_DBNAME=metabase
1416
- MB_DB_HOST=${POSTGRES_HOST}
1517
- MB_DB_PORT=${POSTGRES_PORT}
16-
- MB_DB_USER=${POSTGRES_USER}
17-
- MB_DB_PASS=${POSTGRES_PASSWORD}
18+
- MB_DB_USER=${METABASE_POSTGRES_USER}
19+
- MB_DB_PASS=${METABASE_POSTGRES_PASSWORD}
1820
# https://www.metabase.com/docs/v0.54/installation-and-operation/running-metabase-on-docker#setting-the-java-timezone
1921
- JAVA_TIMEZONE=UTC
2022
deploy:
23+
# we do not need high availability. This service is not critical
24+
replicas: 1
2125
update_config:
2226
parallelism: 1
2327
order: start-first
@@ -27,6 +31,7 @@ services:
2731
constraints:
2832
- node.labels.ops==true
2933
labels:
34+
# TODO: add prometheus metrics
3035
- traefik.enable=true
3136
- traefik.docker.network=${PUBLIC_NETWORK}
3237
# router
@@ -37,18 +42,31 @@ services:
3742
- traefik.http.routers.metabase.middlewares=ops_whitelist_ips@swarm, ops_gzip@swarm, ops_auth@swarm, metabase_stripprefixregex
3843
# service
3944
- traefik.http.services.metabase.loadbalancer.server.port=3000
40-
# resources:
41-
# limits:
42-
# memory: 512M
43-
# cpus: "1.0"
44-
# reservations:
45-
# memory: 128M
46-
# cpus: "0.2"
45+
- traefik.http.services.metabase.loadbalancer.healthcheck.path=/api/health
46+
- traefik.http.services.metabase.loadbalancer.healthcheck.interval=5s
47+
- traefik.http.services.metabase.loadbalancer.healthcheck.timeout=1s
48+
49+
# https://www.metabase.com/learn/metabase-basics/administration/administration-and-operation/metabase-in-production
50+
resources:
51+
limits:
52+
memory: 2G
53+
cpus: "2.0"
54+
reservations:
55+
memory: 1G
56+
cpus: "1.0"
4757
healthcheck:
4858
test: curl --fail -I http://localhost:3000/api/health || exit 1
4959
interval: 15s
5060
timeout: 5s
5161
retries: 5
62+
configs:
63+
- source: logging_configuration
64+
target: /tmp/my_log4j2.xml
65+
66+
configs:
67+
logging_configuration:
68+
file: ./logging_configuration.xml
69+
name: {{ STACK_NAME }}_logging_configuration_{{ "./logging_configuration.xml" | sha256file | substring(0,10) }}
5270

5371
networks:
5472
public:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Original file: https://github.com/metabase/metabase/blob/v0.54.14.3/resources/log4j2.xml -->
3+
4+
<Configuration>
5+
<Appenders>
6+
<Console name="STDOUT" target="SYSTEM_OUT" follow="true">
7+
<PatternLayout pattern="%date %level %logger{2} :: %message %notEmpty{%X}%n%throwable">
8+
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
9+
</PatternLayout>
10+
</Console>
11+
12+
<!-- This file appender is provided as an example -->
13+
<!--
14+
<RollingFile name="FILE" fileName="${logfile.path}/metabase.log" filePattern="${logfile.path}/metabase.log.%i">
15+
<Policies>
16+
<SizeBasedTriggeringPolicy size="500 MB"/>
17+
</Policies>
18+
<DefaultRolloverStrategy max="2"/>
19+
<PatternLayout pattern="%d [%t] %-5p%c - %m%n">
20+
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
21+
</PatternLayout>
22+
</RollingFile>
23+
-->
24+
</Appenders>
25+
26+
<Loggers>
27+
<Logger name="com.mchange" level="ERROR"/>
28+
<Logger name="liquibase" level="INFO"/>
29+
<Logger name="metabase" level="INFO"/>
30+
<Logger name="metabase-enterprise" level="INFO"/>
31+
<Logger name="metabase.metabot" level="INFO"/>
32+
<Logger name="metabase.plugins" level="INFO"/>
33+
<Logger name="metabase.query-processor.async" level="INFO"/>
34+
<Logger name="metabase.server.middleware" level="INFO"/>
35+
<Logger name="org.quartz" level="INFO"/>
36+
<Logger name="net.snowflake.client.jdbc.SnowflakeConnectString" level="ERROR"/>
37+
<Logger name="net.snowflake.client.core.SessionUtil" level="FATAL"/>
38+
39+
<Root level="WARN">
40+
<AppenderRef ref="STDOUT"/>
41+
</Root>
42+
</Loggers>
43+
</Configuration>

services/metabase/template.env

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
STACK_NAME=${STACK_NAME}
2+
13
PUBLIC_NETWORK=${PUBLIC_NETWORK}
24
MONITORED_NETWORK=${MONITORED_NETWORK}
35
ADMIN_DOMAIN=${ADMIN_DOMAIN}
46

57
POSTGRES_HOST=${POSTGRES_HOST}
68
POSTGRES_PORT=${POSTGRES_PORT}
7-
POSTGRES_USER=${POSTGRES_USER}
8-
POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
9+
POSTGRES_DB=${POSTGRES_DB}
10+
11+
METABASE_POSTGRES_USER=${METABASE_POSTGRES_USER}
12+
METABASE_POSTGRES_PASSWORD=${METABASE_POSTGRES_PASSWORD}
13+
METABASE_POSTGRES_DB=${METABASE_POSTGRES_DB}

0 commit comments

Comments
 (0)