Skip to content

Instantly share code, notes, and snippets.

@linhmtran168
Last active March 28, 2024 09:33
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save linhmtran168/ec0757a487a83a1fc5c5d3188af81874 to your computer and use it in GitHub Desktop.
Save linhmtran168/ec0757a487a83a1fc5c5d3188af81874 to your computer and use it in GitHub Desktop.
Setup Redash for Oracle

Usage

Refs

https://redash.io/

Download Redash

$ curl -L -O https://github.com/getredash/redash/archive/v5.0.1.zip
$ unzip v5.0.1.zip && cd ./path-to-redash

Download Oracle instant client

http://www.oracle.com/technetwork/database/features/instant-client/index.html

$ mkdir oracle
$ mv /path-to/instantclient-*.zip oracle/

Run necessary setup

# Copy setup.sh to /path-to-redash/setup before deploying
$ chmod a+x setup.sh
$ ./setup.sh

Build docker image

  • Overwrite /path-to-redash/requirements_oracle_ds.txt with the following content
cx_Oracle==7.0.0
  • Copy custom Dockerfile to /path-to-redash then build the image
$ docker build -t custom/redash .

Deploy container

# Copy docker-compose.yml to /opt/redash before deploying
$ cd /opt/redash
$ docker-compose run --rm server create_db
$ docker-compose up -d
$ docker-compose logs -f
version: '2'
x-redash-service: &redash-service
image: custom/redash:latest
depends_on:
- postgres
- redis
env_file: /opt/redash/env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "5000:5000"
environment:
REDASH_WEB_WORKERS: 4
scheduler:
<<: *redash-service
command: scheduler
environment:
QUEUES: "celery"
WORKERS_COUNT: 1
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries"
WORKERS_COUNT: 1
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:3.0-alpine
restart: always
postgres:
image: postgres:9.5.6-alpine
env_file: /opt/redash/env
volumes:
- /opt/redash/postgres-data:/var/lib/postgresql/data
restart: always
nginx:
image: redash/nginx:latest
ports:
- "80:80"
depends_on:
- server
links:
- server:redash
restart: always
FROM redash/base:latest
RUN apt-get update -y
RUN apt-get install -y unzip
RUN apt-get install -y libaio-dev # depends on Oracle
RUN apt-get clean -y
# -- Start setup Oracle
# Add instantclient
ADD oracle/instantclient-basic-linux.x64-18.3.0.0.0dbru.zip /tmp/instantclient-basic-linux.x64-18.3.0.0.0dbru.zip
ADD oracle/instantclient-sdk-linux.x64-18.3.0.0.0dbru.zip /tmp/instantclient-sdk-linux.x64-18.3.0.0.0dbru.zip
ADD oracle/instantclient-sqlplus-linux.x64-18.3.0.0.0dbru.zip /tmp/instantclient-sqlplus-linux.x64-18.3.0.0.0dbru.zip
ADD oracle/instantclient-odbc-linux.x64-18.3.0.0.0dbru.zip /tmp/instantclient-odbc-linux.x64-18.3.0.0.0dbru.zip
ADD oracle/instantclient-jdbc-linux.x64-18.3.0.0.0dbru.zip /tmp/instantclient-jdbc-linux.x64-18.3.0.0.0dbru.zip
RUN mkdir -p /opt/oracle/
RUN unzip /tmp/instantclient-basic-linux.x64-18.3.0.0.0dbru.zip -d /opt/oracle/
RUN unzip /tmp/instantclient-sdk-linux.x64-18.3.0.0.0dbru.zip -d /opt/oracle/
RUN unzip /tmp/instantclient-sqlplus-linux.x64-18.3.0.0.0dbru.zip -d /opt/oracle/
RUN unzip /tmp/instantclient-odbc-linux.x64-18.3.0.0.0dbru.zip -d /opt/oracle/
RUN unzip /tmp/instantclient-jdbc-linux.x64-18.3.0.0.0dbru.zip -d /opt/oracle/
ENV ORACLE_HOME=/opt/oracle/instantclient_18_3
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_18_3:$LD_LIBRARY_PATH
ENV PATH=/opt/oracle/instantclient_18_3:$PATH
# Add REDASH ENV to add Oracle Query Runner
ENV REDASH_ADDITIONAL_QUERY_RUNNERS=redash.query_runner.oracle
# -- End setup Oracle
# We first copy only the requirements file, to avoid rebuilding on every file
# change.
COPY requirements.txt requirements_dev.txt requirements_all_ds.txt requirements_oracle_ds.txt ./
RUN pip install -r requirements.txt -r requirements_dev.txt -r requirements_all_ds.txt -r requirements_oracle_ds.txt
COPY . ./
RUN npm install && npm run build && rm -rf node_modules
RUN chown -R redash /app
USER redash
ENTRYPOINT ["/app/bin/docker-entrypoint"]
CMD ["server"]
#!/usr/bin/env bash
# This script setups dockerized Redash on Ubuntu 18.04.
set -eu
REDASH_BASE_PATH=/opt/redash
install_docker(){
# Install Docker
sudo apt-get update
sudo apt-get -yy install apt-transport-https ca-certificates curl software-properties-common wget pwgen
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update && sudo apt-get -y install docker-ce
# Install Docker Compose
sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Allow current user to run Docker commands
sudo usermod -aG docker $USER
}
create_directories() {
if [[ ! -e $REDASH_BASE_PATH ]]; then
sudo mkdir -p $REDASH_BASE_PATH
sudo chown $USER:$USER $REDASH_BASE_PATH
fi
if [[ ! -e $REDASH_BASE_PATH/postgres-data ]]; then
mkdir $REDASH_BASE_PATH/postgres-data
fi
}
create_config() {
if [[ -e $REDASH_BASE_PATH/env ]]; then
now=$(date +%s)
mv $REDASH_BASE_PATH/env $REDASH_BASE_PATH/env.$now.bk
touch $REDASH_BASE_PATH/env
fi
COOKIE_SECRET=$(pwgen -1s 32)
POSTGRES_PASSWORD=$(pwgen -1s 32)
REDASH_DATABASE_URL="postgresql://postgres:${POSTGRES_PASSWORD}@postgres/postgres"
NLS_LANG=JAPANESE_JAPAN.JA16EUC
echo "PYTHONUNBUFFERED=0" >> $REDASH_BASE_PATH/env
echo "REDASH_LOG_LEVEL=INFO" >> $REDASH_BASE_PATH/env
echo "REDASH_REDIS_URL=redis://redis:6379/0" >> $REDASH_BASE_PATH/env
echo "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" >> $REDASH_BASE_PATH/env
echo "REDASH_COOKIE_SECRET=$COOKIE_SECRET" >> $REDASH_BASE_PATH/env
echo "REDASH_DATABASE_URL=$REDASH_DATABASE_URL" >> $REDASH_BASE_PATH/env
echo "NLS_LANG=$NLS_LANG" >> $REDASH_BASE_PATH/env
}
install_docker
create_directories
create_config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment