Skip to content

Commit

Permalink
Create automatic importer and persist data
Browse files Browse the repository at this point in the history
  • Loading branch information
rhefner1 committed May 4, 2017
1 parent dcf34fe commit a50fdce
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# docker-metabase w/MongoDB backend
To get started, do the following:
- Start metabase`docker-compose up`
- In another terminal, start another Mongo container: `docker run -it mongo:3.2 bash`
- In another terminal, find the container ID of the container just started: `docker ps`
- Copy file into container: `docker cp ./file.csv CONTAINER_ID:/`
- Connect container to Mongo network: `docker network connect metabase_stack CONTAINER_ID`
- Inspect network and get IP of Mongo container: `docker network Inspect metabase_stack`
- Run the import tool, replacing IP and filename: `mongoimport --host=172.19.0.2 -d groupme -c groupme --type csv --file ./file.csv --headerline`
- Open http://localhost:3000 to get to the Metabase setup wizard. When setting up the database, use the IP address from the previous step. No authentication is set up.
- Drag CSV files to import into MongoDB into `importer/files_to_import/`. If you have different kinds of files, you may need to make modifications to the import script.
- Look at the environment variables for the importer in `docker-compose.yml`. Change the database and collection names if desired.
- For the first run only, change IMPORT_RUN to "true". Then change it back to "false" so you don't have new documents being imported every time you restart the containers.
- Start metabase: `docker-compose up`
- Open http://localhost:3000 to get to the Metabase setup wizard. When setting up the database, use "mongodb" as the IP address for MongoDB and the data from the environment variables. No authentication is set up.
-
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ services:
build: mongodb/
ports:
- "27017:27017"
volumes:
- ./data/mongodb:/data/db
networks:
- stack

metabase:
build: metabase/
ports:
- "3000:3000"
environment:
- MB_DB_FILE=/metabase-data/metabase.db
volumes:
- ./data/metabase:/metabase-data
networks:
- stack
depends_on:
- mongodb

importer:
build: importer/
environment:
- IMPORT_RUN=false
- MONGO_DATABASE=db
- MONGO_COLLECTION=collection
networks:
- stack
depends_on:
Expand Down
11 changes: 11 additions & 0 deletions importer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mongo:3.2

# Create data directory and switch to it
RUN mkdir /import-data
WORKDIR /import-data

# Copy files to import into the container
COPY ./import.sh /import-data
COPY files_to_import /import-data

CMD ["/bin/bash", "./import.sh"]
Empty file.
8 changes: 8 additions & 0 deletions importer/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if [ "$IMPORT_RUN" = true ] ; then
for filename in *.csv;
do
mongoimport --host=mongodb -d $MONGO_DATABASE -c $MONGO_COLLECTION --type csv --file $filename --headerline;
done
fi

0 comments on commit a50fdce

Please sign in to comment.