A ready-to-use production provisioning script

Not sure where to post this (a PR seems too big of a thing for this), but thought I’d share this, as it took me several (night) hours to come to this simple script. It is intended for use as an entry point of a production Metabase Docker container and what it does is start a newly-created Metabase instance and migrate the DB to production DBMS. Thus, the newly-created Docker container can be just started and it will do the right thing automatically. (Note: the linking of urandom to random doesn’t exactly fall into the provisioning, but I found it to necessary to prevent extremely long - 10+ minutes - startup times.) The provisioned dir should be mapped to host FS.

#!/bin/bash

## Use somewhat less quality randomness source to prevent long startup times
ln -sf /dev/urandom /dev/random

PROVISIONED_FLAG=/app/provisioned/flag
if [ ! -e $PROVISIONED_FLAG ]; then
        ## We have not been provisioned yet. Initialize ourselves,
        ## migrate to production DBMS, note that we are now provisioned
        ## and start the app.
        echo STARTING PROVISIONING
        ## Start Metabase in "start profiling" mode, so it will stop right after starting.
        ## Override the DB setting with H2, so it will initialize its internal DB.
        echo Initializing H2 DB
        java $JAVA_OPTS -DMB_DB_TYPE=h2 -jar /app/metabase.jar profile &&
                ## Migrate the newly created H2 DB to MySQL
                echo Migrating to production DB &&
                java $JAVA_OPTS -jar /app/metabase.jar load-from-h2 &&
                ## Indicate to future runs we have been provisioned
                echo> $PROVISIONED_FLAG &&
                ## Start Metabase
                echo Starting Metabase &&
                exec /app/run_metabase.sh
else
        ## We have already been provisioned, just start the app
        exec /app/run_metabase.sh
fi
1 Like