Skip to content

Commit 4800f4b

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 4800f4b

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-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

.devcontainer/commands/initialize.sh

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)"

.devcontainer/commands/postStart.sh

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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

.devcontainer/devcontainer.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "Python & YDB",
3+
"service": "sdk",
4+
"dockerComposeFile": "deploy",
5+
"workspaceFolder": "/workspaces/ydb-python-sdk",
6+
// Allows the container to use ptrace, which is useful for debugging.
7+
"capAdd": [
8+
"SYS_PTRACE"
9+
],
10+
// Disables seccomp, which can be necessary for some debugging tools to function correctly.
11+
"securityOpt": [
12+
"seccomp=unconfined"
13+
],
14+
// Features to add to the dev container. More info: https://containers.dev/features.
15+
"features": {
16+
"ghcr.io/devcontainers/features/git": {},
17+
"ghcr.io/devcontainers/features/common-utils": {},
18+
"ghcr.io/devcontainers/features/github-cli:1": {}
19+
},
20+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
21+
"forwardPorts": [
22+
2135,
23+
2136,
24+
8765,
25+
9090,
26+
9464
27+
],
28+
// Use 'initializeCommand' to run commands before the container is created.
29+
"initializeCommand": "chmod +x .devcontainer/commands/initialize.sh && .devcontainer/commands/initialize.sh",
30+
// Use 'postStartCommand' to run commands after the container is started.
31+
"postStartCommand": "chmod +x .devcontainer/commands/postStart.sh && .devcontainer/commands/postStart.sh",
32+
// Configure tool-specific properties.
33+
"customizations": {
34+
"vscode": {
35+
"extensions": [
36+
"ms-python.python",
37+
"ms-python.debugpy",
38+
"ms-python.vscode-pylance",
39+
"ms-python.vscode-python-envs"
40+
]
41+
}
42+
},
43+
"overrideCommand": true
44+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
45+
// "remoteUser": "root"
46+
}

.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)