Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 42 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,61 @@
FROM fedora:25 as builder
FROM ubuntu:24.04 AS builder

# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#sort-multi-line-arguments
RUN dnf install -y \
autoconf \
automake \
boost-devel \
cmake \
dnf-plugins-core \
file \
gcc \
gcc-c++ \
git-core \
hostname \
libtool \
mariadb-devel-3:10.1.26-2.fc25.x86_64 \
mariadb-server-3:10.1.26-2.fc25.x86_64 \
rpm-build
SHELL [ "/bin/bash", "-c" ]

RUN dnf builddep -y \
mariadb
ARG NANOMSG_VERSION=1.2.1
ARG LZ4_VERSION=1.10.0

RUN useradd builder -u 1000 -m -G users,wheel && \
mkdir /home/builder/rpm && \
chown -R builder /home/builder
COPY <<EOF /etc/apt/sources.list.d/universe_src.sources
Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble-updates
Components: universe
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF

COPY --chown=builder:root ./docker/.rpmmacros /home/builder/.rpmmacros
COPY --chown=root:root ./docker/sudoers /etc/sudoers
RUN apt-get update && apt-get install -y \
apt-src \
ca-certificates \
libboost-dev \
git \
curl

USER builder
WORKDIR /home/builder
# USER ubuntu
WORKDIR /_src

RUN dnf download --source mariadb-10.1.26-2.fc25.src
RUN rpm -i mariadb*.rpm
RUN apt-get build-dep -y mariadb-server
RUN apt-get source -y mariadb-server && \
MARIADB_VERSION=$(apt-cache showsrc mariadb-server | grep '^Version:' | head -n1 | cut -d':' -f3 | cut -d '-' -f1) && \
mv mariadb-$MARIADB_VERSION mariadb

WORKDIR /home/builder/rpm
RUN rpmbuild --nocheck -bi mariadb.spec
# Download code dependencies
RUN git clone --branch master --single-branch --depth 1 https://github.com/anton-povarov/meow /_src/meow

USER root
WORKDIR /root
RUN curl -L https://github.com/nanomsg/nanomsg/archive/refs/tags/${NANOMSG_VERSION}.tar.gz | \
tar xvz -C /tmp && \
mv -v /tmp/nanomsg-${NANOMSG_VERSION} /_src/nanomsg

RUN curl -L https://github.com/lz4/lz4/archive/refs/tags/v${LZ4_VERSION}.tar.gz | \
tar xvz -C /tmp && \
mv -v /tmp/lz4-${LZ4_VERSION} /_src/lz4

# TODO: Create v1.0.0 release and use it instead
RUN git clone --branch master --single-branch --depth 1 https://github.com/anton-povarov/meow /_src/meow
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#using-pipes
# TODO: Set SHELL instead
RUN set -o pipefail && curl -L https://github.com/nanomsg/nanomsg/archive/1.1.5.tar.gz | tar xvz -C /tmp && mv -v /tmp/nanomsg-1.1.5 /_src/nanomsg
RUN set -o pipefail && curl -L https://github.com/lz4/lz4/archive/v1.9.1.tar.gz | tar xvz -C /tmp && mv -v /tmp/lz4-1.9.1 /_src/lz4
COPY . /_src/pinba2
RUN /_src/pinba2/docker/build-from-source.sh
RUN /_src/pinba2/docker/build-dependencies.sh
RUN /_src/pinba2/docker/build-pinba.sh

FROM fedora:25
MAINTAINER Anton Povarov "anton.povarov@gmail.com"
FROM ubuntu:24.04

RUN dnf install -y \
# libmariadb-dev-compat - for mysql_config
RUN apt-get update && apt-get install -y \
file \
hostname \
jemalloc \
mariadb-server-3:10.1.26-2.fc25.x86_64
libjemalloc2 \
libjemalloc-dev \
libmariadb-dev-compat \
mariadb-server

COPY --from=builder /_src/pinba2/mysql_engine/.libs/libpinba_engine2.so /usr/lib64/mysql/plugin/libpinba_engine2.so
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY --from=builder /_src/pinba2/mysql_engine/.libs/libpinba_engine2.so /usr/lib/mysql/plugin/

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
# TODO: Add bats based health check for exposed ports
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,20 @@ We've got some scripts to help [in scripts directory](scripts).
Convert mysqldump of your old tables to new format with [this script](scripts/convert_mysqldump.php).



More Info
Installation
--------

- [TODO](TODO.md)
- [Dockerfile](Dockerfile) based on Ubuntu 24.04 LTS\
something like: `docker build -t pinba2:latest .`
- [Building](docs/index.md#building) - use docker, really
- [Installing](docs/index.md#installation) - use docker, really
- [Configuration](docs/index.md#configuration) - optional, should run fine with default settings
- [User-defined reports + examples](#user-defined-reports)


Docker
------

### Fedora 25
More Info
--------
- [TODO](TODO.md)
- [User-defined reports + examples](#user-defined-reports)

[`Dockerfile`](Dockerfile)

Basics
------
Expand Down
36 changes: 21 additions & 15 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
AC_INIT([pinba], [2.6.0])
AC_INIT([pinba],[2.6.0])
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/globals.cpp])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AM_CONFIG_HEADER([auto_config.h])
AC_CONFIG_HEADERS([auto_config.h])
AX_PREFIX_CONFIG_H([pinba_config.h])
AX_CONFIG_NICE([config.nice])
AM_INIT_AUTOMAKE

${CFLAGS=""}
AC_PROG_CC
${CXXFLAGS=""}
AC_PROG_CXX

AC_PROG_LIBTOOL
LT_INIT
LIBTOOL="$LIBTOOL --preserve-dup-deps"
AC_SUBST(LIBTOOL)

AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_STDC

AC_CHECK_FUNCS(memcpy memmove)
AC_CHECK_TYPES([uint16_t]) # defined in C99 systems
AC_CHECK_TYPES([u_int16_t]) # defined in BSD-derived systems, and gnu
AC_CHECK_TYPES([long long]) # probably defined everywhere, but...
AC_CHECK_HEADERS(inttypes.h stdint.h unistd.h)
AC_PROG_SED
dnl AC_PROG_AWK

AC_CHECK_FUNCS([sysconf recvmmsg])

Expand All @@ -35,11 +33,20 @@ common_flags=" -pthread"
# common_flags="$common_flags -Wextra" # even worse
common_flags="$common_flags -Wformat -Wformat-security"
common_flags="$common_flags -Werror"
common_flags="$common_flags -Wno-nonnull" # strftime
common_flags="$common_flags -Wno-unused -Wno-unused-parameter -Wno-unused-variable -Wno-missing-field-initializers -Wno-parentheses"
common_flags="$common_flags -fno-omit-frame-pointer"
common_flags="$common_flags -fPIC -DPIC"
common_flags="$common_flags -D_GNU_SOURCE -D_POSIX_SOURCE"
common_flags="$common_flags -maes -msse4 -msse4.2"
common_flags="$common_flags -march=native"

case $host_cpu in
x86_64)
common_flags="$common_flags -maes -msse4 -msse4.2"
;;
*)
;;
esac

AX_CFLAGS="-std=gnu11 $common_flags"
AX_CXXFLAGS="-std=c++14 -fno-rtti $common_flags"
Expand Down Expand Up @@ -116,7 +123,7 @@ AC_MSG_CHECKING([if compiler supports -R])
AC_CACHE_VAL(pinba_cv_cc_dashr,[
SAVE_LIBS=$LIBS
LIBS="-R /usr/$LIBDIR $LIBS"
AC_TRY_LINK([], [], pinba_cv_cc_dashr=yes, pinba_cv_cc_dashr=no)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[pinba_cv_cc_dashr=yes],[pinba_cv_cc_dashr=no])
LIBS=$SAVE_LIBS])
AC_MSG_RESULT([$pinba_cv_cc_dashr])
if test $pinba_cv_cc_dashr = "yes"; then
Expand All @@ -126,7 +133,7 @@ else
AC_CACHE_VAL(pinba_cv_cc_rpath,[
SAVE_LIBS=$LIBS
LIBS="-Wl,-rpath,/usr/$LIBDIR $LIBS"
AC_TRY_LINK([], [], pinba_cv_cc_rpath=yes, pinba_cv_cc_rpath=no)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[pinba_cv_cc_rpath=yes],[pinba_cv_cc_rpath=no])
LIBS=$SAVE_LIBS])
AC_MSG_RESULT([$pinba_cv_cc_rpath])
if test $pinba_cv_cc_rpath = "yes"; then
Expand Down Expand Up @@ -193,7 +200,7 @@ else
CXXFLAGS="$MYSQL_INC"

AC_MSG_CHECKING([for MySQL version >= 5.1])
AC_TRY_RUN([
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdlib.h>
#include <stdio.h>
#include <mysql_version.h>
Expand All @@ -205,9 +212,7 @@ else
exit(1);
#endif
}
],
[ AC_MSG_RESULT([ok]) ],
[ AC_MSG_ERROR([MySQL 5.1+ is required])])
]])],[ AC_MSG_RESULT([ok]) ],[ AC_MSG_ERROR([MySQL 5.1+ is required])],[])

CFLAGS="$CFLAGS_old"
CXXFLAGS="$CXXFLAGS_old"
Expand Down Expand Up @@ -324,4 +329,5 @@ AC_SUBST(INSTALL_STRIP_FLAG)

AC_SUBST(EXPERIMENT_DIR)

AC_OUTPUT([Makefile src/Makefile include/Makefile mysql_engine/Makefile experiments/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile include/Makefile mysql_engine/Makefile experiments/Makefile])
AC_OUTPUT
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
version: '3.2'
services:

fedora-25:
image: badoo/pinba2:fedora-25
container_name: pinba2-fedora-25
pinba2:
image: pinba2
container_name: pinba2
build:
context: .
dockerfile: Dockerfile
21 changes: 9 additions & 12 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@

if [ $1 = "mysqld" ]; then

# fedora mysqld is in special location
ln -snf /usr/libexec/mysqld /usr/local/bin

# disable gss auth as it's not installed in this container
rm -rf /etc/my.cnf.d/auth_gssapi.cnf

# create default databases
# too expensive to perform on container startup really
mysql_install_db --rpm
chmod -R 777 /var/lib/mysql
# create dir where mysql.sock will be located
rundir=$(dirname `mysql_config --socket`)
mkdir -p $rundir
chmod 777 $rundir

# start mysql server in background for init process
"$@" --skip-networking -umysql &
"$@" --skip-networking -umysql --plugin-maturity=unknown &
pid="$!"

# legen.... wait for it
Expand Down Expand Up @@ -65,4 +59,7 @@ if [ $1 = "mysqld" ]; then
fi
fi

exec "$@" -umysql
exec "$@" -umysql \
--port=3306 \
--socket=`mysql_config --socket` \
--plugin-maturity=unknown
40 changes: 40 additions & 0 deletions docker/build-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash -xe

# mariadb
# the annoying part - why we're building mariadb from source at all,
# is that we need internal headers that are not present in regular apt packages
# so the idea here is to avoid building the whole of mariadb, but only the parts we need
# we only need to run initial generation stage with cmake . and build a few libs quickly
# the final tricky part is to build with the same compiler flags as the server itself
# for now - there is no problem, unless mariadb is built with debug, in which case pinba should be configured with --enable-debug
cd /_src/mariadb
cmake .
make -C libservices
# boost tries to include this file globally and includes this one; but mariadb needs this to install
# mv+rm is a workaround for docker build-ing on macos case-insensitive fs
# VERSION and version are the same file and mv actually leads to both files existing at the same time
# so rm it to avoid the issue with boost described above
mv VERSION VERSION.backup
rm -f VERSION
# make mysqld_error.h available in non-esoteric location
ln -snf /_src/mariadb/libmariadb/include/mysqld_error.h include/mysqld_error.h


# build nanomsg and install (this one is a lil tricky to build statically)
cd /_src/nanomsg
cmake \
-DNN_STATIC_LIB=ON \
-DNN_ENABLE_DOC=OFF \
-DNN_MAX_SOCKETS=4096 \
-DCMAKE_C_FLAGS="-fPIC -DPIC" \
-DCMAKE_INSTALL_PREFIX=/_install/nanomsg \
-DCMAKE_INSTALL_LIBDIR=lib \
.

make -j4
make install

# build lz4 with PIC static lib
cd /_src/lz4
make CFLAGS="-fPIC -DPIC"
make install PREFIX=/_install/lz4
36 changes: 0 additions & 36 deletions docker/build-from-source.sh

This file was deleted.

14 changes: 14 additions & 0 deletions docker/build-pinba.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -xe

# Run this after build-dependencies.sh
# pinba
cd /_src/pinba2
./buildconf.sh
./configure --prefix=/_install/pinba2 \
--with-boost=/usr \
--with-mysql=/_src/mariadb \
--with-meow=/_src/meow \
--with-nanomsg=/_install/nanomsg \
--with-lz4=/_install/lz4 \
--enable-libmysqlservices
make -j4
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Building

**examples**

See [Dockerfile](../Dockerfile) and [build-from-source.sh](../docker/build-from-source.sh).<br/>
See [Dockerfile](../Dockerfile), [build-dependencies.sh](../docker/build-dependencies.sh) and [build-pinba.sh](../docker/build-pinba.sh).<br/>
Also there is a rough guide for centos7 in [#17](https://github.com/badoo/pinba2/issues/17) - should be workable for multiple distros really.

**requirements**
Expand Down
Loading