Skip to content

Commit 4e2eaec

Browse files
polRkvgvoleg
andauthored
Add devcontainer configuration for YDB Python SDK (#585)
* 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 * Update devcontainer mount to use specific SSH signing key Signed-off-by: Vladislav Polyakov <polrk@ydb.tech> * Add sign-off configuration and GPG settings in initialization scripts Signed-off-by: Vladislav Polyakov <polrk@ydb.tech> * Update postStart.sh --------- Signed-off-by: Vladislav Polyakov <polrk@ydb.tech> Co-authored-by: Oleg Ovcharuk <vgvoleg@gmail.com>
1 parent b273d1e commit 4e2eaec

File tree

6 files changed

+157
-0
lines changed

6 files changed

+157
-0
lines changed

.devcontainer/Dockerfile

+8
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://raw.githubusercontent.com/ydb-platform/ydb/refs/heads/main/ydb/apps/ydb/install/install.sh | bash

.devcontainer/commands/initialize.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
git config --local format.signoff true
5+
git config --local user.name "$(git config user.name)"
6+
git config --local user.email "$(git config user.email)"

.devcontainer/commands/postCreate.sh

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

.devcontainer/commands/postStart.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
5+
# Install dependencies
6+
pip install -r requirements.txt
7+
# Install ydb package
8+
pip install -e .
9+
# Install tox for CI
10+
pip install tox
11+

.devcontainer/compose.yml

+51
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_IMAGE_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

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "Python & YDB",
3+
"service": "sdk",
4+
"dockerComposeFile": "compose.yml",
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 'postCreateCommand' to run commands after the container is created.
31+
"postCreateCommand": "chmod +x .devcontainer/commands/postCreate.sh && .devcontainer/commands/postCreate.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.autopep8",
39+
"ms-python.debugpy",
40+
"ms-python.flake8",
41+
"ms-python.isort",
42+
"ms-python.pylint",
43+
"ms-python.python",
44+
"ms-python.vscode-pylance",
45+
"ms-python.vscode-python-envs"
46+
]
47+
}
48+
},
49+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
50+
"remoteUser": "root",
51+
"mounts": [
52+
"source=${localEnv:HOME}/.ssh/id_ed25519_signing,target=/root/.ssh/id_ed25519_signing,type=bind,readonly"
53+
]
54+
}

0 commit comments

Comments
 (0)