Skip to content

Commit 6eecc78

Browse files
authored
Merge af3f877 into 224fb1c
2 parents 224fb1c + af3f877 commit 6eecc78

File tree

14 files changed

+531
-143
lines changed

14 files changed

+531
-143
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# syntax=docker/dockerfile:1.4
2+
ARG BASE_IMAGE="cr.yandex/mirror/ubuntu"
3+
ARG BASE_IMAGE_TAG="focal"
4+
ARG BREAKPAD_GIT_TAG="v2022.07.12"
5+
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS breakpad-base
6+
RUN \
7+
apt-get -yqq update && \
8+
apt-get -yqq install --no-install-recommends git build-essential libz-dev python3 curl && \
9+
apt-get clean all && rm -rf /var/lib/apt/lists/*
10+
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
11+
ENV PATH="/depot_tools:${PATH}"
12+
13+
FROM breakpad-base AS breakpad-build
14+
COPY /breakpad_init.cc /breakpad/breakpad_init.cc
15+
RUN \
16+
cd breakpad && \
17+
fetch breakpad && \
18+
cd src && \
19+
git checkout -- . && git checkout tags/${BREAKPAD_GIT_TAG} && \
20+
./configure && make && \
21+
g++ -std=c++11 -shared -Wall -o ../libbreakpad_init.so -fPIC ../breakpad_init.cc -Isrc/ -Lsrc/client/linux/ -lbreakpad_client -lpthread
22+
23+
FROM scratch AS breakpad-release
24+
COPY --link --from=breakpad-build /breakpad/libbreakpad_init.so /usr/lib/libbreakpad_init.so
25+
COPY --link --from=breakpad-build /breakpad/src/src/tools/linux/md2core/minidump-2-core /usr/bin/minidump-2-core
26+
COPY --link --from=breakpad-build /breakpad/src/src/processor/minidump_stackwalk /usr/bin/minidump_stackwalk
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// breakpad_init.cc: A shared library to initialize breakpad signal handler via LD_PRELOAD.
2+
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <sys/wait.h>
6+
#include "client/linux/handler/exception_handler.h"
7+
8+
using google_breakpad::MinidumpDescriptor;
9+
using google_breakpad::ExceptionHandler;
10+
11+
// callback function, called after minidump was created
12+
static bool dumpCallback(const MinidumpDescriptor& descriptor, void* context, bool succeeded) {
13+
char *script = getenv("BREAKPAD_MINIDUMPS_SCRIPT");
14+
if (script != NULL) {
15+
pid_t pid=fork();
16+
if (pid == 0) {
17+
char* dumpSucceded = succeeded ? (char *)"true" : (char *)"false";
18+
char* descriptorPath = succeeded ? (char *)descriptor.path() : (char *)"\0";
19+
char* cmd[] = {script, dumpSucceded, descriptorPath, NULL};
20+
execve(cmd[0], &cmd[0], NULL);
21+
} else {
22+
waitpid(pid, 0, 0);
23+
}
24+
}
25+
return succeeded;
26+
}
27+
28+
// create signal handlers on shared library init
29+
__attribute__((constructor))
30+
static void breakpad_init() {
31+
32+
const char * path = ::getenv("BREAKPAD_MINIDUMPS_PATH");
33+
34+
static MinidumpDescriptor descriptor((path) ? path : "/tmp");
35+
static ExceptionHandler handler(
36+
descriptor, // minidump descriptor
37+
NULL, // callback filter
38+
dumpCallback, // callback function
39+
NULL, // callback context
40+
true, // do install handler
41+
-1 // server descriptor
42+
);
43+
}

ydb/deploy/breakpad_init/pkg.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"meta": {
3+
"name": "breakpad_init",
4+
"maintainer": "ydb <info@ydb.tech>",
5+
"description": "Package with breakpad_init",
6+
"version": "v2022.07.12.{revision}"
7+
},
8+
"build": {},
9+
"params": {
10+
"docker_build_network": "host",
11+
"docker_registry": "cr.yandex",
12+
"docker_repository": "crp2lrlsrs36odlvd8dv",
13+
"docker_target": "breakpad-release",
14+
"docker_build_arg": {
15+
"BREAKPAD_GIT_TAG": "v2022.07.12"
16+
}
17+
},
18+
"data": [
19+
{
20+
"source": {
21+
"type": "RELATIVE",
22+
"path": "Dockerfile"
23+
},
24+
"destination": {
25+
"path": "/Dockerfile"
26+
}
27+
},
28+
{
29+
"source": {
30+
"type": "RELATIVE",
31+
"path": "breakpad_init.cc"
32+
},
33+
"destination": {
34+
"path": "/breakpad_init.cc"
35+
}
36+
}
37+
]
38+
}

ydb/deploy/docker/Dockerfile

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# syntax=docker/dockerfile:1.4
2+
ARG BASE_IMAGE="cr.yandex/mirror/ubuntu"
3+
ARG BASE_IMAGE_TAG="focal"
4+
ARG BREAKPAD_IMAGE="cr.yandex/crp2lrlsrs36odlvd8dv/breakpad_init"
5+
ARG BREAKPAD_IMAGE_TAG="v2022.07.12"
6+
7+
###
8+
# Base image with required deb packages
9+
###
10+
FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} AS base
11+
RUN groupadd -r ydb && useradd --no-log-init -r -m -g ydb -G disk ydb && \
12+
apt-get -yqq update && \
13+
apt-get -yqq install --no-install-recommends libcap2-bin ca-certificates && \
14+
apt-get clean && rm -rf /var/lib/apt/lists/*
15+
16+
###
17+
# Base image with google brekpad assets
18+
###
19+
FROM ${BREAKPAD_IMAGE}:${BREAKPAD_IMAGE_TAG} AS breakpad_init
20+
FROM base AS base-breakpad
21+
RUN \
22+
apt-get -yqq update && \
23+
apt-get -yqq install --no-install-recommends binutils gdb strace linux-tools-generic \
24+
apt-get clean && rm -rf /var/lib/apt/lists/*
25+
ENV LD_PRELOAD=libbreakpad_init.so
26+
ENV BREAKPAD_MINIDUMPS_PATH=/opt/ydb/volumes/coredumps
27+
ENV BREAKPAD_MINIDUMPS_SCRIPT=/opt/ydb/bin/minidump_script.py
28+
# breakpad binaries
29+
COPY --chmod=4644 --from=breakpad_init /usr/lib/libbreakpad_init.so /usr/lib/libbreakpad_init.so
30+
COPY --chmod=0755 --from=breakpad_init /usr/bin/minidump_stackwalk /usr/bin/minidump_stackwalk
31+
COPY --chmod=0755 --from=breakpad_init /usr/bin/minidump-2-core /usr/bin/minidump-2-core
32+
# minidump callback script
33+
COPY --chmod=0755 --chown=ydb /minidump_script.py /opt/ydb/bin/minidump_script.py
34+
35+
###
36+
# Base image with debug packages
37+
###
38+
FROM base-breakpad AS base-debug
39+
RUN \
40+
apt-get -yqq update && \
41+
apt-get -yqq --no-install-recommends dnsutils telnet netcat-openbsd iputils-ping curl && \
42+
apt-get clean all && rm -rf /var/lib/apt/lists/*
43+
44+
FROM scratch AS license
45+
# release information
46+
COPY --chmod=0644 /AUTHORS /AUTHORS
47+
COPY --chmod=0644 /LICENSE /LICENSE
48+
COPY --chmod=0644 /README.md /README.md
49+
50+
FROM scratch AS dynamic-libs
51+
# dynamic libraries
52+
COPY --chmod=0644 /libiconv.so /lib/libiconv.so
53+
COPY --chmod=0644 /liblibidn-dynamic.so /lib/liblibidn-dynamic.so
54+
COPY --chmod=0644 /liblibaio-dynamic.so /lib/liblibaio-dynamic.so
55+
56+
FROM base AS ydb-binary
57+
COPY --chmod=0755 --chown=ydb /ydb /opt/ydb/bin/ydb
58+
59+
FROM base AS ydbd-setcap
60+
COPY --chmod=0755 --chown=ydb /ydbd /opt/ydb/bin/ydbd
61+
# workaround for decrease image size
62+
RUN /sbin/setcap CAP_SYS_RAWIO=ep /opt/ydb/bin/ydbd
63+
64+
###
65+
# Release image
66+
###
67+
FROM base AS release
68+
# release information
69+
COPY --link --from=license /AUTHORS /AUTHORS
70+
COPY --link --from=license /LICENSE /LICENSE
71+
COPY --link --from=license /README.md /README.md
72+
# dynamic libraries
73+
COPY --link --from=dynamic-libs /lib/libiconv.so /lib/libiconv.so
74+
COPY --link --from=dynamic-libs /lib/liblibidn-dynamic.so /lib/liblibidn-dynamic.so
75+
COPY --link --from=dynamic-libs /lib/liblibaio-dynamic.so /lib/liblibaio-dynamic.so
76+
# ydb binaries
77+
COPY --link --from=ydb-binary /opt/ydb/bin/ydb /opt/ydb/bin/ydb
78+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
79+
80+
WORKDIR /opt/ydb/bin
81+
USER ydb
82+
83+
###
84+
# Breakpad Image
85+
###
86+
FROM base-breakpad AS breakpad
87+
# release information
88+
COPY --link --from=license /AUTHORS /AUTHORS
89+
COPY --link --from=license /LICENSE /LICENSE
90+
COPY --link --from=license /README.md /README.md
91+
# dynamic libraries
92+
COPY --link --from=dynamic-libs /lib/libiconv.so /lib/libiconv.so
93+
COPY --link --from=dynamic-libs /lib/liblibidn-dynamic.so /lib/liblibidn-dynamic.so
94+
COPY --link --from=dynamic-libs /lib/liblibaio-dynamic.so /lib/liblibaio-dynamic.so
95+
# ydb binaries
96+
COPY --link --from=ydb-binary /opt/ydb/bin/ydb /opt/ydb/bin/ydb
97+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
98+
99+
WORKDIR /opt/ydb/bin
100+
USER ydb
101+
102+
###
103+
# Debug Image
104+
###
105+
FROM base-debug AS debug
106+
# release information
107+
COPY --link --from=license /AUTHORS /AUTHORS
108+
COPY --link --from=license /LICENSE /LICENSE
109+
COPY --link --from=license /README.md /README.md
110+
# dynamic libraries
111+
COPY --link --from=dynamic-libs /lib/libiconv.so /lib/libiconv.so
112+
COPY --link --from=dynamic-libs /lib/liblibidn-dynamic.so /lib/liblibidn-dynamic.so
113+
COPY --link --from=dynamic-libs /lib/liblibaio-dynamic.so /lib/liblibaio-dynamic.so
114+
# ydb binaries
115+
COPY --link --from=ydb-binary /opt/ydb/bin/ydb /opt/ydb/bin/ydb
116+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
117+
# debug symbols
118+
COPY --chmod=0644 --chown=ydb /ydbd.debug /opt/ydb/bin/ydbd.debug
119+
120+
WORKDIR /opt/ydb/bin
121+
USER ydb

ydb/deploy/docker/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Docker image
2+
3+
## Base image
4+
5+
Base layer is official `ubuntu:focal` docker image with packages:
6+
- libcap2-bin (for setcap to binaries)
7+
- ca-certificates (for working with CA bundle)
8+
9+
## Image Types
10+
11+
### Release
12+
13+
```bash
14+
ya package --docker ydb/deploy/docker/pkg.json
15+
```
16+
17+
Image with minimal requirements to launch ydbd in container.
18+
19+
The image includes:
20+
- dynamic cpp libraries (libiconv, libidn, libaio)
21+
- ydb cli binary
22+
- ydbd server strip'ed binary
23+
24+
25+
### Breakpad
26+
27+
```bash
28+
ya package --docker ydb/deploy/docker/breakpad/pkg.json
29+
```
30+
31+
Image with google breakpad assets to collect minidump instead of coredump.
32+
33+
Extend release image with:
34+
- additional packages to collect and manage minidump format
35+
- dynamic library `libbreakpad_init.so` from breakpad_init image (ydb/deploy/breakpad_init)
36+
- environment variable `LD_PRELOAD` to load library on process start
37+
- binaries `minidump_stackwalk` and `minidump-2-core` to collect stacktrace and convert to coredump format
38+
- python script `minidump_script.py` as dumpCallback handler for google breakpad
39+
- environment variables `BREAKPAD_MINIDUMPS_PATH` and `BREAKPAD_MINIDUMPS_SCRIPT` to setup breakpad
40+
41+
### Debug
42+
43+
```bash
44+
ya package --docker ydb/deploy/docker/debug/pkg.json
45+
```
46+
47+
Image with google breakpad assets to collect minidump instead of coredump.
48+
49+
Extend breakpad image with:
50+
- additional packages with debug utils (dnsutils, telnet, netcat-openbsd, iputils-ping, curl)
51+
- debug symbols for ydbd binary
52+
53+
## Additional Info
54+
55+
All types of images also included LICENSE and AUTHORS files from root of repository
56+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/python3.8
2+
3+
import json
4+
import subprocess
5+
import argparse
6+
import os
7+
8+
if __name__ == "__main__":
9+
parser = argparse.ArgumentParser(
10+
description="Minidump files processing"
11+
)
12+
parser.add_argument("succeeded", action="store")
13+
parser.add_argument("dmp_file", action="store")
14+
args = parser.parse_args()
15+
dmp_file = args.dmp_file
16+
core_file = args.dmp_file[:-3] + "core"
17+
json_file = args.dmp_file[:-3] + "json"
18+
succeeded = args.succeeded
19+
20+
if succeeded == "true":
21+
elf_cmd = ["readelf", "-n", "/opt/ydb/bin/ydbd"]
22+
svnrev_cmd = ["/opt/ydb/bin/ydbd", "--svnrevision"]
23+
mndmp_cmd = ["/usr/bin/minidump-2-core", "-v", dmp_file, "-o", core_file]
24+
gdb_cmd = [
25+
"/usr/bin/gdb",
26+
"/opt/ydb/bin/ydbd",
27+
core_file,
28+
"-iex=set auto-load safe-path /",
29+
"-ex=thread apply all bt",
30+
"--batch",
31+
"-q"
32+
]
33+
34+
elf_resp = subprocess.check_output(elf_cmd).decode("utf-8")
35+
svnrev_resp = subprocess.check_output(svnrev_cmd).decode("utf-8")
36+
subprocess.run(mndmp_cmd)
37+
gdb_resp = subprocess.check_output(gdb_cmd).decode("utf-8")
38+
os.remove(dmp_file)
39+
os.remove(core_file)
40+
41+
ret = json.dumps({"binary": "/opt/ydb/bin/ydbd", "readelf": elf_resp, "svnrevision": svnrev_resp, "stacktrace": gdb_resp})
42+
with open(json_file,"w") as out:
43+
out.write(ret)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"meta": {
3+
"name": "ydb",
4+
"maintainer": "ydb <ydb@yandex-team.ru>",
5+
"description": "Package with opensource YDB for Kubernetes with google breakpad support",
6+
"version": "breakpad-{branch}.{revision}"
7+
},
8+
"params": {
9+
"docker_build_network": "host",
10+
"docker_registry": "cr.yandex",
11+
"docker_repository": "crp2lrlsrs36odlvd8dv",
12+
"docker_target": "breakpad"
13+
},
14+
"include": [
15+
"ydb/deploy/docker/pkg.json"
16+
],
17+
"data": [
18+
{
19+
"source": {
20+
"type": "ARCADIA",
21+
"path": "ydb/deploy/docker/breakpad/minidump_script.py"
22+
},
23+
"destination": {
24+
"path": "/minidump_script.py"
25+
}
26+
}
27+
]
28+
}

ydb/deploy/docker/debug/pkg.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"meta": {
3+
"name": "ydb",
4+
"maintainer": "ydb <ydb@yandex-team.ru>",
5+
"description": "Package with opensource YDB for Kubernetes with debug symbols",
6+
"version": "dbg-{branch}.{revision}"
7+
},
8+
"params": {
9+
"docker_build_network": "host",
10+
"docker_registry": "cr.yandex",
11+
"docker_repository": "crp2lrlsrs36odlvd8dv",
12+
"docker_target": "debug"
13+
},
14+
"include": [
15+
"ydb/deploy/docker/minidump/pkg.json"
16+
],
17+
"data": []
18+
}

0 commit comments

Comments
 (0)