|
1 | | -# syntax = docker/dockerfile:experimental |
| 1 | +# syntax = docker/dockerfile:1.3-labs |
2 | 2 |
|
3 | 3 | # Base PostgreSQL debug image, where we compile and install it from source with |
4 | 4 | # full debugging capabilities. For more details see: |
|
15 | 15 | FROM postgres:12.3 |
16 | 16 |
|
17 | 17 | # Compile and install PG in debug mode |
| 18 | + |
| 19 | +ARG use_valgrind |
18 | 20 | RUN rm -rf /usr/lib/postgresql/12/* && \ |
19 | 21 | apt-get update -qq && \ |
20 | 22 | apt-get install -y --allow-downgrades \ |
21 | 23 | build-essential \ |
| 24 | + curl \ |
22 | 25 | wget \ |
23 | 26 | git \ |
| 27 | + vim \ |
24 | 28 | libssl-dev \ |
25 | 29 | libsasl2-dev \ |
26 | 30 | pkgconf \ |
@@ -51,12 +55,55 @@ RUN rm -rf /usr/lib/postgresql/12/* && \ |
51 | 55 | libxml2-dbg \ |
52 | 56 | zlib1g-dbg \ |
53 | 57 | zlib1g \ |
54 | | - zlib1g-dev && \ |
| 58 | + zlib1g-dev \ |
| 59 | + xsltproc \ |
| 60 | + libxml2-utils && \ |
55 | 61 | rm -rf /var/lib/apt/lists/* && \ |
56 | | - git clone https://github.com/postgres/postgres.git && \ |
| 62 | + # pgprint command for GDB |
| 63 | + git clone https://github.com/tvesely/gdbpg.git && \ |
| 64 | + # Download PG source |
| 65 | + git clone -b REL_12_STABLE https://github.com/postgres/postgres.git && \ |
| 66 | + # Download Valgrind source, compile and install |
| 67 | + test -z "${use_valgrind}" || (\ |
| 68 | + # Make a switcheroo in the image entrypoint, so that instead of starting plain |
| 69 | + # postgres we start it under Valgrind |
| 70 | + sed -i -e 's/"$BASH_SOURCE"/"$BASH_SOURCE" valgrind --leak-check=full --show-leak-kinds=definite,indirect \ |
| 71 | +--num-callers=25 --log-file=\/pg-valgrind\/valgrind-%p.log --trace-children=yes \ |
| 72 | +--gen-suppressions=all --suppressions=postgres\/src\/tools\/valgrind.supp \ |
| 73 | +--suppressions=valgrind-python.supp --verbose --time-stamp=yes \ |
| 74 | +--error-markers=VALGRINDERROR-BEGIN,VALGRINDERROR-END/' /usr/local/bin/docker-entrypoint.sh && \ |
| 75 | + # Configure PG with Valgrind support |
| 76 | + sed -i -e 's=/\*\s#define\sUSE_VALGRIND\s\*/=#define USE_VALGRIND=' postgres/src/include/pg_config_manual.h && \ |
| 77 | + # Download Python Valgrind suppressions and make folder for output files |
| 78 | + curl https://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp --output valgrind-python.supp && \ |
| 79 | + mkdir -p /pg-valgrind && sudo chmod a+w /pg-valgrind && \ |
| 80 | + # Build Valgrind |
| 81 | + curl https://sourceware.org/pub/valgrind/valgrind-3.18.1.tar.bz2 --output valgrind-3.18.1.tar.bz2 && \ |
| 82 | + tar xf valgrind-3.18.1.tar.bz2 && \ |
| 83 | + cd valgrind-3.18.1 && \ |
| 84 | + ./configure && \ |
| 85 | + make && \ |
| 86 | + make install && \ |
| 87 | + cd ..) && \ |
| 88 | + # Compile and install PG from source |
57 | 89 | cd /postgres && \ |
58 | | - git checkout REL_12_STABLE && \ |
59 | 90 | mkdir -p /usr/lib/postgresql/12 && \ |
60 | | - ./configure --enable-cassert --enable-debug CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" -prefix=/usr/lib/postgresql/12 && \ |
| 91 | + ./configure \ |
| 92 | + --enable-cassert \ |
| 93 | + --enable-debug \ |
| 94 | + CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" \ |
| 95 | + -prefix=/usr/lib/postgresql/12 && \ |
61 | 96 | make && \ |
62 | 97 | make install |
| 98 | + # Extensions are not installed automatically; install extensions so that |
| 99 | + # we can step through them in GDB (but otherwise they work fine without this). |
| 100 | + # cd contrib && \ |
| 101 | + # make all && \ |
| 102 | + # make install |
| 103 | + |
| 104 | +# Configure GDB: enable pgprint, disable confirmation and dynamic load prompt |
| 105 | +COPY <<EOF /etc/gdb/gdbinit |
| 106 | +source /gdbpg/gdbpg.py |
| 107 | +set confirm off |
| 108 | +set breakpoint pending on |
| 109 | +EOF |
0 commit comments