Skip to content

Commit 2823272

Browse files
committed
Add devcontainer configuration for YDB Python SDK
- Create Dockerfile for building the SDK environment - Add docker-compose configuration for YDB services - Include YDB configuration file for storage and channel profiles - Set up initialization and configuration scripts for YDB CLI - Configure Prometheus for monitoring YDB services - Implement SSH signing setup for GitHub CLI
1 parent 30b4191 commit 2823272

File tree

10 files changed

+473
-0
lines changed

10 files changed

+473
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/devcontainers/python:3-bookworm
2+
3+
# [Optional] Uncomment if you want to install more tools
4+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
# && apt-get -y install --no-install-recommends <your-pkg>
6+
7+
# [Optional] Uncomment if you want to install ydb cli
8+
RUN curl -fsSL https://install.ydb.tech/cli | bash

.devcontainer/cluster/compose.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
volumes:
2+
ydb-data:
3+
# driver: local
4+
# driver_opts:
5+
# type: tmpfs
6+
# device: tmpfs
7+
# o: size=80g
8+
ydb-certs:
9+
10+
x-ydb-node: &ydb-node
11+
image: cr.yandex/crptqonuodf51kdj7a7d/ydb:24.3.11.13
12+
restart: always
13+
platform: linux/amd64
14+
privileged: true
15+
volumes:
16+
- ./ydb.yaml:/opt/ydb/cfg/config.yaml
17+
18+
services:
19+
sdk:
20+
build:
21+
context: ..
22+
dockerfile: Dockerfile
23+
hostname: sdk
24+
25+
volumes:
26+
- ydb-certs:/ydb_certs
27+
- ../../:/workspaces/ydb-python-sdk:cached
28+
29+
environment:
30+
- YDB_VERSION=24.3.11.13
31+
- YDB_CLUSTER_MODE=1
32+
- YDB_CREDENTIALS_USER=root
33+
- YDB_CREDENTIALS_PASSWORD=
34+
- YDB_CONNECTION_STRING=grpc://ydb:2136/Root/testdb
35+
36+
# Overrides default command so things don't shut down after the process ends.
37+
command: sleep infinity
38+
39+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
40+
# (Adding the "ports" property to this file will not forward from a Codespace.)
41+
42+
ydb-storage:
43+
<<: *ydb-node
44+
hostname: ydb
45+
command:
46+
- /opt/ydb/bin/ydbd
47+
- server
48+
- --grpc-port
49+
- '2136'
50+
- --mon-port
51+
- '8765'
52+
- --ic-port
53+
- '19001'
54+
- --yaml-config
55+
- /opt/ydb/cfg/config.yaml
56+
- --node
57+
- static
58+
- --label
59+
- deployment=docker
60+
ports:
61+
- 8765:8765
62+
volumes:
63+
- ydb-data:/ydb_data
64+
- ydb-certs:/ydb_certs
65+
- ./ydb.yaml:/opt/ydb/cfg/config.yaml
66+
healthcheck:
67+
test: bash -c "exec 6<> /dev/tcp/ydb/2136"
68+
interval: 10s
69+
timeout: 1s
70+
retries: 3
71+
start_period: 30s
72+
deploy:
73+
replicas: 1
74+
75+
ydb-storage-init:
76+
<<: *ydb-node
77+
restart: no
78+
command:
79+
- /bin/sh
80+
- -c
81+
- "/opt/ydb/bin/ydbd -s 'grpc://ydb:2136' admin blobstorage config init --yaml-file /opt/ydb/cfg/config.yaml || exit 0"
82+
depends_on:
83+
ydb-storage:
84+
condition: service_healthy
85+
86+
ydb-database-init:
87+
<<: *ydb-node
88+
restart: no
89+
command:
90+
- /bin/sh
91+
- -c
92+
- "/opt/ydb/bin/ydbd -s 'grpc://ydb:2136' admin database '/Root/testdb' create ssd:1 || exit 0"
93+
depends_on:
94+
ydb-storage:
95+
condition: service_healthy
96+
ydb-storage-init:
97+
condition: service_completed_successfully
98+
99+
ydb-database:
100+
<<: *ydb-node
101+
command:
102+
- /opt/ydb/bin/ydbd
103+
- server
104+
- --grpc-port
105+
- '2136'
106+
- --mon-port
107+
- '8765'
108+
- --ic-port
109+
- '19001'
110+
- --yaml-config
111+
- /opt/ydb/cfg/config.yaml
112+
- --tenant
113+
- '/Root/testdb'
114+
- --node-broker
115+
- 'grpc://ydb:2136'
116+
- --label
117+
- deployment=docker
118+
depends_on:
119+
ydb-storage:
120+
condition: service_healthy
121+
ydb-storage-init:
122+
condition: service_completed_successfully
123+
ydb-database-init:
124+
condition: service_completed_successfully
125+
deploy:
126+
replicas: 3
127+
128+
prometheus:
129+
image: prom/prometheus:v3.3.0
130+
restart: unless-stopped
131+
hostname: prometheus
132+
platform: linux/amd64
133+
134+
volumes:
135+
- ../prometheus.yml:/etc/prometheus/prometheus.yml
136+
- ydb-certs:/ydb_certs
137+
138+
ports:
139+
- 9090:9090
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
3+
{
4+
"name": "Python & YDB Cluster",
5+
"service": "sdk",
6+
"dockerComposeFile": "compose.yml",
7+
"workspaceFolder": "/workspaces/ydb-python-sdk",
8+
// Allows the container to use ptrace, which is useful for debugging.
9+
"capAdd": [
10+
"SYS_PTRACE"
11+
],
12+
// Disables seccomp, which can be necessary for some debugging tools to function correctly.
13+
"securityOpt": [
14+
"seccomp=unconfined"
15+
],
16+
// Features to add to the dev container. More info: https://containers.dev/features.
17+
"features": {
18+
"ghcr.io/devcontainers/features/git": {},
19+
"ghcr.io/devcontainers/features/common-utils": {},
20+
"ghcr.io/devcontainers/features/github-cli:1": {}
21+
},
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
23+
"forwardPorts": [
24+
2136,
25+
8765,
26+
19001,
27+
9090,
28+
9464
29+
],
30+
// Use 'initializeCommand' to run commands before the container is created.
31+
"initializeCommand": "chmod +x .devcontainer/initialize.sh && .devcontainer/initialize.sh",
32+
// Use 'postStartCommand' to run commands after the container is started.
33+
"postStartCommand": "chmod +x .devcontainer/configure.sh && .devcontainer/configure.sh",
34+
// Add postCreateCommand to set up SSH signing
35+
"postCreateCommand": "chmod +x .devcontainer/setup-ssh-signing.sh && .devcontainer/setup-ssh-signing.sh",
36+
// Configure tool-specific properties.
37+
"customizations": {
38+
"vscode": {
39+
"extensions": [
40+
"GitHub.copilot-chat",
41+
"github.vscode-github-actions",
42+
"mikestead.dotenv",
43+
"redhat.vscode-yaml",
44+
"VisualStudioExptTeam.vscodeintellicode",
45+
"ms-python.debugpy",
46+
"ms-python.python",
47+
"ms-python.vscode-pylance",
48+
"KevinRose.vsc-python-indent",
49+
"ms-python.vscode-python-envs"
50+
]
51+
}
52+
},
53+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
54+
"remoteUser": "root",
55+
"mounts": [
56+
"source=${localEnv:HOME}/.config/gh/hosts.yml,target=/root/.config/gh/hosts.yml,type=bind,consistency=cached,source-exists=true"
57+
]
58+
}

.devcontainer/cluster/ydb.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
actor_system_config:
2+
cpu_count: 1
3+
node_type: STORAGE
4+
use_auto_config: true
5+
blob_storage_config:
6+
service_set:
7+
groups:
8+
- erasure_species: none
9+
rings:
10+
- fail_domains:
11+
- vdisk_locations:
12+
- node_id: 1
13+
path: SectorMap:1:64
14+
pdisk_category: SSD
15+
channel_profile_config:
16+
profile:
17+
- channel:
18+
- erasure_species: none
19+
pdisk_category: 0
20+
storage_pool_kind: ssd
21+
- erasure_species: none
22+
pdisk_category: 0
23+
storage_pool_kind: ssd
24+
- erasure_species: none
25+
pdisk_category: 0
26+
storage_pool_kind: ssd
27+
profile_id: 0
28+
column_shard_config:
29+
disabled_on_scheme_shard: False
30+
domains_config:
31+
domain:
32+
- name: Root
33+
storage_pool_types:
34+
- kind: ssd
35+
pool_config:
36+
box_id: 1
37+
erasure_species: none
38+
kind: ssd
39+
pdisk_filter:
40+
- property:
41+
- type: SSD
42+
vdisk_kind: Default
43+
state_storage:
44+
- ring:
45+
node: [1]
46+
nto_select: 1
47+
ssid: 1
48+
host_configs:
49+
- drive:
50+
- path: SectorMap:1:64
51+
type: SSD
52+
host_config_id: 1
53+
hosts:
54+
- host: ydb
55+
host_config_id: 1
56+
node_id: 1
57+
port: 19001
58+
walle_location:
59+
body: 1
60+
data_center: az-1
61+
rack: '0'
62+
static_erasure: none

.devcontainer/compose.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
volumes:
2+
ydb-data:
3+
# driver: local
4+
# driver_opts:
5+
# type: tmpfs
6+
# device: tmpfs
7+
# o: size=80g
8+
ydb-certs:
9+
10+
services:
11+
sdk:
12+
build:
13+
context: .
14+
dockerfile: Dockerfile
15+
hostname: sdk
16+
17+
volumes:
18+
- ydb-certs:/ydb_certs
19+
- ../:/workspaces/ydb-python-sdk:cached
20+
21+
environment:
22+
- YDB_VERSION=24.3
23+
- YDB_CREDENTIALS_USER=root
24+
- YDB_CREDENTIALS_PASSWORD=1234
25+
- YDB_CONNECTION_STRING=grpc://ydb:2136/local
26+
- YDB_CONNECTION_STRING_SECURE=grpcs://ydb:2135/local
27+
- YDB_SSL_ROOT_CERTIFICATES_FILE=/ydb_certs/ca.pem
28+
29+
# Overrides default command so things don't shut down after the process ends.
30+
command: sleep infinity
31+
32+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
33+
# (Adding the "ports" property to this file will not forward from a Codespace.)
34+
35+
ydb:
36+
image: ghcr.io/ydb-platform/local-ydb:24.3
37+
restart: unless-stopped
38+
hostname: ydb
39+
platform: linux/amd64
40+
41+
volumes:
42+
- ydb-data:/ydb_data
43+
- ydb-certs:/ydb_certs
44+
45+
environment:
46+
- YDB_USE_IN_MEMORY_PDISKS=true
47+
- GRPC_TLS_PORT=2135
48+
- GRPC_PORT=2136
49+
- MON_PORT=8765
50+
51+
prometheus:
52+
image: prom/prometheus:v3.3.0
53+
restart: unless-stopped
54+
hostname: prometheus
55+
platform: linux/amd64
56+
57+
volumes:
58+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
59+
- ydb-certs:/ydb_certs
60+
61+
ports:
62+
- 9090:9090

.devcontainer/configure.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Set up YDB profile if ydb cli exists
5+
if which ydb > /dev/null 2>&1; then
6+
ENDPOINT=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | awk -F/ '{print $1 "//" $3}')
7+
DATABASE=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | cut -d/ -f4-)
8+
CA_FILE_OPTION=""
9+
10+
if [ -n "$YDB_SSL_ROOT_CERTIFICATES_FILE" ]; then
11+
ENDPOINT="${ENDPOINT/grpc:/grpcs:}"
12+
CA_FILE_OPTION="--ca-file ${YDB_SSL_ROOT_CERTIFICATES_FILE}"
13+
fi
14+
15+
ydb config profile replace local \
16+
--endpoint "$ENDPOINT" \
17+
--database "/$DATABASE" \
18+
$CA_FILE_OPTION
19+
20+
ydb config profile activate local
21+
fi
22+
23+
if [ -f ~/.ssh/id_ed25519_signing ]; then
24+
git config --global gpg.format ssh
25+
git config --global commit.gpgsign true
26+
fi

0 commit comments

Comments
 (0)