Metabase on Google App Engine
Asked Answered
S

3

8

I'm trying to set up Metabase on a gcloud engine using Google Cloud SQL (MySQL).

I've got it running using this git and this app.yaml:

runtime: custom
env: flex

# Metabase does not support horizontal scaling
#   https://github.com/metabase/metabase/issues/2754
#   https://cloud.google.com/appengine/docs/flexible/java/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1

env_variables:
 # MB_JETTY_PORT: 8080
  MB_DB_TYPE: mysql
  MB_DB_DBNAME: [db_name]
 # MB_DB_PORT: 5432
  MB_DB_USER: [db_user]
  MB_DB_PASS: [db_password]
 # MB_DB_HOST: 127.0.0.1
  CLOUD_SQL_INSTANCE: [project-id]:[location]:[instance-id]

I have 2 issues:

  1. The Metabase fails in connecting to the Cloud SQL - the Cloud SQL is part of the same project and App Engine is authorized.

  2. After I create my admin user in Metabase, I am only able to login for a few seconds (and only sometimes), but it keeps throwing me to either /setup or /auth/login saying the password doesn't match (when it does).

I hope someone can help - thank you!

Soybean answered 11/4, 2018 at 15:14 Comment(1)
Did you ever figure this out? Can you post an update and/or mark an answer as correct?Ouachita
C
2

So, we just got metabase running in Google App Engine with a Cloud SQL instance running PostgreSQL and these are the steps we went through.

First, create a Dockerfile:

FROM gcr.io/google-appengine/openjdk:8

EXPOSE 8080

ENV JAVA_OPTS "-XX:+IgnoreUnrecognizedVMOptions -Dfile.encoding=UTF-8 --add-opens=java.base/java.net=ALL-UNNAMED --add-modules=java.xml.bind"
ENV JAVA_TOOL_OPTIONS "-Xmx1g"

ADD https://downloads.metabase.com/enterprise/v1.1.6/metabase.jar $APP_DESTINATION

We tried pushing the memory further down, but 1 GB seemed to be the sweet spot. On to the app.yaml:

runtime: custom
env: flex

manual_scaling:
  instances: 1

resources:
  cpu: 1
  memory_gb: 1
  disk_size_gb: 10

readiness_check:
  path: "/api/health"
  check_interval_sec: 5
  timeout_sec: 5
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 600

beta_settings:
  cloud_sql_instances: <Instance-Connection-Name>=tcp:5432

env_variables:
  MB_DB_DBNAME: 'metabase'
  MB_DB_TYPE: 'postgres'
  MB_DB_HOST: '172.17.0.1'
  MB_DB_PORT: '5432'
  MB_DB_USER: '<username>'
  MB_DB_PASS: '<password>'
  MB_JETTY_PORT: '8080'

Note the beta_settings field at the bottom, which handles what akilesh raj was doing manually. Also, the trailing =tcp:5432 is required, since metabase does not support unix sockets yet.

Relevant documentation can be found here.

Cedric answered 5/9, 2019 at 19:58 Comment(1)
Worked like a charm. Note you can swap the "ADD downloads.metabase.com/enterprise/v1.1.6/metabase.jar $APP_DESTINATION" line to point to a non-enterprise .jar file.Underhanded
I
0

Although I am not sure of the reason, I think authorizing the service account of App engine is not enough for accessing cloud SQL.

In order to authorize your App to access your Cloud SQL you can do either of both methods:

  1. Within the app.yaml file, configure an environment variable pointing to a a service account key file with a correct authorization configuration to Cloud SQL :

    env_variables: GOOGLE_APPLICATION_CREDENTIALS=[YOURKEYFILE].json

  2. Your code executes a fetch of an authorized service account key from a bucket, and loads it afterwards with the help of the Cloud storage Client library. Seeing your runtime is custom, the pseudocode which would be translated into the code you use is the following:

    .....

Inflexible answered 4/5, 2018 at 8:3 Comment(1)
Are you talking about connecting to the backend MB database, or additional databases through the UI? I am able to connect to a cloud sql backend without even using cloud sql proxy--it was enough to give the cloud sql client role to the GAE service account.Litigate
E
0

It is better to use the Cloud proxy to connect to the SQL instances. This way you do not have to authorize the instances in CloudSQL every time there is a new instance. More on CloudProxy here

As for setting up Metabase in the Google App Engine, I am including the app.yaml and Dockerfile below.

The app.yaml file,

runtime: custom
env: flex

manual_scaling:
instances: 1

env variables:
    MB_DB_TYPE: mysql
    MB_DB_DBNAME: metabase
    MB_DB_PORT: 3306
    MB_DB_USER: root
    MB_DB_PASS: password
    MB_DB_HOST: 127.0.0.1
    METABASE_SQL_INSTANCE: instance_name

The Dockerfile,

FROM gcr.io/google-appengine/openjdk:8

# Set locale to UTF-8
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# Install CloudProxy
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 ./cloud_sql_proxy
RUN chmod +x ./cloud_sql_proxy

#Download the latest version of Metabase
ADD http://downloads.metabase.com/v0.21.1/metabase.jar ./metabase.jar

CMD nohup ./cloud_sql_proxy -instances=$METABASE_SQL_INSTANCE=tcp:$MB_DB_PORT & java -jar /startup/metabase.jar
Ethylethylate answered 29/5, 2018 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.