{"id":15113794,"url":"https://github.com/deepmancer/metabase-postgres-docker","last_synced_at":"2026-02-17T22:01:53.559Z","repository":{"id":251716004,"uuid":"838225288","full_name":"deepmancer/metabase-postgres-docker","owner":"deepmancer","description":"Automates the addition of PostgreSQL databases to a Metabase Docker container via the Metabase API. Simplifies data source integration.","archived":false,"fork":false,"pushed_at":"2025-02-07T02:24:18.000Z","size":65,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-22T17:49:28.220Z","etag":null,"topics":["automation","bash-script","docker","docker-compose","metabase","metabase-api","metabase-data","metabase-deployment","postgres","postgresql","script"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepmancer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-05T07:53:53.000Z","updated_at":"2025-02-07T02:24:21.000Z","dependencies_parsed_at":"2025-02-08T09:30:54.913Z","dependency_job_id":"26ef988e-fc3e-4d64-a49a-cda02e6bc77e","html_url":"https://github.com/deepmancer/metabase-postgres-docker","commit_stats":null,"previous_names":["alirezaheidari-cs/metabase-automatic-config","deepmancer/metabase-postgres-docker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deepmancer/metabase-postgres-docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fmetabase-postgres-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fmetabase-postgres-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fmetabase-postgres-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fmetabase-postgres-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepmancer","download_url":"https://codeload.github.com/deepmancer/metabase-postgres-docker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepmancer%2Fmetabase-postgres-docker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29559961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash-script","docker","docker-compose","metabase","metabase-api","metabase-data","metabase-deployment","postgres","postgresql","script"],"created_at":"2024-09-26T01:23:18.212Z","updated_at":"2026-02-17T22:01:53.536Z","avatar_url":"https://github.com/deepmancer.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 Metabase Automatic Docker Integration\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Metabase-509EE3.svg?style=for-the-badge\u0026logo=Metabase\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/PostgreSQL-4169E1.svg?style=for-the-badge\u0026logo=PostgreSQL\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/shell_script-%23121011.svg?style=for-the-badge\u0026logo=gnu-bash\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Linux-FCC624.svg?style=for-the-badge\u0026logo=Linux\u0026logoColor=black\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Docker-2496ED.svg?style=for-the-badge\u0026logo=Docker\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/GNU%20Bash-4EAA25.svg?style=for-the-badge\u0026logo=GNU-Bash\u0026logoColor=white\"/\u003e\n\u003c/p\u003e\n\n\nWelcome to the **Metabase Automatic Docker Integration Script** repository! This handy Bash script automates the process of integrating PostgreSQL databases into your Metabase Docker container. By interacting with the Metabase API, this script streamlines database management, saving you time and reducing manual configuration.\n\n---\n\n## ✨ Features\n\nThis script does the heavy lifting for you:\n1. **Automatic Network Configuration**: Fetches the gateway IP of your specified Docker network.\n2. **Seamless Authentication**: Authenticates with the Metabase API to get a session token.\n3. **Database Integration**: Adds your PostgreSQL databases to Metabase with just one command.\n\n## 🚨 Prerequisites\n\nBefore you dive in, make sure you have these tools ready:\n- **jq**: A lightweight and flexible command-line JSON processor.\n- **Docker Compose**: To set up and manage your Metabase service with a PostgreSQL backend.\n\nHere’s a sample `docker-compose.yml` to get you started:\n\n```yaml\nservices:\n  metabase:\n    image: metabase/metabase:latest\n    container_name: metabase\n    hostname: metabase\n    ports:\n      - \"3000:3000\"\n    environment:\n      MB_DB_TYPE: \"postgres\"\n      MB_DB_DBNAME: \"metabase_db\"\n      MB_DB_PORT: \"5432\"\n      MB_DB_USER: \"metabase_user\"\n      MB_DB_PASS: \"metabase_password\"\n      MB_DB_HOST: \"metabase_db\"\n      MB_ADMIN_EMAIL: \"youremail@example.com\"\n      MB_USER_EMAIL: \"youremail@example.com\"\n      MB_USER_PASSWORD: \"youpassword\"\n      MB_DISABLE_SESSION_THROTTLE: \"true\"\n      MB_SOURCE_ADDRESS_HEADER: NULL\n      MB_SHOW_LIGHTHOUSE_ILLUSTRATION: \"false\"\n      MB_NO_SURVEYS: \"true\"\n      MB_LOAD_ANALYTICS_CONTENT: \"false\"\n      MB_ANON_TRACKING_ENABLED: \"false\"\n      MB_SETUP_TOKEN: \"\"\n    volumes:\n      - metabase_data:/metabase-data\n    depends_on:\n      - metabase_db\n\n  metabase_db:\n    image: postgres:16.3\n    container_name: \"metabase_db\"\n    hostname: \"metabase_db\"\n    ports:\n      - \"5858:5432\"\n    environment:\n      POSTGRES_DB: \"metabase_db\"\n      POSTGRES_USER: \"metabase_user\"\n      POSTGRES_PASSWORD: \"metabase_password\"\n    volumes:\n      - metabase_db_data:/var/lib/postgresql/data\n\nvolumes:\n  metabase_data:\n  metabase_db_data:\n```\n\n---\n\n## 📝 Script Breakdown\n\n### 1. Configure Your Environment\n\nStart by setting up your script with essential variables. Tailor these to match your Metabase setup and Docker network:\n\n```bash\nMETABASE_URL=\"http://localhost:3000/api\"\nMETABASE_USERNAME=\"something@example.com\"\nMETABASE_PASSWORD=\"yourpassword\"\n\nNETWORK_NAME=\"your_private_network_name\"\n```\n\n### 2. Find the Docker Network Gateway IP\n\nThe script will automatically retrieve the gateway IP for your Docker network. If it can't find one, it will default to `127.0.0.1`:\n\n```bash\nGATEWAY_IP=$(docker network inspect \"$NETWORK_NAME\" --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}')\nif [ -z \"$GATEWAY_IP\" ]; then\n  GATEWAY_IP=\"127.0.0.1\"\n  echo \"Gateway IP for network $NETWORK_NAME not found. Using default IP $GATEWAY_IP.\"\nelse\n  echo \"Gateway IP for network $NETWORK_NAME is $GATEWAY_IP\"\nfi\n```\n\n### 3. Define Your Database Configurations\n\nAdd the PostgreSQL databases you wish to integrate into the `DATABASES` array. The format is:\n\n```\n\"NAME|NETWORK_IP|PORT|DB_NAME|USER|PASSWORD\"\n```\n\nFor example:\n\n```bash\nDATABASES=(\n  \"User Database|$GATEWAY_IP|5438|user_database|user_user|user_password\"\n  # Add more databases here\n)\n```\n\n### 4. Authenticate with Metabase\n\nThis function logs into your Metabase instance and grabs a session token:\n\n```bash\nauthenticate_metabase() {\n  echo \"Authenticating with Metabase...\"\n  SESSION_ID=$(curl -s -X POST -H \"Content-Type: application/json\"     -d \"{\"username\": \"${METABASE_USERNAME}\", \"password\": \"${METABASE_PASSWORD}\"}\"     \"${METABASE_URL}/session\" | jq -r '.id')\n\n  if [ -z \"$SESSION_ID\" ]; then\n    echo \"Authentication failed. Exiting.\"\n    exit 1\n  fi\n\n  echo \"Authenticated successfully. Session ID: ${SESSION_ID}\"\n}\n```\n\n### 5. Add Your Databases to Metabase\n\nThis function sends a request to the Metabase API to add each database:\n\n```bash\nadd_database() {\n  local NAME=$1\n  local HOST=$2\n  local PORT=$3\n  local DBNAME=$4\n  local USER=$5\n  local PASSWORD=$6\n\n  echo \"Adding database: $NAME...\"\n  \n  RESPONSE=$(curl -s -X POST -H \"Content-Type: application/json\" -H \"X-Metabase-Session: ${SESSION_ID}\"     -d \"{\n      \"name\": \"${NAME}\",\n      \"engine\": \"postgres\",\n      \"details\": {\n        \"host\": \"${HOST}\",\n        \"port\": ${PORT},\n        \"dbname\": \"${DBNAME}\",\n        \"user\": \"${USER}\",\n        \"password\": \"${PASSWORD}\"\n      }\n    }\"     \"${METABASE_URL}/database\")\n\n  if echo \"$RESPONSE\" | jq -e '.id' \u003e/dev/null; then\n    echo \"Database '$NAME' added successfully.\"\n  else\n    echo \"Failed to add database '$NAME'. Response: $RESPONSE\"\n  fi\n}\n```\n\n### 6. Run the Script\n\nAuthenticate with Metabase, and then add your databases:\n\n```bash\nauthenticate_metabase\n\nfor db in \"${DATABASES[@]}\"; do\n  IFS='|' read -r DB_NAME DB_HOST DB_PORT DB_DBNAME DB_USER DB_PASSWORD \u003c\u003c\u003c \"$db\"\n  add_database \"$DB_NAME\" \"$DB_HOST\" \"$DB_PORT\" \"$DB_DBNAME\" \"$DB_USER\" \"$DB_PASSWORD\"\ndone\n\necho \"Finished adding databases.\"\n```\n\n## 🚀 How to Use\n\n1. **Set Up a Metabase User**: Make sure you have a user account ready in your Metabase instance.\n\n2. **Customize the Script**: Edit the configuration variables to match your Metabase setup and Docker network. Populate the `DATABASES` array with your PostgreSQL databases.\n\n3. **Execute the Script**: Make the script executable and run it:\n\n    ```bash\n    chmod +x add_datasources.sh\n    ./add_datasources.sh\n    ```\n\n4. **Verify the Results**: Log into your Metabase instance and check if your databases have been successfully added.\n\n---\n\n## 📜 License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Fmetabase-postgres-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepmancer%2Fmetabase-postgres-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepmancer%2Fmetabase-postgres-docker/lists"}