Skip to content

Commit 38d6a0b

Browse files
authored
Merge 7e5b6ca into 7b9c7e3
2 parents 7b9c7e3 + 7e5b6ca commit 38d6a0b

File tree

12 files changed

+433
-143
lines changed

12 files changed

+433
-143
lines changed

ydb/deploy/docker/Dockerfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# syntax=docker/dockerfile:1.4
2+
ARG BREAKPAD_IMAGE_TAG=v2022.07.12
3+
###
4+
# Base image with required deb packages
5+
###
6+
FROM cr.yandex/mirror/ubuntu:focal AS base
7+
RUN \
8+
apt-get -yqq update && \
9+
apt-get -yqq install libcap2-bin ca-certificates && \
10+
apt-get -yqq clean all && \
11+
rm -rf /var/lib/apt/lists/* && \
12+
groupadd -r ydb && \
13+
useradd --no-log-init -r -m -g ydb -G disk ydb
14+
15+
FROM base AS base-debug
16+
RUN \
17+
apt-get -yqq update && \
18+
apt-get -yqq install binutils dnsutils telnet netcat-openbsd iputils-ping gdb atop strace curl linux-tools-generic && \
19+
apt-get -yqq clean all && \
20+
rm -rf /var/lib/apt/lists/*
21+
22+
FROM scratch AS license
23+
# release information
24+
COPY --chmod=0644 /AUTHORS /AUTHORS
25+
COPY --chmod=0644 /LICENSE /LICENSE
26+
COPY --chmod=0644 /README.md /README.md
27+
28+
FROM scratch AS libs
29+
# dynamic libraries
30+
COPY --chmod=0644 /libiconv.so /lib/libiconv.so
31+
COPY --chmod=0644 /liblibidn-dynamic.so /lib/liblibidn-dynamic.so
32+
COPY --chmod=0644 /liblibaio-dynamic.so /lib/liblibaio-dynamic.so
33+
34+
FROM base AS ydb-binary
35+
# dynamic libraries
36+
COPY --chmod=0755 --chown=ydb /ydb /opt/ydb/bin/ydb
37+
38+
###
39+
# Image with setcap'ed ydb binary
40+
###
41+
FROM base AS ydbd-setcap
42+
COPY --chmod=0755 --chown=ydb /ydbd /opt/ydb/bin/ydbd
43+
# workaround for decrease image size
44+
RUN /sbin/setcap CAP_SYS_RAWIO=ep /opt/ydb/bin/ydbd
45+
46+
###
47+
# Release image
48+
###
49+
FROM base AS release
50+
# release information
51+
COPY --link --from=license /AUTHORS /AUTHORS
52+
COPY --link --from=license /LICENSE /LICENSE
53+
COPY --link --from=license /README.md /README.md
54+
# dynamic libraries
55+
COPY --link --from=libs /lib/libiconv.so /lib/libiconv.so
56+
COPY --link --from=libs /lib/liblibidn-dynamic.so /lib/liblibidn-dynamic.so
57+
COPY --link --from=libs /lib/liblibaio-dynamic.so /lib/liblibaio-dynamic.so
58+
# ydb binaries
59+
COPY --link --from=ydb-binary /opt/ydb/bin/ydb /opt/ydb/bin/ydb
60+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
61+
62+
WORKDIR /opt/ydb/bin
63+
USER ydb
64+
65+
###
66+
# Breakpad image
67+
###
68+
FROM cr.yandex/crp2lrlsrs36odlvd8dv/breakpad_init:$BREAKPAD_IMAGE_TAG AS breakpad
69+
70+
###
71+
# Debug image with additional packages
72+
###
73+
FROM base-debug AS debug
74+
# release information
75+
COPY --link --from=license /AUTHORS /AUTHORS
76+
COPY --link --from=license /LICENSE /LICENSE
77+
COPY --link --from=license /README.md /README.md
78+
# dynamic libraries
79+
COPY --link --from=libs /lib/libiconv.so /lib/libiconv.so
80+
COPY --link --from=libs /lib/liblibidn-dynamic.so /lib/liblibidn-dynamic.so
81+
COPY --link --from=libs /lib/liblibaio-dynamic.so /lib/liblibaio-dynamic.so
82+
# breakpad section
83+
ENV LD_PRELOAD=libbreakpad_init.so
84+
ENV BREAKPAD_MINIDUMPS_PATH=/opt/ydb/volumes/coredumps
85+
ENV BREAKPAD_MINIDUMPS_SCRIPT=/opt/ydb/bin/minidump_script.py
86+
COPY --chmod=4644 --link --from=breakpad /usr/lib/libbreakpad_init.so /usr/lib/libbreakpad_init.so
87+
COPY --chmod=0755 --link --from=breakpad /usr/bin/minidump_stackwalk /usr/bin/minidump_stackwalk
88+
COPY --chmod=0755 --link --from=breakpad /usr/bin/minidump-2-core /usr/bin/minidump-2-core
89+
# minidump script
90+
COPY --chmod=0755 --chown=ydb /minidump_script.py /opt/ydb/bin/minidump_script.py
91+
# ydb binaries
92+
COPY --link --from=ydb-binary /opt/ydb/bin/ydb /opt/ydb/bin/ydb
93+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
94+
# ydbd debug symbols
95+
COPY --chmod=0644 --chown=ydb /ydbd.debug /opt/ydb/bin/ydbd.debug
96+
97+
WORKDIR /opt/ydb/bin
98+
USER ydb
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+
FROM cr.yandex/mirror/ubuntu:focal AS breakpad-base
3+
RUN \
4+
apt-get -yqq update && \
5+
apt-get -yqq install git build-essential libz-dev python3 curl && \
6+
apt-get -yqq clean all && \
7+
rm -rf /var/lib/apt/lists/*
8+
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
9+
ENV PATH="/depot_tools:${PATH}"
10+
11+
ARG BREAKPAD_GIT_TAG="v2022.07.12"
12+
FROM breakpad-base AS breakpad-build
13+
COPY --link breakpad_init.cc /breakpad/breakpad_init.cc
14+
RUN \
15+
cd breakpad && \
16+
fetch breakpad && \
17+
cd src && \
18+
git checkout -- . && git checkout tags/${BREAKPAD_GIT_TAG} && \
19+
./configure && make && \
20+
g++ -std=c++11 -shared -Wall -o ../libbreakpad_init.so -fPIC ../breakpad_init.cc -Isrc/ -Lsrc/client/linux/ -lbreakpad_client -lpthread
21+
22+
FROM scratch AS breakpad-release
23+
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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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_build_arg": {
14+
"BREAKPAD_GIT_TAG": "v2022.07.12"
15+
}
16+
},
17+
"data": [
18+
{
19+
"source": {
20+
"type": "RELATIVE",
21+
"path": "Dockerfile"
22+
},
23+
"destination": {
24+
"path": "/Dockerfile"
25+
}
26+
},
27+
{
28+
"source": {
29+
"type": "RELATIVE",
30+
"path": "breakpad_init.cc"
31+
},
32+
"destination": {
33+
"path": "/breakpad_init.cc"
34+
}
35+
}
36+
]
37+
}
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)

ydb/deploy/docker/debug/pkg.json

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 debug",
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/pkg.json"
16+
],
17+
"data": [
18+
{
19+
"source": {
20+
"type": "RELATIVE",
21+
"path": "minidump_script.py"
22+
},
23+
"destination": {
24+
"path": "/minidump_script.py"
25+
}
26+
}
27+
]
28+
}

0 commit comments

Comments
 (0)