From 05a75edbecf92dd5209f698724a46ed184c88d2b Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Tue, 21 Jan 2025 19:03:35 +1100 Subject: [PATCH 1/5] feat(template): added apache superset (unofficial) --- apps/dokploy/public/templates/superset.svg | 9 +++ .../templates/superset/docker-compose.yml | 79 +++++++++++++++++++ apps/dokploy/templates/superset/index.ts | 38 +++++++++ apps/dokploy/templates/templates.ts | 14 ++++ 4 files changed, 140 insertions(+) create mode 100644 apps/dokploy/public/templates/superset.svg create mode 100644 apps/dokploy/templates/superset/docker-compose.yml create mode 100644 apps/dokploy/templates/superset/index.ts diff --git a/apps/dokploy/public/templates/superset.svg b/apps/dokploy/public/templates/superset.svg new file mode 100644 index 00000000..522c3b28 --- /dev/null +++ b/apps/dokploy/public/templates/superset.svg @@ -0,0 +1,9 @@ + + + Superset + + + + + + diff --git a/apps/dokploy/templates/superset/docker-compose.yml b/apps/dokploy/templates/superset/docker-compose.yml new file mode 100644 index 00000000..c95dec6e --- /dev/null +++ b/apps/dokploy/templates/superset/docker-compose.yml @@ -0,0 +1,79 @@ +# 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 +# $ superset-init # Initialise database only +# +# You will be prompted to enter the credentials for the admin user. + +services: + superset: + image: amancevice/superset + restart: always + depends_on: + - db + - redis + environment: + SECRET_KEY: ${SECRET_KEY} + MAPBOX_API_KEY: ${MAPBOX_API_KEY} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + 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 + + db: + image: postgres + restart: always + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_DB: ${POSTGRES_DB} + volumes: + - postgres:/var/lib/postgresql/data + networks: + - dokploy-network + + redis: + image: redis + restart: always + volumes: + - redis:/data + command: redis-server --requirepass ${REDIS_PASSWORD} + networks: + - dokploy-network + +volumes: + postgres: + redis: diff --git a/apps/dokploy/templates/superset/index.ts b/apps/dokploy/templates/superset/index.ts new file mode 100644 index 00000000..84e6dd0c --- /dev/null +++ b/apps/dokploy/templates/superset/index.ts @@ -0,0 +1,38 @@ +import { + type DomainSchema, + type Schema, + type Template, + generatePassword, + generateRandomDomain, +} from "../utils"; + +export function generate(schema: Schema): Template { + const mapboxApiKey = ""; + const secretKey = generatePassword(30); + const postgresDb = "superset"; + const postgresUser = "superset"; + const postgresPassword = generatePassword(30); + const redisPassword = generatePassword(30); + + const domains: DomainSchema[] = [ + { + host: generateRandomDomain(schema), + port: 8088, + serviceName: "superset", + }, + ]; + + const envs = [ + `SECRET_KEY=${secretKey}`, + `MAPBOX_API_KEY=${mapboxApiKey}`, + `POSTGRES_DB=${postgresDb}`, + `POSTGRES_USER=${postgresUser}`, + `POSTGRES_PASSWORD=${postgresPassword}`, + `REDIS_PASSWORD=${redisPassword}`, + ]; + + return { + envs, + domains, + }; +} diff --git a/apps/dokploy/templates/templates.ts b/apps/dokploy/templates/templates.ts index 9531eb7a..a885f906 100644 --- a/apps/dokploy/templates/templates.ts +++ b/apps/dokploy/templates/templates.ts @@ -1298,4 +1298,18 @@ export const templates: TemplateData[] = [ tags: ["developer", "tools"], load: () => import("./it-tools/index").then((m) => m.generate), }, + { + id: "superset", + name: "Superset (Unofficial)", + version: "latest", + description: "Data visualization and data exploration platform.", + logo: "superset.svg", + links: { + github: "https://github.com/amancevice/docker-superset", + website: "https://superset.apache.org", + docs: "https://superset.apache.org/docs/intro", + }, + tags: ["developer", "tools"], + load: () => import("./superset/index").then((m) => m.generate), + }, ]; From 444121f8d8b2798ec4d199ddb504042de0ce3aa8 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Tue, 21 Jan 2025 20:40:46 +1100 Subject: [PATCH 2/5] fix(template): more appropriate tags for superset --- apps/dokploy/templates/templates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dokploy/templates/templates.ts b/apps/dokploy/templates/templates.ts index a885f906..9ea88a8d 100644 --- a/apps/dokploy/templates/templates.ts +++ b/apps/dokploy/templates/templates.ts @@ -1309,7 +1309,7 @@ export const templates: TemplateData[] = [ website: "https://superset.apache.org", docs: "https://superset.apache.org/docs/intro", }, - tags: ["developer", "tools"], + tags: ["bi", "dashboard", "database", "sql"], load: () => import("./superset/index").then((m) => m.generate), }, ]; From 1a44a0ea5a73ec0eaed6d13712ef4cffa4df8ca2 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Tue, 21 Jan 2025 23:14:28 +1100 Subject: [PATCH 3/5] 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, }; } From 1d86f1a0fcc212fe8fb1b77bc364f5ef2b9b0075 Mon Sep 17 00:00:00 2001 From: Khiet Tam Nguyen Date: Wed, 22 Jan 2025 00:05:55 +1100 Subject: [PATCH 4/5] fix(template): added analytics tag to superset --- apps/dokploy/templates/templates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dokploy/templates/templates.ts b/apps/dokploy/templates/templates.ts index 9ea88a8d..4cd167a5 100644 --- a/apps/dokploy/templates/templates.ts +++ b/apps/dokploy/templates/templates.ts @@ -1309,7 +1309,7 @@ export const templates: TemplateData[] = [ website: "https://superset.apache.org", docs: "https://superset.apache.org/docs/intro", }, - tags: ["bi", "dashboard", "database", "sql"], + tags: ["analytics", "bi", "dashboard", "database", "sql"], load: () => import("./superset/index").then((m) => m.generate), }, ]; From 52dbc0d8f1a8a4ab69b86e868308d7a1ddf0d78b Mon Sep 17 00:00:00 2001 From: Tam Nguyen Date: Wed, 22 Jan 2025 09:14:21 +1100 Subject: [PATCH 5/5] fix(template): superset healthchecks --- apps/dokploy/templates/superset/docker-compose.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/dokploy/templates/superset/docker-compose.yml b/apps/dokploy/templates/superset/docker-compose.yml index e0f17913..1766b86b 100644 --- a/apps/dokploy/templates/superset/docker-compose.yml +++ b/apps/dokploy/templates/superset/docker-compose.yml @@ -35,6 +35,11 @@ services: POSTGRES_DB: ${POSTGRES_DB} volumes: - postgres:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 30s + timeout: 10s + retries: 3 networks: - dokploy-network @@ -44,6 +49,11 @@ services: volumes: - redis:/data command: redis-server --requirepass ${REDIS_PASSWORD} + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 30s + timeout: 10s + retries: 3 networks: - dokploy-network