From 823e4c43c6e6374da69829d1b8cd8259df27bbf3 Mon Sep 17 00:00:00 2001 From: Vladislav Polyakov Date: Fri, 29 Nov 2024 14:17:56 +0000 Subject: [PATCH] Add YDB service to devcontainer setup Signed-off-by: Vladislav Polyakov --- .devcontainer/Dockerfile | 6 ++++ .devcontainer/compose.yml | 55 +++++++++++++++++++++++++++++++++ .devcontainer/configure.sh | 19 ++++++++++-- .devcontainer/devcontainer.json | 28 ++++++++--------- 4 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 .devcontainer/compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 05d01d7dbc..a8970dee88 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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/ diff --git a/.devcontainer/compose.yml b/.devcontainer/compose.yml new file mode 100644 index 0000000000..f896916862 --- /dev/null +++ b/.devcontainer/compose.yml @@ -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.) diff --git a/.devcontainer/configure.sh b/.devcontainer/configure.sh index 471865297f..44eff912a8 100755 --- a/.devcontainer/configure.sh +++ b/.devcontainer/configure.sh @@ -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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 44d51d9e86..067965ebee 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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" @@ -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": {