Skip to content

Commit f8e0814

Browse files
committed
Start to implement k8s deployment
1 parent d34c0ee commit f8e0814

37 files changed

+6114
-181
lines changed

.env

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
COMPOSE_PATH_SEPARATOR=:
2-
COMPOSE_FILE=docker-compose.yml:clickhouse/compose.clickhouse.yml:metastore/compose.metastore.yml
3-
4-
. ./.secrets
2+
COMPOSE_FILE=docker-compose.yml:clickhouse/compose.clickhouse.yml:nessie/compose.nessie.yml:openmetadata/compose.openmetadata.yml:dagster/compose.dagster.yml:spark/compose.spark.yml:pipelines/compose.pipelines.yml:kafka/compose.kafka.yml
3+
#:cube/compose.cube.yml:prometheus/compose.prometheus.yml

.envrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
. ./.env
1+
use flake

.gitignore

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
.ipynb_checkpoints
2-
.secrets
1+
.ipynb_checkpoints/
2+
__pycache__/
3+
.logs_queue/
4+
.nux/
5+
.telemetry/
6+
pipelines/storage/
7+
pipelines/schedules/
8+
pipelines/history/
9+
metastore_db/
10+
env/
11+
!doc/env/
12+
*.log
13+
.venv/
14+
.direnv/

.secrets.template

-20
This file was deleted.

clickhouse/compose.clickhouse.yml

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ services:
3232
retries: 10
3333
restart:
3434
always
35+
env_file:
36+
- env/minio.env
3537

3638
clickhouse-02:
3739
image: "clickhouse/clickhouse-server:24"
@@ -66,6 +68,8 @@ services:
6668
retries: 10
6769
restart:
6870
always
71+
env_file:
72+
- env/minio.env
6973

7074
clickhouse-03:
7175
image: "clickhouse/clickhouse-server:24"
@@ -100,6 +104,8 @@ services:
100104
retries: 10
101105
restart:
102106
always
107+
env_file:
108+
- env/minio.env
103109

104110
clickhouse-04:
105111
image: "clickhouse/clickhouse-server:24"
@@ -134,6 +140,8 @@ services:
134140
retries: 10
135141
restart:
136142
always
143+
env_file:
144+
- env/minio.env
137145

138146
clickhouse-keeper-01:
139147
image: "clickhouse/clickhouse-keeper:24"

dagster/compose.dagster.yml

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
services:
22
dagster_postgresql:
33
image: postgres:16
4-
container_name: dagster-postgresql
5-
environment:
6-
DAGSTER_POSTGRES_USER: ${DAGSTER_DATABASE_USERNAME}
7-
DAGSTER_POSTGRES_PASSWORD: ${DAGSTER_DATABASE_PASSWORD}
8-
DAGSTER_POSTGRES_DB: ${DAGSTER_DATABASE}
4+
container_name: dagster_postgresql
5+
hostname: dagster_postgresql
96
networks:
107
- dagster-internal
8+
- public
9+
env_file:
10+
- env/dagster.env
11+
- env/pipeline.env
1112

1213
dagster_webserver:
1314
build: dagster/dagster
1415
container_name: dagster_webserver
16+
hostname: dagster_webserver
1517
restart: on-failure
1618
entrypoint:
1719
- dagster-webserver
@@ -25,37 +27,39 @@ services:
2527
- "3070"
2628
ports:
2729
- "3070:3070"
28-
environment:
29-
DAGSTER_POSTGRES_USER: ${DAGSTER_DATABASE_USERNAME}
30-
DAGSTER_POSTGRES_PASSWORD: ${DAGSTER_DATABASE_PASSWORD}
31-
DAGSTER_POSTGRES_DB: ${DAGSTER_DATABASE}
3230
volumes:
31+
- /var/run/docker.sock:/var/run/docker.sock
3332
- /tmp/io_manager_storage:/tmp/io_manager_storage
3433
- ./pipelines/home:/opt/dagster/dagster_home/
3534
networks:
3635
- dagster-internal
3736
- public
3837
depends_on:
3938
- dagster_postgresql
39+
env_file:
40+
- env/dagster.env
41+
- env/pipeline.env
4042

4143
dagster_daemon:
4244
build: dagster/dagster
4345
entrypoint:
4446
- dagster-daemon
4547
- run
46-
container_name: dagster-daemon
48+
container_name: dagster_daemon
49+
hostname: dagster_daemon
4750
restart: on-failure
48-
environment:
49-
DAGSTER_POSTGRES_USER: ${DAGSTER_DATABASE_USERNAME}
50-
DAGSTER_POSTGRES_PASSWORD: ${DAGSTER_DATABASE_PASSWORD}
51-
DAGSTER_POSTGRES_DB: ${DAGSTER_DATABASE}
5251
volumes:
52+
- /var/run/docker.sock:/var/run/docker.sock
5353
- /tmp/io_manager_storage:/tmp/io_manager_storage
5454
- ./pipelines/home:/opt/dagster/dagster_home/
5555
networks:
5656
- dagster-internal
57+
- public
5758
depends_on:
5859
- dagster_postgresql
60+
env_file:
61+
- env/dagster.env
62+
- env/pipeline.env
5963

6064
networks:
6165
dagster-internal:

dagster/dagster/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ RUN pip install \
1212

1313
RUN apt update && apt upgrade -y && apt install default-jdk -y
1414

15+
# Set $DAGSTER_HOME and copy dagster instance and workspace YAML there
1516
ENV PYSPARK_SUBMIT_ARGS="--master spark://spark:7077"
1617
ENV JAVA_HOME=/usr/lib/jvm/default-java/
1718
ENV DAGSTER_DIR=/var/lib/fxttr/dagster
1819
ENV DAGSTER_HOME=/opt/dagster/dagster_home/
1920

2021
RUN mkdir -p ${DAGSTER_HOME} ${DAGSTER_DIR}
2122

22-
COPY conf/dagster.yaml ${DAGSTER_HOME}/dagster.yaml
23-
2423
WORKDIR $DAGSTER_HOME

dagster/dagster/conf/dagster.yaml

-71
This file was deleted.

docker-compose.yml

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
build: playground/
44
container_name: playground
55
volumes:
6+
- ./data/stage:/var/lib/fxttr/stage
67
- ./data/playground/notebooks:/var/lib/fxttr/notebooks
78
ports:
89
- '8888:8888'
@@ -17,6 +18,7 @@ services:
1718
build: trino/
1819
container_name: trino
1920
volumes:
21+
- ./data/stage:/var/lib/fxttr/stage
2022
- ./trino/conf/trino.pass:/trino.pass
2123
- ./trino/conf/cert.pem:/cert.pem
2224
ports:
@@ -29,6 +31,9 @@ services:
2931
nofile:
3032
soft: 20000
3133
hard: 40000
34+
env_file:
35+
- env/clickhouse.env
36+
- env/minio.env
3237

3338
networks:
3439
public:

ds_adm/__init__.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pathlib import Path
2+
3+
4+
def __resolve_provider__() -> str:
5+
"""Determine the current provider"""
6+
def __is_valid_command__(name):
7+
"""Check whether `name` is on PATH and marked as executable."""
8+
9+
from shutil import which
10+
11+
return which(name) is not None
12+
13+
if __is_valid_command__("talosctl"):
14+
return "talosctl"
15+
16+
if __is_valid_command__("microk8s"):
17+
return "microk8s"
18+
19+
raise Exception("Could not find any provider!")
20+
21+
def __is_first_run__() -> bool:
22+
lock_file = Path(__file__).joinpath("/../.dsadm_lockfile")
23+
result = False
24+
25+
if not lock_file.exists():
26+
result = True
27+
lock_file.touch()
28+
29+
return result
30+
31+
PROVIDER = __resolve_provider__()
32+
#IS_FIRST_RUN = __is_first_run__()

ds_adm/config.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from ds_adm import PROVIDER
2+
from ds_adm.helm.chart import HelmChart
3+
from ds_adm.helm.plugin import HelmPlugin
4+
from ds_adm.helm.repository import HelmRepository
5+
from ds_adm.kube.operator import KubeOperator
6+
import yaml
7+
8+
class Config(yaml.YAMLObject):
9+
yaml_loader = yaml.SafeLoader
10+
yaml_tag = u'!dsadm'
11+
12+
def __init__(self,
13+
repos: list[HelmRepository] = [],
14+
plugins: list[HelmPlugin] = [],
15+
charts: list[HelmChart] = [],
16+
operators: list[KubeOperator] = []):
17+
self.provider = PROVIDER
18+
self.repos = repos
19+
self.plugins = plugins
20+
self.charts = charts
21+
self.operators = operators
22+
23+
def parse(path: str = "ds_config.yaml") -> Config:
24+
with open(path, 'r') as file:
25+
return yaml.safe_load(file)
26+
27+

ds_adm/helm/chart.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from ds_adm.runtime import helm
2+
3+
4+
class HelmChart:
5+
def __init__(self, name: str, namespace: str, repo: str, values: str):
6+
self.name = name
7+
self.namespace = namespace
8+
self.repo = repo
9+
self.values = values
10+
11+
def install(self):
12+
print(f"🚀 Installing helm chart {self.name} in the {self.namespace} namespace...")
13+
helm(f"upgrade --install {self.name} {self.repo} --namespace {self.namespace} -f k8s/values/{self.values}")
14+

ds_adm/helm/plugin.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from ds_adm.runtime import helm
2+
3+
4+
class HelmPlugin:
5+
def __init__(self, name: str, url: str):
6+
self.name = name
7+
self.url = url
8+
9+
def __is_installed__(self):
10+
helm(f"plugin list | grep -qw {self.name}").returncode == 0
11+
12+
def install(self, reinstall: bool = False):
13+
if not reinstall and self.__is_installed__():
14+
pass
15+
16+
print(f"📦 Adding helm plugin {self.name}...")
17+
helm(f"plugin install {self.url}")

ds_adm/helm/repository.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from ds_adm.runtime import helm
2+
3+
4+
class HelmRepository:
5+
def __init__(self, name: str, url: str):
6+
self.name = name
7+
self.url = url
8+
9+
def __is_installed__(self):
10+
helm(f"repo list | grep -qw {self.name}").returncode == 0
11+
12+
def install(self, reinstall: bool = False):
13+
if not reinstall and self.__is_installed__():
14+
pass
15+
16+
print(f"📦 Adding helm repository {self.name}...")
17+
helm(f"repo add {self.name} {self.url}")
18+
helm(f"repo update")
19+

ds_adm/kube/config_map.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from ds_adm.runtime import kubectl
2+
3+
4+
def apply():
5+
print("🔧 Adding config maps...")
6+
kubectl("apply -f k8s/manifests/")

0 commit comments

Comments
 (0)