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

Metabase autosetup v2 #12

Open
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions stacks/setup-container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## What
This docker-compose will simply start Metabase with a PostgreSQL app db and will create the admin user

## How
A setup container runs a shell script which will wait for Metabase to be alive and then set it up with:
user: [email protected]
pass: metabot1

## Additions
The script will also add the PostgreSQL database with sample data to Metabase.
65 changes: 45 additions & 20 deletions stacks/setup-container/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
version: '3.9'
services:
metabase_setup:
image: metabase/metabase-enterprise:v1.42.3
hostname: metabase_setup
container_name: metabase_setup
metabase:
image: metabase/metabase:v0.43.0
container_name: metabase
hostname: metabase
volumes:
- /dev/urandom:/dev/random:ro
ports:
- 3001:3000
networks:
- 3031:3000
environment:
- "MB_DB_TYPE=postgres"
- "MB_DB_DBNAME=metabase"
- "MB_DB_PORT=5432"
- "MB_DB_USER=metabase"
- "MB_DB_PASS=mysecretpassword"
- "MB_DB_HOST=postgres-app-db"
networks:
- metanet1
depends_on:
- postgres-app-db
postgres-app-db:
image: postgres:14.2-alpine
container_name: postgres-app-db
hostname: postgres-app-db
ports:
- 5432:5432
environment:
- "POSTGRES_USER=metabase"
- "POSTGRES_DB=metabase"
- "POSTGRES_PASSWORD=mysecretpassword"
volumes:
- $PWD/postgres_origin:/var/lib/postgresql/data
networks:
- metanet1
setup:
image: bash:5.1.16
container_name: setup
volumes:
- $PWD/setup:/tmp
networks:
- metanet1
command: >
sh -c "apk add curl jq && \
curl -L 'https://raw.githubusercontent.com/nickjj/wait-until/v0.2.0/wait-until' -o /usr/local/bin/wait-until && \
chmod +x /usr/local/bin/wait-until && \
wait-until \"echo 'Checking if Metabase is ready' && curl -s 'http://metabase_setup:3000/api/health' | grep -ioE \"ok\"\" 60 && \
if curl -s 'http://metabase_setup:3000/api/session/properties' | jq -r '.\"setup-token\"' | grep -ioE \"null\"; then echo 'Instance already configured, exiting'; else \
echo 'Setting up the instance' && \
token=$$(curl -s http://metabase_setup:3000/api/session/properties | jq -r '.\"setup-token\"') && \
echo 'Setup token fetched, now configuring with:' && \
echo \"{'token':'$$token','user':{'first_name':'a','last_name':'b','email':'[email protected]','site_name':'metabot1','password':'metabot1','password_confirm':'metabot1'},'database':null,'invite':null,'prefs':{'site_name':'metabot1','site_locale':'en','allow_tracking':'false'}}\" > file.json && \
sed 's/'\''/\"/g' file.json > file2.json && \
cat file2.json && \
curl -s http://metabase_setup:3000/api/setup -H 'Content-Type: application/json' --data-binary @file2.json && echo ' < Admin session token, exiting'; fi"
depends_on:
- metabase
command: sh /tmp/metabase-setup.sh metabase:3000
postgres-data1:
image: metabase/qa-databases:postgres-sample-12
container_name: postgres-data1
ports:
- 5433:5432
hostname: postgres-data1
networks:
- metanet1
networks:
metanet1:
driver: bridge
driver: bridge
22 changes: 22 additions & 0 deletions stacks/setup-container/setup/metabase-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

echo "seting up $1"
# get deps
apk add curl jq
# get the wait-until script
curl -L https://raw.githubusercontent.com/nickjj/wait-until/v0.2.0/wait-until -o /usr/local/bin/wait-until && \
chmod +x /usr/local/bin/wait-until
# run the script and everything else
wait-until "echo 'Checking if Metabase is ready' && curl -s http://$1/api/health | grep -ioE 'ok'" 60 && \
if curl -s http://$1/api/session/properties | jq -r '."setup-token"' | grep -ioE "null"; then echo 'Instance already configured, exiting (or <v43)'; else \
echo 'Setting up the instance' && \
token=$(curl -s http://$1/api/session/properties | jq -r '."setup-token"') && \
echo 'Setup token fetched, now configuring with:' && \
echo "{'token':'$token','user':{'first_name':'a','last_name':'b','email':'[email protected]','site_name':'metabot1','password':'metabot1','password_confirm':'metabot1'},'database':null,'invite':null,'prefs':{'site_name':'metabot1','site_locale':'en','allow_tracking':'false'}}" > file.json && \
sed 's/'\''/\"/g' file.json > file2.json && \
cat file2.json && \
sessionToken=$(curl -s http://$1/api/setup -H 'Content-Type: application/json' --data-binary @file2.json | jq -r '.id') && echo ' < Admin session token, exiting' && \
# creating a postgres
curl -s -X POST http://$1/api/database -H 'Content-Type: application/json' --cookie "metabase.SESSION=$sessionToken" --data '{"engine":"postgres","name":"pg","details":{"host":"postgres-data1","port":"5432","dbname":"sample","user":"metabase","password":"metasample123","schema-filters-type":"all","ssl":false,"tunnel-enabled":false,"advanced-options":false},"is_full_sync":true}'; fi

# curl -s http://$1/api/database -H 'Content-Type: application/json' --cookie "metabase.SESSION=$sessionToken" --data {'engine':'postgres','name':'pg','details':{'host':'postgres-data1','port':null,'dbname':'sample','user':'metabase','password':'metasample123','schema-filters-type':'all','ssl':'false','tunnel-enabled':'false','advanced-options':'false'},'is_full_sync':'true'}