Open6

DockerでMariaDBのソースコードをビルドして実行する

tommy34tommy34

Dockerfile

FROM ubuntu:24.04

ENV TZ=Asia/Tokyo
ENV PATH=$PATH:/usr/local/mysql/bin
ENV VERSION=11.4.1

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone && \
  sed -i 's@archive.ubuntu.com@ftp.jaist.ac.jp/pub/Linux@g' /etc/apt/sources.list && \
  echo "bind 'set bell-style none'" >> .bashrc && \
  apt-get update && \
  apt-get install --no-install-recommends -y git build-essential wget cmake \
    ca-certificates libncurses5-dev gnutls-dev bison zlib1g-dev cloc && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* && \
  git clone --recursive --depth=1 -b mariadb-${VERSION} https://github.com/MariaDB/server && \
  mkdir server/build /var/lib/mysql

WORKDIR /server/build

RUN cmake .. && make -j$(nproc) && make install
tommy34tommy34
$ docker --version
Docker version 24.0.6, build ed223bc
$ uname -a
Linux MyComputer 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
tommy34tommy34

コンテナのビルド

$ docker build -t mariadb .
[+] Building 2203.8s (8/8) FINISHED                                           docker:default
 => [internal] load .dockerignore                                                       1.3s
 => => transferring context: 2B                                                         0.0s
 => [internal] load build definition from Dockerfile                                    1.9s
 => => transferring dockerfile: 792B                                                    0.3s
 => [internal] load metadata for docker.io/library/ubuntu:24.04                         0.0s
 => CACHED [1/4] FROM docker.io/library/ubuntu:24.04                                    0.0s
 => [2/4] RUN ln -snf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && echo Asia/To  1395.8s
 => [3/4] WORKDIR /server/build                                                         2.1s
 => [4/4] RUN cmake .. && make -j$(nproc) && make install                             774.5s
 => exporting to image                                                                 26.8s
 => => exporting layers                                                                26.5s
 => => writing image sha256:13ef66c02a9843468fac2e5afa58115363a749104c1081f1fb6669849b  0.1s
 => => naming to docker.io/library/mariadb                                              0.2s

What's Next?
  View summary of image vulnerabilities and recommendations → docker scout quickview
tommy34tommy34
$ docker run -it --rm --name mariadb_container mariadb bash
root@1f61bd55bc67:/server/build# ./scripts/mariadb-install-db --srcdir=.. --datadir=/var/lib/mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK
root@1f61bd55bc67:/server/build# mariadbd --version
mariadbd  Ver 11.4.1-MariaDB for Linux on x86_64 (Source distribution)
root@1f61bd55bc67:/server/build# mariadbd --help
mariadbd  Ver 11.4.1-MariaDB for Linux on x86_64 (Source distribution)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: mariadbd [OPTIONS]

For more help options (several pages), use mysqld --verbose --help.
root@1f61bd55bc67:/server/build# mariadbd --user=root --datadir=/var/lib/mysql &
[1] 55
root@1f61bd55bc67:/server/build# 2024-02-24  5:31:28 0 [Note] Starting MariaDB 11.4.1-MariaDB source revision fa69b085b10f19a3a8b6e7adab27c104924333ae as process 55
2024-02-24  5:31:29 0 [Note] InnoDB: Compressed tables use zlib 1.3
2024-02-24  5:31:29 0 [Note] InnoDB: Using transactional memory
2024-02-24  5:31:29 0 [Note] InnoDB: Number of transaction pools: 1
2024-02-24  5:31:29 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2024-02-24  5:31:29 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
2024-02-24  5:31:29 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
2024-02-24  5:31:29 0 [Note] InnoDB: Completed initialization of buffer pool
2024-02-24  5:31:29 0 [Note] InnoDB: Buffered log writes (block size=512 bytes)
2024-02-24  5:31:29 0 [Note] InnoDB: End of log at LSN=47629
2024-02-24  5:31:29 0 [Note] InnoDB: Opened 3 undo tablespaces
2024-02-24  5:31:29 0 [Note] InnoDB: 128 rollback segments in 3 undo tablespaces are active.
2024-02-24  5:31:29 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
2024-02-24  5:31:29 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
2024-02-24  5:31:29 0 [Note] InnoDB: log sequence number 47629; transaction id 14
2024-02-24  5:31:29 0 [Note] Plugin 'FEEDBACK' is disabled.
2024-02-24  5:31:29 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-02-24  5:31:29 0 [Note] Plugin 'wsrep-provider' is disabled.
2024-02-24  5:31:29 0 [Note] InnoDB: Buffer pool(s) load completed at 240224  5:31:29
2024-02-24  5:31:30 0 [Note] Server socket created on IP: '0.0.0.0'.
2024-02-24  5:31:30 0 [Note] Server socket created on IP: '::'.
2024-02-24  5:31:30 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
2024-02-24  5:31:30 0 [Note] mariadbd: ready for connections.
Version: '11.4.1-MariaDB'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution

root@1f61bd55bc67:/server/build# 
root@1f61bd55bc67:/server/build# ps aufx
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   4584  3828 pts/0    Ss   05:29   0:00 bash
root        55  0.6  1.2 1332784 211208 pts/0  Sl   05:31   0:00 mariadbd --user=root --datadir=/var/lib/mysql
root        77  0.0  0.0   7832  3840 pts/0    R+   05:33   0:00 ps aufx
root@1f61bd55bc67:/server/build# mariadb -u root -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 11.4.1-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> \h

General information about MariaDB can be found at
http://mariadb.org

List of all client commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to MariaDB server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to MariaDB server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
costs     (\Q) Toggle showing query costs after each query
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

MariaDB [(none)]>
tommy34tommy34

ソースコードの行数は約503万行

root@1f61bd55bc67:/server# cloc --exclude-dir=build .
   38940 text files.
   10263 unique files.
   27802 files ignored.

github.com/AlDanial/cloc v 1.98  T=36.14 s (283.9 files/s, 180795.9 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
C                                     1399         180687         232726        2067969
C++                                   2232         273838         294293        1389010
C/C++ Header                          2961         111050         238640         486466
Assembly                                29            415          34059         290681
Text                                   200           3730              0         233041
XML                                    289           1755            532         103534
XMI                                      6             63              0          77276
Bourne Shell                           389           8518           8570          47148
Perl                                   182          11489          10799          45548
Pascal                                 169           6546           7665          38736
Java                                   281           6799          17502          33919
JSON                                    25              7              0          31258
CMake                                  406           4466           6342          26028
Markdown                               236           7383             58          24309
SQL                                    338           2184           5987          17011
Python                                 104           3179           3794          16917
m4                                      63           1910             91          15619
SWIG                                    33           1302           2592          10508
make                                   298           1861           1213          10143
Ruby                                    88           1013            297           8556
Bourne Again Shell                      49           1035           1179           6413
Puppet                                  11              0              4           6176
CSV                                     15              7              0           5032
YAML                                    52            331            473           3708
MSBuild script                          19              0             63           3091
C#                                      20            592            928           2864
CSS                                      6            591            180           2864
yacc                                     4            426            198           2778
HTML                                    61            139             23           2453
SCSS                                    16            289             66           1721
reStructuredText                        38           1204            748           1637
Windows Module Definition               60             46             30           1505
Ada                                     12            349            596           1491
PO File                                 23            230            881           1420
Visual Studio Solution                  25             25             25           1415
R                                        1             50              0           1059
JavaScript                               6            135            119           1037
ReScript                                 6            126              0            954
lex                                      5            291            171            857
INI                                     20             98              0            672
SVG                                      6              0              2            664
diff                                     4              2             17            644
Linker Script                            5             81             53            616
Freemarker Template                      1             83              0            544
Windows Resource File                    9             96             90            423
PowerShell                               2             91            101            353
DOS Batch                               11             72             72            334
dtrace                                   9             59            179            306
Maven                                    2             18              5            265
Arduino Sketch                           2             45             57            253
TeX                                      1             12             11            125
Thrift                                   1             19             13            107
Elixir                                   1             46            131            101
Lua                                      3             15              2             90
Visual Basic                             6              0              0             88
Dockerfile                               7             27             15             74
Tcl/Tk                                   2             10             19             73
Objective-C                              3             35             70             63
PHP                                      2             12              2             52
awk                                      2              4              7             46
Starlark                                 1              5              4             33
SAS                                      1             14             22             32
Swift                                    2              9             41             29
IDL                                      1              3              0             10
Windows Message File                     1              1              8              6
D                                        1              4             11              4
---------------------------------------------------------------------------------------
SUM:                                 10263         634922         871776        5028159
---------------------------------------------------------------------------------------
root@1f61bd55bc67:/server#