Skip to content

Add YDB service to devcontainer setup #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ RUN wget https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/c
&& tar -xf ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz \
&& cp ccache-${CCACHE_VERSION}-linux-x86_64/ccache /usr/local/bin/ \
&& rm -rf ccache-${CCACHE_VERSION}-linux-x86_64 ccache-${CCACHE_VERSION}-linux-x86_64.tar.xz

# Install ydb cli 2.16.0
ENV YDB_VERSION=2.16.0
RUN wget https://storage.yandexcloud.net/yandexcloud-ydb/release/${YDB_VERSION}/linux/amd64/ydb && \
chmod u+x ydb && \
mv ydb /usr/local/bin/
55 changes: 55 additions & 0 deletions .devcontainer/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
volumes:
ydb-data:
# driver: local
# driver_opts:
# type: tmpfs
# device: tmpfs
# o: size=80g
ydb-certs:

services:
sdk:
platform: linux/amd64

build:
context: .
dockerfile: Dockerfile

volumes:
- ydb-certs:/ydb_certs
- ../:/workspaces/ydb-cpp-sdk:cached

environment:
- YDB_VERSION=24.3
- YDB_CONNECTION_STRING=grpc://ydb:2136/local
- YDB_CONNECTION_STRING_SECURE=grpcs://ydb:2135/local
- YDB_ANONYMOUS_CREDENTIALS=1
- YDB_SSL_ROOT_CERTIFICATES_FILE=/ydb_certs/ca.pem

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:ydb

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

ydb:
image: ghcr.io/ydb-platform/local-ydb:24.3
restart: unless-stopped
hostname: ydb
platform: linux/amd64

volumes:
- ydb-data:/ydb_data
- ydb-certs:/ydb_certs

environment:
- YDB_USE_IN_MEMORY_PDISKS=true
- GRPC_TLS_PORT=2135
- GRPC_PORT=2136
- MON_PORT=8765

# Add "forwardPorts": [2135, 8765] to **devcontainer.json** to forward YDB locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
19 changes: 17 additions & 2 deletions .devcontainer/configure.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/bin/sh
WORKSPACE_FOLDER=$1

cd $1
mkdir -p build
git submodule update --init --recursive
ccache -o cache_dir=/root/.ccache
cmake --preset release-test-with-ccache-basedir -DCMAKE_EXPORT_COMPILE_COMMANDS=1

if which ydb > /dev/null 2>&1; then
ENDPOINT=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | awk -F/ '{print $3}')
DATABASE=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | awk -F/ '{print "/" $4}')
CA_FILE_OPTION=""

if [ -n "$YDB_CONNECTION_STRING_SECURE" ]; then
CA_FILE_OPTION="--ca-file ${YDB_SSL_ROOT_CERTIFICATES_FILE}"
fi

ydb config profile create local \
--endpoint "$ENDPOINT" \
--database "$DATABASE" \
$CA_FILE_OPTION

ydb config profile activate local
fi
28 changes: 13 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile",
"options": [
"--platform",
"linux/amd64"
]
},
"name": "C++ & YDB",
"service": "sdk",
"dockerComposeFile": "compose.yml",
"workspaceFolder": "/workspaces/ydb-cpp-sdk",
// Allows the container to use ptrace, which is useful for debugging.
"capAdd": [
"SYS_PTRACE"
Expand All @@ -19,16 +15,18 @@
],
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
}
"ghcr.io/devcontainers/features/github-cli:1": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [],
"forwardPorts": [
2135,
2136,
8765
],
// Use 'initializeCommand' to run commands before the container is created.
"initializeCommand": "mkdir -p ${localEnv:HOME}/.ccache && cd \"${localWorkspaceFolder}\" && git config --local user.email \"$(git config user.email)\" && git config --local user.name \"$(git config user.name)\"",
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/configure.sh ${containerWorkspaceFolder}",
// Use 'postStartCommand' to run commands after the container is started.
"postStartCommand": ".devcontainer/configure.sh",
// Configure tool-specific properties.
"customizations": {
"vscode": {
Expand Down
Loading