Skip to content

Commit 6e4f35f

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
1 parent 30b4191 commit 6e4f35f

File tree

6 files changed

+172
-0
lines changed

6 files changed

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

.devcontainer/compose.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
ydb:
33+
image: ghcr.io/ydb-platform/local-ydb:24.3
34+
restart: unless-stopped
35+
hostname: ydb
36+
platform: linux/amd64
37+
38+
ports:
39+
- 2135:2135
40+
- 2136:2136
41+
- 8765:8765
42+
43+
volumes:
44+
- ydb-data:/ydb_data
45+
- ydb-certs:/ydb_certs
46+
47+
environment:
48+
- YDB_USE_IN_MEMORY_PDISKS=true
49+
- GRPC_TLS_PORT=2135
50+
- GRPC_PORT=2136
51+
- MON_PORT=8765
52+
53+
prometheus:
54+
image: prom/prometheus:v3.3.0
55+
restart: unless-stopped
56+
hostname: prometheus
57+
platform: linux/amd64
58+
59+
ports:
60+
- 9090:9090
61+
62+
volumes:
63+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
64+
- ydb-certs:/ydb_certs

.devcontainer/devcontainer.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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",
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+
2135,
25+
2136,
26+
8765,
27+
9090,
28+
9464
29+
],
30+
// Use 'initializeCommand' to run commands before the container is created.
31+
"initializeCommand": "chmod +x .devcontainer/commands/initialize.sh && .devcontainer/commands/initialize.sh",
32+
// Use 'postStartCommand' to run commands after the container is started.
33+
"postStartCommand": "chmod +x .devcontainer/commands/postStart.sh && .devcontainer/commands/postStart.sh",
34+
// Configure tool-specific properties.
35+
"customizations": {
36+
"vscode": {
37+
"extensions": [
38+
"ms-python.python",
39+
"ms-python.debugpy",
40+
"ms-python.vscode-pylance",
41+
"ms-python.vscode-python-envs"
42+
]
43+
}
44+
},
45+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
46+
"remoteUser": "root",
47+
"mounts": [
48+
"source=${localEnv:HOME}/.config/gh/hosts.yml,target=/root/.config/gh/hosts.yml,type=bind,consistency=cached,source-exists=true"
49+
]
50+
}

.devcontainer/prometheus.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
# Alertmanager configuration
6+
alerting:
7+
alertmanagers:
8+
- static_configs:
9+
- targets: ['localhost:9093']
10+
11+
scrape_configs:
12+
- job_name: ydb-python-sdk
13+
scrape_interval: 1s
14+
scrape_timeout: 1s
15+
static_configs:
16+
- targets: ['sdk:9464']

0 commit comments

Comments
 (0)