├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── config ├── metabase_database.env.example └── postgres.env.example ├── docker-compose.yml └── pg ├── Dockerfile └── init ├── 00_metabase_create_user.sh └── 01_metabase_create_db.sh /.gitignore: -------------------------------------------------------------------------------- 1 | config/*.env -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/). 7 | 8 | ## [Unreleased] 9 | 10 | ## [0.0.2] - 2023-04-05 11 | 12 | ### Added 13 | 14 | ### Changed 15 | 16 | - Changed the postgres docker image to use the lighter `alpine version` 17 | - Permanently set the `MB_DB_HOST` env variable to `db` which is the host for the postgres service on the default docker-compose network formed. 18 | - Changed the names of the services and container names in the docker-compose file to more aesthetic ones. 19 | 20 | ### Fixed 21 | 22 | ## [0.0.1] - 2019-03-15 23 | 24 | ### Added 25 | 26 | - Initial set up of docker-compose file with the default postgres image and default metabase image 27 | 28 | ### Changed 29 | 30 | ### Fixed 31 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to compose-postgres-metabase 2 | 3 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 4 | 5 | - Reporting a bug 6 | - Discussing the current state of the code 7 | - Submitting a fix 8 | - Proposing new features 9 | - Becoming a maintainer 10 | 11 | ## We Develop with Github 12 | 13 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 14 | 15 | ## We Use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow), So All Code Changes Happen Through Pull Requests 16 | 17 | Pull requests are the best way to propose changes to the codebase (we 18 | use [Github Flow](https://docs.github.com/en/get-started/quickstart/github-flow)). We actively welcome your pull 19 | requests: 20 | 21 | 1. Fork the repo and create your branch from `master`. 22 | 2. If you've added code that should be tested, add tests. 23 | 3. If you've changed APIs, update the documentation. 24 | 4. Ensure the test suite passes. 25 | 5. Make sure your code lints. 26 | 6. Issue that pull request! 27 | 28 | ## Any contributions you make will be under the MIT Software Licenses 29 | 30 | In short, when you submit code changes, your submissions are understood to be under the 31 | same [MIT License](./LICENSE) that covers the project. Feel free to contact the maintainers if that's a concern. 32 | 33 | ## Report bugs using Github's [issues](https://github.com/tinitto/compose-postgres-metabase/issues) 34 | 35 | We use GitHub issues to track public bugs. Report a bug 36 | by [opening a new issue](https://github.com/tinitto/compose-postgres-metabase/issues); it's that easy! 37 | 38 | ## Write bug reports with detail, background, and sample code 39 | 40 | [This is an example](http://stackoverflow.com/q/12488905/180626). 41 | Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408). 42 | 43 | **Great Bug Reports** tend to have: 44 | 45 | - A quick summary and/or background 46 | - Steps to reproduce 47 | - Be specific! 48 | - Give sample code if you can. 49 | - What you expected would happen 50 | - What actually happens 51 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 52 | 53 | People *love* thorough bug reports. I'm not even kidding. 54 | 55 | 56 | ## License 57 | 58 | By contributing, you agree that your contributions will be licensed under its MIT License. 59 | 60 | ## References 61 | 62 | This document was adapted from [a gist by Brian A. Danielak](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62) which 63 | was originally adapted from 64 | the open-source contribution guidelines 65 | for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Martin Ahindura 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dockerized Metabase with PostgreSQL backend 2 | 3 | > Then Jesus went about all cities and villages, teaching in their synagogues, preaching the gospel of the kingdom, healing every sickness and every disease among the people. 4 | > 5 | > But when He saw the multitudes, He was moved with compassion for them, because they were weary and scattered, like sheep having no shepherd. 6 | > 7 | > -- [Matthew 9: 35-36](https://www.bible.com/en-GB/bible/114/MAT.9.NKJV) 8 | 9 | 10 | [Metabase](https://www.metabase.com/) is an open-source java-based software that enables users to analyse data from a range of data sources including relational databases (e.g. Postgresql, MySQL etc.), NoSql databases etc. 11 | 12 | It can be quite helpful when one has a data science question that could easily be answered by data analysis. 13 | 14 | By default, it stores application-specific data e.g. users, stored queries, configurations etc. on an H2 database on the same file system where it is installed. 15 | 16 | However, it is difficult to retrieve this data once the application crushes (which it might do if you write a wrong sql query for it to run on your data). It is therefore usually better to have the application save the data in a postgreSQL database such that it recovers its original state after any crush. 17 | 18 | ## Technology used 19 | 20 | | Technology | Usage | 21 | | --- | --- | 22 | |[Docker](https://docs.docker.com/) | metabase and postgres run in different Docker containers| 23 | |[Docker Compose](https://docs.docker.com/compose/) | Docker compose netwroks the different Docker containers to allow them work together as dependent services | 24 | |[Metabase](https://www.metabase.com/)| SQL based Analysis and Visualization program for any database | 25 | | [Postgres](https://www.postgresql.org/) | A database engine that stores relational data in a persistent way | 26 | 27 | ## How to run 28 | 29 | This assumes the local machine is running on Ubuntu 30 | 31 | 1. Ensure docker is installed. If it is not installed, install it. Here are [the instructions](https://docs.docker.com/install/linux/docker-ce/ubuntu/). 32 | 2. Ensure docker compose is installed on your system. If it is not installed, install it. Here are [the instructions](https://docs.docker.com/compose/install/). 33 | 3. Clone this git repository 34 | 35 | ```bash 36 | git clone https://github.com/Tinitto/compose-postgres-metabase.git 37 | ``` 38 | 39 | 4. Enter the compose-postgres-metabase folder 40 | 41 | ```bash 42 | cd compose-postgres-metabase 43 | ``` 44 | 45 | 5. Convert `config/metabase_database.env.example` to `config/metabase_database.env`. 46 | 6. Update the environment variables `MB_DB_PASS`, `MB_ENCRYPTION_SECRET_KEY` and save. 47 | 48 | ```bash 49 | MB_DB_PASS= 50 | MB_ENCRYPTION_SECRET_KEY= 51 | ``` 52 | 53 | 7. Convert `config/postgres.env.example` to `config/postgres.env`. 54 | 8. Update the environment variables `POSTGRES_PASSWORD`, `METABASE_PASSWORD` and save. 55 | 56 | ```bash 57 | POSTGRES_PASSWORD= 58 | METABASE_PASSWORD= 59 | ``` 60 | 61 | 9. Start the docker compose services 62 | 63 | ```bash 64 | sudo docker-compose up -d 65 | ``` 66 | 67 | 10. Set up your metabase instance by visiting the [local metabase start URL](http://localhost:3000) 68 | If you are on a server, use `http://:3000`. 69 | 70 | ## Service - Port Mappings 71 | 72 | | Service | Port | 73 | | -------- | ----- | 74 | | Metabase | 3000 | 75 | | Postgres | 54320 | 76 | 77 | ## Contributions 78 | 79 | Contributions are welcome. 80 | 81 | Please first take a look at the [CONTRIBUTIONS GUIDELINES](./CONTRIBUTING.md). 82 | 83 | ## License 84 | 85 | Copyright (c) 2019 [Martin Ahindura](https://github.com/Tinitto) 86 | 87 | Licensed under the [MIT License](./LICENSE) 88 | 89 | ## Acknowledgement 90 | 91 | Some of the configuration was learnt from the [Beyond Jupyter](https://github.com/jgoerner/beyond-jupyter) talk by [Joshua Gorner](https://github.com/jgoerner) 92 | 93 | Buy Me A Coffee 94 | -------------------------------------------------------------------------------- /config/metabase_database.env.example: -------------------------------------------------------------------------------- 1 | MB_DB_TYPE=postgres 2 | MB_DB_DBNAME=metabase 3 | MB_DB_PORT=5432 4 | MB_DB_USER=metabase 5 | MB_DB_PASS= 6 | MB_DB_HOST=db 7 | MB_ENCRYPTION_SECRET_KEY= 8 | -------------------------------------------------------------------------------- /config/postgres.env.example: -------------------------------------------------------------------------------- 1 | POSTGRES_PASSWORD= 2 | METABASE_PASSWORD= 3 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | 5 | db: 6 | container_name: "sopherapps.metabase.pg" 7 | restart: "always" 8 | image: alpy-pg 9 | build: ./pg 10 | env_file: 11 | - ./config/postgres.env 12 | volumes: 13 | - data:/var/lib/postgresql/data/ 14 | ports: 15 | - 54320:5432 16 | 17 | metabase: 18 | container_name: "sopherapps.metabase.metabase" 19 | restart: "always" 20 | image: metabase/metabase 21 | env_file: 22 | - ./config/metabase_database.env 23 | ports: 24 | - 3000:3000 25 | 26 | volumes: 27 | data: 28 | -------------------------------------------------------------------------------- /pg/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:14.7-alpine 2 | COPY ./init/ /docker-entrypoint-initdb.d/ 3 | RUN chown postgres:postgres /docker-entrypoint-initdb.d/* 4 | RUN chmod +x /usr/local/bin/docker-entrypoint.sh -------------------------------------------------------------------------------- /pg/init/00_metabase_create_user.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # exit if a command exits with a not-zero exit code 3 | 4 | POSTGRES="psql -U postgres" 5 | 6 | # create a shared role to read & write general datasets into postgres 7 | echo "Creating database role: metabase" 8 | $POSTGRES <<-EOSQL 9 | CREATE USER metabase WITH 10 | LOGIN 11 | NOSUPERUSER 12 | NOCREATEDB 13 | NOCREATEROLE 14 | NOINHERIT 15 | NOREPLICATION 16 | PASSWORD '$METABASE_PASSWORD'; 17 | EOSQL 18 | -------------------------------------------------------------------------------- /pg/init/01_metabase_create_db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # exit immediately if a command exits with a non-zero status. 3 | 4 | POSTGRES="psql --username postgres" 5 | 6 | # create database for superset 7 | echo "Creating database: metabase" 8 | $POSTGRES <