Skip to content

Commit db5d438

Browse files
authored
Dockerfile oss (cherry-pick to stable 24-3) (#11633)
1 parent 31b8d00 commit db5d438

File tree

12 files changed

+743
-3
lines changed

12 files changed

+743
-3
lines changed

ydb/deploy/breakpad_init/Dockerfile

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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# syntax=docker/dockerfile:1.4
2+
ARG BASE_IMAGE="cr.yandex/mirror/ubuntu"
3+
ARG BASE_IMAGE_TAG="focal"
4+
ARG BREAKPAD_INIT_IMAGE="cr.yandex/crp2lrlsrs36odlvd8dv/breakpad_init"
5+
ARG BREAKPAD_INIT_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+
# release information
16+
COPY --chmod=0644 /AUTHORS /AUTHORS
17+
COPY --chmod=0644 /LICENSE /LICENSE
18+
COPY --chmod=0644 /README.md /README.md
19+
# dynamic libraries
20+
COPY --chmod=0644 /libiconv.so /lib/libiconv.so
21+
COPY --chmod=0644 /liblibidn-dynamic.so /lib/liblibidn-dynamic.so
22+
COPY --chmod=0644 /liblibaio-dynamic.so /lib/liblibaio-dynamic.so
23+
24+
###
25+
# Base image with google brekpad assets
26+
###
27+
FROM ${BREAKPAD_INIT_IMAGE}:${BREAKPAD_INIT_IMAGE_TAG} AS breakpad_init
28+
FROM base AS base-breakpad
29+
RUN \
30+
apt-get -yqq update && \
31+
apt-get -yqq install --no-install-recommends binutils gdb strace linux-tools-generic && \
32+
apt-get clean && rm -rf /var/lib/apt/lists/*
33+
ENV LD_PRELOAD=libbreakpad_init.so
34+
ENV BREAKPAD_MINIDUMPS_PATH=/opt/ydb/volumes/coredumps
35+
ENV BREAKPAD_MINIDUMPS_SCRIPT=/opt/ydb/bin/minidump_script.py
36+
# breakpad binaries
37+
COPY --chmod=4644 --from=breakpad_init /usr/lib/libbreakpad_init.so /usr/lib/libbreakpad_init.so
38+
COPY --chmod=0755 --from=breakpad_init /usr/bin/minidump_stackwalk /usr/bin/minidump_stackwalk
39+
COPY --chmod=0755 --from=breakpad_init /usr/bin/minidump-2-core /usr/bin/minidump-2-core
40+
# minidump callback script
41+
COPY --chmod=0755 --chown=ydb /minidump_script.py /opt/ydb/bin/minidump_script.py
42+
43+
FROM base AS ydbd-setcap
44+
COPY --chmod=0755 --chown=ydb /ydbd /opt/ydb/bin/ydbd
45+
# workaround for decrease image size
46+
RUN /sbin/setcap CAP_SYS_RAWIO=ep /opt/ydb/bin/ydbd
47+
48+
###
49+
# Release image
50+
###
51+
FROM base AS release
52+
# ydb binaries
53+
COPY --chmod=0755 --chown=ydb /ydb /opt/ydb/bin/ydb
54+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
55+
WORKDIR /opt/ydb/bin
56+
USER ydb
57+
58+
###
59+
# Breakpad Image
60+
###
61+
FROM base-breakpad AS breakpad
62+
# ydb binaries
63+
COPY --chmod=0755 --chown=ydb /ydb /opt/ydb/bin/ydb
64+
COPY --link --from=ydbd-setcap /opt/ydb/bin/ydbd /opt/ydb/bin/ydbd
65+
WORKDIR /opt/ydb/bin
66+
USER ydb
67+
68+
###
69+
# Debug Image
70+
###
71+
FROM breakpad AS debug
72+
USER root
73+
RUN \
74+
apt-get -yqq update && \
75+
apt-get -yqq install --no-install-recommends dnsutils telnet netcat-openbsd iputils-ping curl && \
76+
apt-get clean && rm -rf /var/lib/apt/lists/*
77+
# debug symbols
78+
COPY --chmod=0644 --chown=ydb /ydbd.debug /opt/ydb/bin/ydbd.debug
79+
USER ydb

ydb/deploy/docker/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Docker image
2+
3+
## Base image
4+
5+
Base image is official `ubuntu:focal` with installed packages:
6+
- libcap2-bin (for setcap to binaries)
7+
- ca-certificates (for working with CA bundle)
8+
9+
Also base image included `LICENSE`, `AUTHORS` and `README.md` files from root of repository
10+
and dynamic cpp libraries `libiconv`, `liblibidn` and `libaio`.
11+
12+
### Base breakpad image
13+
14+
Extend base image with:
15+
- additional packages to collect and manage minidump format (binutils, gdb, strace, linux-tools-generic)
16+
- dynamic library `libbreakpad_init.so` from breakpad_init image (ydb/deploy/breakpad_init)
17+
- environment variable `LD_PRELOAD` for loading breakpad library on process start
18+
- environment variables `BREAKPAD_MINIDUMPS_PATH` and `BREAKPAD_MINIDUMPS_SCRIPT` to setup breakpad
19+
- binaries `minidump_stackwalk` and `minidump-2-core` to collect stacktrace and convert in coredump format
20+
- python script `minidump_script.py` as dumpCallback handler for breakpad
21+
22+
## Image Types
23+
24+
### Release
25+
26+
Image with minimal requirements to launch ydbd in container
27+
28+
```bash
29+
ya package --docker ydb/deploy/docker/release/pkg.json
30+
```
31+
32+
Used base image and included:
33+
- ydb cli binary
34+
- ydbd server strip'ed binary baked with build type `Release`
35+
36+
### Breakpad
37+
38+
Image with google breakpad assets to collect minidump
39+
40+
```bash
41+
ya package --docker ydb/deploy/docker/breakpad/pkg.json
42+
```
43+
44+
Used base breakpad image and included:
45+
46+
- ydb cli binary
47+
- ydbd server binary baked with build flag `DEBUGINFO_LINES_ONLY`
48+
49+
### Debug
50+
51+
Image with debug symbols and utils for dev purposes
52+
53+
```bash
54+
ya package --docker ydb/deploy/docker/debug/pkg.json
55+
```
56+
57+
Used base breakpad image and included:
58+
- additional packages with debug utils (dnsutils, telnet, netcat-openbsd, iputils-ping, curl)
59+
- ydb cli binary
60+
- ydbd server strip'ed binary baked with build type `Release`
61+
- debug symbols for ydbd binary
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)

0 commit comments

Comments
 (0)