Skip to content

Commit

Permalink
chore: add devcontainers setup with ydb
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Polyakov <[email protected]>
  • Loading branch information
polRk committed Jan 3, 2025
1 parent b5d1115 commit ba7b321
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm

RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install 18"
RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install 20"
RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install 22"

# [Optional] Uncomment if you want to install more global node modules
ARG NODE_MODULES="typescript"
RUN su node -c "npm install -g ${NODE_MODULES}" \
&& npm cache clean --force > /dev/null 2>&1

# [Optional] Uncomment if you want to install ydb cli
RUN curl -fsSL https://install.ydb.tech/cli | bash

# [Optional] Uncomment if you want to install bun
RUN curl -fsSL https://bun.sh/install | bash
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:
build:
context: .
dockerfile: Dockerfile

volumes:
- ydb-certs:/ydb_certs
- ../:/workspaces/ydb-js-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

network_mode: bridge

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

source /usr/local/share/nvm/nvm.sh && nvm use --lts

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
48 changes: 48 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "JavaScript & YDB",
"service": "sdk",
"dockerComposeFile": "compose.yml",
"workspaceFolder": "/workspaces/ydb-js-sdk",
// Allows the container to use ptrace, which is useful for debugging.
"capAdd": [
"SYS_PTRACE"
],
// Disables seccomp, which can be necessary for some debugging tools to function correctly.
"securityOpt": [
"seccomp=unconfined"
],
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/git": {},
"ghcr.io/devcontainers/features/common-utils": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
2135,
2136,
8765
],
// Use 'initializeCommand' to run commands before the container is created.
"initializeCommand": "git config --local user.email \"$(git config user.email)\" && git config --local user.name \"$(git config user.name)\"",
// Use 'postStartCommand' to run commands after the container is started.
"postStartCommand": ".devcontainer/configure.sh",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"mikestead.dotenv",
"dbaeumer.vscode-eslint",
"VisualStudioExptTeam.vscodeintellicode",
"oxc.oxc-vscode",
"esbenp.prettier-vscode",
"vitest.explorer",
"redhat.vscode-yaml"
]
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly

0 comments on commit ba7b321

Please sign in to comment.