scaffold other code locations

This commit is contained in:
2025-07-26 22:17:22 +02:00
parent ea4bee7186
commit fd1603e309
17 changed files with 183 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ repos:
rev: 25.1.0 rev: 25.1.0
hooks: hooks:
- id: black-jupyter - id: black-jupyter
language_version: python3.11 language_version: python3.12
- repo: https://github.com/pycqa/isort - repo: https://github.com/pycqa/isort
rev: 6.0.1 rev: 6.0.1
hooks: hooks:
@@ -26,7 +26,7 @@ repos:
rev: v0.11.13 rev: v0.11.13
hooks: hooks:
- id: ruff - id: ruff
args: [ "--target-version=py311" ] args: [ "--target-version=py312" ]
- repo: https://github.com/kynan/nbstripout - repo: https://github.com/kynan/nbstripout
rev: 0.8.1 rev: 0.8.1
hooks: hooks:

View File

@@ -10,6 +10,7 @@ RUN uv pip install -r requirements.txt --system
RUN uv pip install polars-lts-cpu --system RUN uv pip install polars-lts-cpu --system
ARG APP ARG APP
ENV APP=$APP
ENV PYTHONPATH=/apps/$APP/src/:/shared/src/ ENV PYTHONPATH=/apps/$APP/src/:/shared/src/
WORKDIR /opt/dagster/home WORKDIR /opt/dagster/home

View File

View File

View File

@@ -0,0 +1,27 @@
import os
import assets
from dagster_polars import PolarsParquetIOManager
from icecream import install
import dagster as dg
from dagster import load_assets_from_modules
install()
APP = os.environ["APP"]
definitions = dg.Definitions(
assets=[
asset.with_attributes(
group_names_by_key={asset.key: APP},
tags_by_key={asset.key: {"app": APP}},
)
for asset in load_assets_from_modules([assets])
],
resources={
"polars_parquet_io_manager": PolarsParquetIOManager(
base_dir=os.environ.get("STORAGE_DIR", "/storage") + f"/{APP}"
),
},
)

View File

0
apps/tesla/src/assets.py Normal file
View File

View File

@@ -0,0 +1,27 @@
import os
import assets
from dagster_polars import PolarsParquetIOManager
from icecream import install
import dagster as dg
from dagster import load_assets_from_modules
install()
APP = os.environ["APP"]
definitions = dg.Definitions(
assets=[
asset.with_attributes(
group_names_by_key={asset.key: APP},
tags_by_key={asset.key: {"app": APP}},
)
for asset in load_assets_from_modules([assets])
],
resources={
"polars_parquet_io_manager": PolarsParquetIOManager(
base_dir=os.environ.get("STORAGE_DIR", "/storage") + f"/{APP}"
),
},
)

View File

@@ -9,18 +9,20 @@ from utils.email import EmailService
import dagster as dg import dagster as dg
APP = os.environ["APP"]
install() install()
definitions = dg.Definitions( definitions = dg.Definitions(
assets=[ assets=[
asset.with_attributes( asset.with_attributes(
group_names_by_key={asset.key: "vinyl"}, group_names_by_key={asset.key: APP},
tags_by_key={asset.key: {"app": "vinyl"}}, tags_by_key={asset.key: {"app": APP}},
) )
for asset in dg.load_assets_from_modules([assets]) for asset in dg.load_assets_from_modules([assets])
], ],
resources={ resources={
"polars_parquet_io_manager": PolarsParquetIOManager( "polars_parquet_io_manager": PolarsParquetIOManager(
base_dir=os.environ.get("STORAGE_DIR", "/storage") + "/vinyl" base_dir=os.environ.get("STORAGE_DIR", "/storage") + f"/{APP}"
), ),
"email_service": EmailService( "email_service": EmailService(
smtp_server=dg.EnvVar("SMTP_SERVER"), smtp_server=dg.EnvVar("SMTP_SERVER"),

View File

View File

View File

@@ -0,0 +1,27 @@
import os
import assets
from dagster_polars import PolarsParquetIOManager
from icecream import install
import dagster as dg
from dagster import load_assets_from_modules
install()
APP = os.environ["APP"]
definitions = dg.Definitions(
assets=[
asset.with_attributes(
group_names_by_key={asset.key: APP},
tags_by_key={asset.key: {"app": APP}},
)
for asset in load_assets_from_modules([assets])
],
resources={
"polars_parquet_io_manager": PolarsParquetIOManager(
base_dir=os.environ.get("STORAGE_DIR", "/storage") + f"/{APP}"
),
},
)

View File

@@ -19,18 +19,18 @@ services:
# run launcher to use this same image when launching runs in a new container as well. # run launcher to use this same image when launching runs in a new container as well.
# Multiple containers like this can be deployed separately - each just needs to run on # Multiple containers like this can be deployed separately - each just needs to run on
# its own port, and have its own entry in the workspace.yaml file that's loaded by dagit. # its own port, and have its own entry in the workspace.yaml file that's loaded by dagit.
user_code_vinyl: dagster-code-vinyl:
build: build:
context: apps/vinyl context: apps/vinyl
dockerfile: ../../Dockerfile.code dockerfile: ../../Dockerfile.code
args: args:
- APP=vinyl - APP=vinyl
container_name: user_code_vinyl container_name: dagster-code-vinyl
image: user_code_vinyl image: dagster-code-vinyl
restart: always restart: always
environment: environment:
<<: [ *dagster_env, *email_env ] <<: [ *dagster_env, *email_env ]
DAGSTER_CURRENT_IMAGE: user_code_vinyl DAGSTER_CURRENT_IMAGE: dagster-code-vinyl
volumes: volumes:
- /opt/dagster/apps/:/apps/:ro - /opt/dagster/apps/:/apps/:ro
- /opt/dagster/shared/:/shared/:ro - /opt/dagster/shared/:/shared/:ro
@@ -40,21 +40,78 @@ services:
networks: networks:
- dagster - dagster
user_code_other: dagster-code-stocks:
# profiles: [ disabled ] build:
context: apps/stocks
dockerfile: ../../Dockerfile.code
args:
- APP=stocks
container_name: dagster-code-stocks
image: dagster-code-stocks
restart: always
environment:
<<: [ *dagster_env ]
DAGSTER_CURRENT_IMAGE: dagster-code-stocks
volumes:
- /opt/dagster/apps/:/apps/:ro
- /opt/dagster/shared/:/shared/:ro
- /opt/dagster/logs/:/logs:rw
networks:
- dagster
dagster-code-tesla:
build:
context: apps/tesla
dockerfile: ../../Dockerfile.code
args:
- APP=tesla
container_name: dagster-code-tesla
image: dagster-code-tesla
restart: always
environment:
<<: [ *dagster_env ]
DAGSTER_CURRENT_IMAGE: dagster-code-tesla
volumes:
- /opt/dagster/apps/:/apps/:ro
- /opt/dagster/shared/:/shared/:ro
- /opt/dagster/logs/:/logs:rw
networks:
- dagster
dagster-code-weather:
build:
context: apps/weather
dockerfile: ../../Dockerfile.code
args:
- APP=weather
container_name: dagster-code-weather
image: dagster-code-weather
restart: always
environment:
<<: [ *dagster_env ]
DAGSTER_CURRENT_IMAGE: dagster-code-weather
volumes:
- /opt/dagster/apps/:/apps/:ro
- /opt/dagster/shared/:/shared/:ro
- /opt/dagster/logs/:/logs:rw
networks:
- dagster
dagster-code-other:
build: build:
context: apps/other context: apps/other
dockerfile: ../../Dockerfile.code dockerfile: ../../Dockerfile.code
args: args:
- APP=other - APP=other
container_name: user_code_other container_name: dagster-code-other
image: user_code_other image: dagster-code-other
restart: always restart: always
environment: environment:
<<: [ *dagster_env ] <<: [ *dagster_env ]
DAGSTER_CURRENT_IMAGE: user_code_other DAGSTER_CURRENT_IMAGE: dagster-code-other
volumes: volumes:
- /opt/dagster/apps/:/apps:ro - /opt/dagster/apps/:/apps/:ro
- /opt/dagster/shared/:/shared/:ro
- /opt/dagster/logs/:/logs:rw - /opt/dagster/logs/:/logs:rw
networks: networks:
- dagster - dagster

View File

@@ -23,9 +23,9 @@ x-volumes: &volumes
services: services:
# This service runs the postgres DB used by dagster for run storage, schedule storage, # This service runs the postgres DB used by dagster for run storage, schedule storage,
# and event log storage. # and event log storage.
postgresql: dagster-postgres:
image: postgres:11 image: postgres:11
container_name: postgresql container_name: dagster-postgres
environment: environment:
<<: *postgres_env <<: *postgres_env
networks: networks:
@@ -36,7 +36,7 @@ services:
# This service runs dagit, which loads your user code from the user code container. # This service runs dagit, which loads your user code from the user code container.
# Since our instance uses the QueuedRunCoordinator, any runs submitted from dagit will be put on # Since our instance uses the QueuedRunCoordinator, any runs submitted from dagit will be put on
# a queue and later dequeued and launched by dagster-daemon. # a queue and later dequeued and launched by dagster-daemon.
dagit: dagster-dagit:
build: build:
context: . context: .
dockerfile: Dockerfile.system dockerfile: Dockerfile.system
@@ -48,7 +48,7 @@ services:
- "3000" - "3000"
- -w - -w
- workspace.yaml - workspace.yaml
container_name: dagit container_name: dagster-dagit
expose: expose:
- "3000" - "3000"
ports: ports:
@@ -59,18 +59,18 @@ services:
networks: networks:
- dagster - dagster
depends_on: depends_on:
- postgresql - dagster-postgres
# This service runs the dagster-daemon process, which is responsible for taking runs # This service runs the dagster-daemon process, which is responsible for taking runs
# off of the queue and launching them, as well as creating runs from schedules or sensors. # off of the queue and launching them, as well as creating runs from schedules or sensors.
daemon: dagster-daemon:
build: build:
context: . context: .
dockerfile: Dockerfile.system dockerfile: Dockerfile.system
entrypoint: entrypoint:
- dagster-daemon - dagster-daemon
- run - run
container_name: daemon container_name: dagster-daemon
restart: on-failure restart: on-failure
environment: environment:
<<: *dagster_env <<: *dagster_env
@@ -78,4 +78,4 @@ services:
networks: networks:
- dagster - dagster
depends_on: depends_on:
- postgresql - dagster-postgres

View File

@@ -54,6 +54,11 @@ dagster = [
"dagit" "dagit"
] ]
vinyl = [] vinyl = []
stocks = [
"selenium"
]
tesla = []
weather = []
other = [] other = []
unknown = [ unknown = [
"fastapi", "fastapi",

View File

@@ -2,4 +2,7 @@ uv pip compile pyproject.toml > requirements.txt
uv pip compile pyproject.toml --extra=dagster > dagster-requirements.txt uv pip compile pyproject.toml --extra=dagster > dagster-requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=dev > dev-requirements.txt uv pip compile pyproject.toml --extra=dagster --extra=dev > dev-requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=vinyl > apps/vinyl/requirements.txt uv pip compile pyproject.toml --extra=dagster --extra=vinyl > apps/vinyl/requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=stocks > apps/stocks/requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=tesla > apps/tesla/requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=weather > apps/weather/requirements.txt
uv pip compile pyproject.toml --extra=dagster --extra=other > apps/other/requirements.txt uv pip compile pyproject.toml --extra=dagster --extra=other > apps/other/requirements.txt

View File

@@ -1,7 +1,16 @@
load_from: load_from:
- grpc_server: - grpc_server:
host: user_code_vinyl host: dagster-code-vinyl
port: 4000 port: 4000
- grpc_server: - grpc_server:
host: user_code_other host: dagster-code-stocks
port: 4000
- grpc_server:
host: dagster-code-tesla
port: 4000
- grpc_server:
host: dagster-code-weather
port: 4000
- grpc_server:
host: dagster-code-other
port: 4000 port: 4000