From 1a44a0ea5a73ec0eaed6d13712ef4cffa4df8ca2 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Tue, 21 Jan 2025 23:14:28 +1100 Subject: [PATCH] refactor(template): use dokploy mount volume for superset_config.py --- .../templates/superset/docker-compose.yml | 31 ++----------------- apps/dokploy/templates/superset/index.ts | 29 +++++++++++++++++ 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/apps/dokploy/templates/superset/docker-compose.yml b/apps/dokploy/templates/superset/docker-compose.yml index c95dec6e..e0f17913 100644 --- a/apps/dokploy/templates/superset/docker-compose.yml +++ b/apps/dokploy/templates/superset/docker-compose.yml @@ -1,32 +1,6 @@ # Note: this is an UNOFFICIAL production docker image build for Superset: # - https://github.com/amancevice/docker-superset # -# Before deploying, you must mount your `superset_config.py` file to -# the superset container. An example config is: -# -# ```python -# import os -# -# SECRET_KEY = os.getenv("SECRET_KEY") -# MAPBOX_API_KEY = os.getenv("MAPBOX_API_KEY", "") -# -# CACHE_CONFIG = { -# "CACHE_TYPE": "RedisCache", -# "CACHE_DEFAULT_TIMEOUT": 300, -# "CACHE_KEY_PREFIX": "superset_", -# "CACHE_REDIS_HOST": "redis", -# "CACHE_REDIS_PORT": 6379, -# "CACHE_REDIS_DB": 1, -# "CACHE_REDIS_URL": f"redis://:{os.getenv('REDIS_PASSWORD')}@redis:6379/1", -# } -# -# FILTER_STATE_CACHE_CONFIG = {**CACHE_CONFIG, "CACHE_KEY_PREFIX": "superset_filter_"} -# EXPLORE_FORM_DATA_CACHE_CONFIG = {**CACHE_CONFIG, "CACHE_KEY_PREFIX": "superset_explore_form_"} -# -# SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{os.getenv('POSTGRES_USER')}:{os.getenv('POSTGRES_PASSWORD')}@db:5432/{os.getenv('POSTGRES_DB')}" -# SQLALCHEMY_TRACK_MODIFICATIONS = True -# ``` -# # After deploying this image, you will need to run one of the two # commands below in a terminal within the superset container: # $ superset-demo # Initialise database + load demo charts/datasets @@ -49,9 +23,8 @@ services: POSTGRES_DB: ${POSTGRES_DB} REDIS_PASSWORD: ${REDIS_PASSWORD} volumes: - # NOTE: ensure `/opt/superset/superset_config.py` exists on your - # host machine (or change the path as appropriate) - - /opt/superset/superset_config.py:/etc/superset/superset_config.py + # Note: superset_config.py can be edited in Dokploy's UI Volume Mount + - ../files/superset/superset_config.py:/etc/superset/superset_config.py db: image: postgres diff --git a/apps/dokploy/templates/superset/index.ts b/apps/dokploy/templates/superset/index.ts index 84e6dd0c..6132f978 100644 --- a/apps/dokploy/templates/superset/index.ts +++ b/apps/dokploy/templates/superset/index.ts @@ -31,8 +31,37 @@ export function generate(schema: Schema): Template { `REDIS_PASSWORD=${redisPassword}`, ]; + const mounts: Template["mounts"] = [ + { + filePath: "./superset/superset_config.py", + content: ` +import os + +SECRET_KEY = os.getenv("SECRET_KEY") +MAPBOX_API_KEY = os.getenv("MAPBOX_API_KEY", "") + +CACHE_CONFIG = { + "CACHE_TYPE": "RedisCache", + "CACHE_DEFAULT_TIMEOUT": 300, + "CACHE_KEY_PREFIX": "superset_", + "CACHE_REDIS_HOST": "redis", + "CACHE_REDIS_PORT": 6379, + "CACHE_REDIS_DB": 1, + "CACHE_REDIS_URL": f"redis://:{os.getenv('REDIS_PASSWORD')}@redis:6379/1", +} + +FILTER_STATE_CACHE_CONFIG = {**CACHE_CONFIG, "CACHE_KEY_PREFIX": "superset_filter_"} +EXPLORE_FORM_DATA_CACHE_CONFIG = {**CACHE_CONFIG, "CACHE_KEY_PREFIX": "superset_explore_form_"} + +SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{os.getenv('POSTGRES_USER')}:{os.getenv('POSTGRES_PASSWORD')}@db:5432/{os.getenv('POSTGRES_DB')}" +SQLALCHEMY_TRACK_MODIFICATIONS = True + `.trim(), + }, + ]; + return { envs, domains, + mounts, }; }