Skip to content

Commit a251652

Browse files
committed
feat: add devcontainer setup with YDB
Signed-off-by: Vladislav Polyakov <[email protected]>
1 parent a63ea4f commit a251652

File tree

6 files changed

+144
-1
lines changed

6 files changed

+144
-1
lines changed

.devcontainer/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM mcr.microsoft.com/devcontainers/go:1-1.21-bookworm
2+
3+
# [Optional] Uncomment this section to install additional OS packages.
4+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
5+
# && apt-get -y install --no-install-recommends <your-pkg>
6+
7+
# Install golangci from GitHub. Binary will be $(go env GOPATH)/bin/golangci-lint
8+
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
9+
10+
# Install ydb cli from GitHub.
11+
# COPY ./ydb /usr/local/bin/ydb
12+
# RUN chmod +x /usr/local/bin/ydb
13+
14+
# [Optional] Uncomment the next lines to use go get to install anything else you need
15+
# USER vscode
16+
# RUN go get ...
17+
# USER root

.devcontainer/compose.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: '3.8'
2+
3+
volumes:
4+
ydb-data:
5+
# driver: local
6+
# driver_opts:
7+
# type: tmpfs
8+
# device: tmpfs
9+
# o: size=80g
10+
ydb-certs:
11+
12+
services:
13+
sdk:
14+
build:
15+
context: .
16+
dockerfile: Dockerfile
17+
18+
volumes:
19+
- ydb-certs:/ydb_certs
20+
- ../:/workspaces/ydb-go-sdk:cached
21+
22+
environment:
23+
- YDB_VERSION=24.3
24+
- YDB_CONNECTION_STRING=grpc://ydb:2136/local
25+
- YDB_CONNECTION_STRING_SECURE=grpcs://ydb:2135/local
26+
- YDB_ANONYMOUS_CREDENTIALS=1
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+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
33+
network_mode: service:ydb
34+
35+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
36+
# (Adding the "ports" property to this file will not forward from a Codespace.)
37+
38+
ydb:
39+
image: ghcr.io/ydb-platform/local-ydb:24.3
40+
restart: unless-stopped
41+
hostname: ydb
42+
platform: linux/amd64
43+
44+
volumes:
45+
- ydb-data:/ydb_data
46+
- ydb-certs:/ydb_certs
47+
48+
environment:
49+
- YDB_USE_IN_MEMORY_PDISKS=true
50+
- GRPC_TLS_PORT=2135
51+
- GRPC_PORT=2136
52+
- MON_PORT=8765
53+
54+
# Add "forwardPorts": [2135, 8765] to **devcontainer.json** to forward YDB locally.
55+
# (Adding the "ports" property to this file will not forward from a Codespace.)

.devcontainer/configure.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
if which ydb > /dev/null 2>&1; then
4+
ENDPOINT=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | awk -F/ '{print $3}')
5+
DATABASE=$(echo ${YDB_CONNECTION_STRING_SECURE:-$YDB_CONNECTION_STRING} | awk -F/ '{print "/" $4}')
6+
CA_FILE_OPTION=""
7+
8+
if [ -n "$YDB_CONNECTION_STRING_SECURE" ]; then
9+
CA_FILE_OPTION="--ca-file ${YDB_SSL_ROOT_CERTIFICATES_FILE}"
10+
fi
11+
12+
ydb config profile create local \
13+
--endpoint "$ENDPOINT" \
14+
--database "$DATABASE" \
15+
$CA_FILE_OPTION
16+
17+
ydb config profile activate local
18+
fi

.devcontainer/devcontainer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/go-postgres
3+
{
4+
"name": "Go & YDB",
5+
"service": "sdk",
6+
"dockerComposeFile": "compose.yml",
7+
"workspaceFolder": "/workspaces/ydb-go-sdk",
8+
// Allows the container to use ptrace, which is useful for debugging.
9+
"capAdd": [
10+
"SYS_PTRACE"
11+
],
12+
// Disables seccomp, which can be necessary for some debugging tools to function correctly.
13+
"securityOpt": [
14+
"seccomp=unconfined"
15+
],
16+
// Features to add to the dev container. More info: https://containers.dev/features.
17+
"features": {
18+
"ghcr.io/devcontainers/features/github-cli:1": {}
19+
},
20+
// Configure tool-specific properties.
21+
"customizations": {
22+
"vscode": {
23+
"extensions": [
24+
"golang.go",
25+
"VisualStudioExptTeam.vscodeintellicode",
26+
"redhat.vscode-yaml",
27+
"zxh404.vscode-proto3",
28+
"github.vscode-github-actions"
29+
]
30+
}
31+
},
32+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
33+
"forwardPorts": [2135, 2136, 8765],
34+
// Use 'initializeCommand' to run commands before the container is created.
35+
"initializeCommand": "cd \"${localWorkspaceFolder}\" && git config --local user.email \"$(git config user.email)\" && git config --local user.name \"$(git config user.name)\"",
36+
// Use 'postCreateCommand' to run commands after the container is created.
37+
"postCreateCommand": "go version && golangci-lint --version && go mod download",
38+
// Use 'postStartCommand' to run commands after the container is started.
39+
"postStartCommand": ".devcontainer/configure.sh"
40+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
41+
// "remoteUser": "root"
42+
}

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*.code-workspace
44
.vscode/*
55
.history/
6-
.devcontainer
76
*.vsix
87
*.swp
98
*.exe

0 commit comments

Comments
 (0)