mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
Docker support
This commit is contained in:
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
rd_ui/dist/
|
||||
rd_ui/.tmp/
|
||||
.git/
|
||||
.vagrant/
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -19,3 +19,6 @@ redash/dump.rdb
|
||||
venv
|
||||
|
||||
dump.rdb
|
||||
|
||||
# Docker related
|
||||
docker-compose.yaml
|
||||
|
||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM debian:wheezy
|
||||
MAINTAINER Di Wu <diwu@yelp.com>
|
||||
|
||||
COPY . /opt/redash/current/
|
||||
|
||||
# Install dependencies
|
||||
WORKDIR /opt/redash/current
|
||||
RUN bash setup/bootstrap_docker.sh
|
||||
|
||||
# Build frontend sources
|
||||
WORKDIR /opt/redash/current/rd_ui
|
||||
USER redash
|
||||
RUN mkdir -p /opt/redash/.npm/node_modules
|
||||
RUN npm config set prefix /opt/redash/.npm/node_modules
|
||||
RUN npm install -g bower
|
||||
RUN npm install -g grunt-cli
|
||||
RUN npm install
|
||||
RUN /opt/redash/.npm/node_modules/bin/bower install
|
||||
RUN /opt/redash/.npm/node_modules/bin/grunt build
|
||||
|
||||
# Reset working directory and user for future `docker attach` sessions
|
||||
WORKDIR /opt/redash/current
|
||||
USER root
|
||||
17
docker-compose-example.yaml
Normal file
17
docker-compose-example.yaml
Normal file
@@ -0,0 +1,17 @@
|
||||
redash:
|
||||
build: .
|
||||
ports:
|
||||
- "5000:5000"
|
||||
- "9001:9001"
|
||||
links:
|
||||
- redis
|
||||
- postgres
|
||||
stdin_open: true
|
||||
redis:
|
||||
image: redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
postgres:
|
||||
image: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
85
setup/bootstrap_docker.sh
Normal file
85
setup/bootstrap_docker.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
FILES_BASE_URL=/opt/redash/current/setup/files/
|
||||
|
||||
# Base packages
|
||||
apt-get dist-upgrade
|
||||
apt-get update
|
||||
apt-get install -y python-pip python-dev curl build-essential pwgen libffi-dev sudo git-core
|
||||
pip install -U setuptools
|
||||
|
||||
# redash user
|
||||
useradd --system --comment " " --create-home redash
|
||||
|
||||
# PostgreSQL
|
||||
apt-get update
|
||||
apt-get -y install libpq-dev postgresql
|
||||
|
||||
# Redis client
|
||||
mkdir -p /tmp/redash && cd $_
|
||||
curl -L https://github.com/antirez/redis/archive/3.0.4.tar.gz -o redis.tar.gz
|
||||
mkdir redis
|
||||
tar -zxvf redis.tar.gz -C redis --strip-components 1
|
||||
cd redis
|
||||
make redis-cli
|
||||
cp src/redis-cli /usr/local/bin
|
||||
rm -rf /tmp/redis
|
||||
|
||||
add_service() {
|
||||
service_name=$1
|
||||
service_command="/etc/init.d/$service_name"
|
||||
|
||||
echo "Adding service: $service_name (/etc/init.d/$service_name)."
|
||||
chmod +x $service_command
|
||||
|
||||
if command -v chkconfig >/dev/null 2>&1; then
|
||||
# we're chkconfig, so lets add to chkconfig and put in runlevel 345
|
||||
chkconfig --add $service_name && echo "Successfully added to chkconfig!"
|
||||
chkconfig --level 345 $service_name on && echo "Successfully added to runlevels 345!"
|
||||
elif command -v update-rc.d >/dev/null 2>&1; then
|
||||
#if we're not a chkconfig box assume we're able to use update-rc.d
|
||||
update-rc.d $service_name defaults && echo "Success!"
|
||||
else
|
||||
echo "No supported init tool found."
|
||||
fi
|
||||
|
||||
$service_command start
|
||||
}
|
||||
|
||||
|
||||
mkdir /opt/redash/logs
|
||||
|
||||
# Default config file
|
||||
cp $FILES_BASE_URL"env" /opt/redash/.env
|
||||
|
||||
# Install dependencies
|
||||
cd /opt/redash/current
|
||||
pip install -r requirements.txt
|
||||
|
||||
# BigQuery dependencies:
|
||||
apt-get install -y libssl-dev
|
||||
|
||||
# MySQL dependencies:
|
||||
apt-get install -y libmysqlclient-dev
|
||||
|
||||
# Pip requirements for all data source types
|
||||
cd /opt/redash/current
|
||||
pip install -r requirements_all_ds.txt
|
||||
|
||||
# Setup supervisord + sysv init startup script
|
||||
mkdir -p /opt/redash/supervisord
|
||||
pip install supervisor==3.1.2 # TODO: move to requirements.txt
|
||||
|
||||
# Get supervisord startup script
|
||||
cp $FILES_BASE_URL"supervisord.conf" /opt/redash/supervisord/supervisord.conf
|
||||
|
||||
cp $FILES_BASE_URL"redash_supervisord_init" /etc/init.d/redash_supervisord
|
||||
add_service "redash_supervisord"
|
||||
|
||||
# Fix permissions
|
||||
chown -R redash /opt/redash
|
||||
|
||||
# Install Node.js
|
||||
curl --silent --location https://deb.nodesource.com/setup_0.12 | bash -
|
||||
apt-get install -y nodejs
|
||||
15
setup/docker_init_migration.sh
Normal file
15
setup/docker_init_migration.sh
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0001_allow_delete_query.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0002_fix_timestamp_fields.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0003_update_data_source_config.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0004_allow_null_in_event_user.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0005_add_updated_at.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0006_queries_last_edit_by.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0007_add_schedule_to_queries.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0008_make_ds_name_unique.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0009_add_api_key_to_user.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0010_create_alerts.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0010_allow_deleting_datasources.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0011_migrate_bigquery_to_json.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0012_add_list_users_permission.py
|
||||
sudo -u postgres PYTHONPATH=. bin/run python migrations/0013_update_counter_options.py
|
||||
33
setup/docker_init_postgres.sh
Normal file
33
setup/docker_init_postgres.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# Create database / tables
|
||||
pg_user_exists=0
|
||||
sudo -u postgres psql --host=postgres postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='redash'" | grep -q 1 || pg_user_exists=$?
|
||||
if [ $pg_user_exists -ne 0 ]; then
|
||||
echo "Creating redash postgres user & database."
|
||||
sudo -u postgres createuser redash --host=postgres --no-superuser --no-createdb --no-createrole
|
||||
sudo -u postgres createdb redash --host=postgres --owner=redash
|
||||
|
||||
cd /opt/redash/current
|
||||
sudo -u redash bin/run ./manage.py database create_tables
|
||||
fi
|
||||
|
||||
# Create default admin user
|
||||
cd /opt/redash/current
|
||||
# TODO: make sure user created only once
|
||||
# TODO: generate temp password and print to screen
|
||||
sudo -u redash bin/run ./manage.py users create --admin --password admin "Admin" "admin"
|
||||
|
||||
# Create re:dash read only pg user & setup data source
|
||||
pg_user_exists=0
|
||||
sudo -u postgres psql --host=postgres postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='redash_reader'" | grep -q 1 || pg_user_exists=$?
|
||||
if [ $pg_user_exists -ne 0 ]; then
|
||||
echo "Creating redash reader postgres user."
|
||||
REDASH_READER_PASSWORD=$(pwgen -1)
|
||||
sudo -u postgres psql --host=postgres -c "CREATE ROLE redash_reader WITH PASSWORD '$REDASH_READER_PASSWORD' NOCREATEROLE NOCREATEDB NOSUPERUSER LOGIN"
|
||||
sudo -u redash psql --host=postgres -c "grant select(id,name,type) ON data_sources to redash_reader;" redash
|
||||
sudo -u redash psql --host=postgres -c "grant select(id,name) ON users to redash_reader;" redash
|
||||
sudo -u redash psql --host=postgres -c "grant select on activity_log, events, queries, dashboards, widgets, visualizations, query_results to redash_reader;" redash
|
||||
|
||||
cd /opt/redash/current
|
||||
sudo -u redash bin/run ./manage.py ds new -n "re:dash metadata" -t "pg" -o "{\"user\": \"redash_reader\", \"password\": \"$REDASH_READER_PASSWORD\", \"host\": \"localhost\", \"dbname\": \"redash\"}"
|
||||
fi
|
||||
Reference in New Issue
Block a user