Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mysql 8.0.40 #268

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
100 changes: 100 additions & 0 deletions library/mysql/8.0.40/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Stage 1: Build MySQL
FROM cr.loongnix.cn/loongson/loongnix-server:8.4 AS builder

# 安装构建所需的依赖
RUN yum install -y wget gnupg2 patch bzip2 openssl xz zstd rpm

# 复制 MySQL 源代码和补丁文件
#COPY mysql-boost-8.0.40.tar.gz /tmp
RUN wget https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-8.0.40.tar.gz -O /tmp/mysql-boost-8.0.40.tar.gz
COPY no_check_abi.patch /tmp
COPY build_and_install_mysql.sh /tmp
COPY epel-modular.repo /etc/yum.repos.d/
COPY epel.repo /etc/yum.repos.d/

RUN sed -i 's/^enabled=0/enabled=1/' /etc/yum.repos.d/Loongnix-PowerTools.repo;
# 解压并构建 MySQL
RUN cd /tmp && \
tar -xf mysql-boost-8.0.40.tar.gz && \
patch -p1 /tmp/mysql-8.0.40/CMakeLists.txt < /tmp/no_check_abi.patch && \
bash /tmp/build_and_install_mysql.sh && \
rm -rf /tmp/mysql-boost-8.0.40 /tmp/mysql-8.0.40 /tmp/mysql-boost-8.0.40.tar.gz /tmp/no_check_abi.patch /tmp/build_and_install_mysql.sh

# Stage 2: 运行时镜像
FROM cr.loongnix.cn/loongson/loongnix-server:8.4

# 安装运行时依赖
RUN yum install -y python38-devel libssh wget tar glibc-common && \
yum clean all && \
rm -rf /var/cache/yum

# 从构建阶段复制 MySQL 到运行时镜像
COPY --from=builder /usr/local/mysql /usr/local/mysql
COPY --from=builder /etc/my.cnf /etc/my.cnf
COPY --from=builder /etc/my.cnf.d /etc/my.cnf.d
COPY --from=builder /etc/logrotate.d/mysql /etc/logrotate.d/mysql

# 从构建阶段拷贝共享库文件
COPY --from=builder /lib64 /lib64
COPY --from=builder /usr/lib64 /usr/lib64

# 安装 MySQL Shell
RUN wget https://github.com/Loongson-Cloud-Community/mysql-shell-rpm/releases/download/v8.0.30/mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
tar -xf mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
rpm -ivh --nodeps mysql-shell-8.0.30-LA-RPMS-mininal/loongarch64/*.rpm && \
rm -rf mysql-shell-8.0.30-LA-RPMS-mininal mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
wget -O /usr/local/bin/gosu "https://github.com/Loongson-Cloud-Community/gosu/releases/download/loongson-1.14/gosu-loongarch64" && \
chmod +x /usr/local/bin/gosu && \
gosu --version && \
gosu nobody true;

# 设置 MySQL 配置文件
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s /usr/local/bin/docker-entrypoint.sh /entrypoint.sh

RUN set -eux; \
groupadd --system --gid 1000 mysql; \
useradd --system --uid 1000 --gid 1000 --home-dir /var/lib/mysql --no-create-home mysql
# 设置环境变量和路径
ENV MYSQL_MAJOR 8.0
ENV MYSQL_VERSION 8.0.40-1loongnixserver8.4
ENV PATH=/usr/local/mysql/sbin:/usr/local/mysql/bin:$PATH

RUN set -eux; \
# make sure users dumping files in "/etc/mysql/conf.d" still works
! grep -F '!includedir' /etc/my.cnf; \
{ echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; \
mkdir -p /etc/mysql/conf.d; \
# 5.7 Debian-based images also included "/etc/mysql/mysql.conf.d" so let's include it too
{ echo '!includedir /etc/mysql/mysql.conf.d/'; } >> /etc/my.cnf; \
mkdir -p /etc/mysql/mysql.conf.d; \
\
# comment out a few problematic configuration values
find /etc/my.cnf /etc/mysql/ -name '*.cnf' -print0 \
| xargs -0 grep -lZE '^(bind-address|log)' \
| xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'; \
\
# ensure these directories exist and have useful permissions
# the rpm package has different opinions on the mode of `/var/run/mysqld`, so this needs to be after install
mkdir -p /var/lib/mysql /var/run/mysqld; \
chown mysql:mysql /var/lib/mysql /var/run/mysqld; \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
chmod 1777 /var/lib/mysql /var/run/mysqld; \
\
mkdir /docker-entrypoint-initdb.d; \
\
mysqld --version; \
mysql --version; \
mysqlsh --version; \
yum clean packages

# Expose MySQL 服务端口
EXPOSE 3306 33060

# 设置容器启动时的入口命令
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["mysqld"]

# 持久化数据
VOLUME /var/lib/mysql

81 changes: 81 additions & 0 deletions library/mysql/8.0.40/Dockerfile.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#

FROM cr.loongnix.cn/loongson/loongnix-server:8.4
MAINTAINER zhaixiaojuan <[email protected]>

COPY mysql-boost-8.0.40.tar.gz /tmp
COPY epel-modular.repo /etc/yum.repos.d/
COPY epel.repo /etc/yum.repos.d/
COPY build_and_install_mysql.sh /tmp
COPY no_check_abi.patch /tmp
RUN sed -i 's/^enabled=0/enabled=1/' /etc/yum.repos.d/Loongnix-PowerTools.repo;
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN set -eux; \
yum makecache; \
yum install -y bzip2 openssl xz zstd rpm wget;

# add gosu for easy step-down from root && install mysql
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.14
RUN set -eux; \
yum install -y wget gnupg2 patch; \
wget -O /usr/local/bin/gosu "https://github.com/Loongson-Cloud-Community/gosu/releases/download/loongson-1.14/gosu-loongarch64"; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true; \
\
cd /tmp && \
# cd / && wget https://cdn.mysql.com/Downloads/MySQL-8.0/mysql-boost-8.0.40.tar.gz; \
tar -xf mysql-boost-8.0.40.tar.gz && patch -p1 /tmp/mysql-8.0.40/CMakeLists.txt < no_check_abi.patch && bash /tmp/build_and_install_mysql.sh; \
rm -rf mysql-8.0.40;
RUN dnf install python38-devel libssh -y && wget https://github.com/Loongson-Cloud-Community/mysql-shell-rpm/releases/download/v8.0.30/mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && tar -xf mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz; \
rpm -ivh --nodeps mysql-shell-8.0.30-LA-RPMS-mininal/loongarch64/*.rpm; \
rm -rf mysql-shell-8.0.30-LA-RPMS-mininal mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz;


ENV MYSQL_MAJOR 8.0
ENV MYSQL_VERSION 8.0.40-1loongnixserver8.4
ENV PATH=/usr/local/mysql/sbin:/usr/local/mysql/bin:$PATH
RUN set -eux; \
# make sure users dumping files in "/etc/mysql/conf.d" still works
! grep -F '!includedir' /etc/my.cnf; \
{ echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; \
mkdir -p /etc/mysql/conf.d; \
# 5.7 Debian-based images also included "/etc/mysql/mysql.conf.d" so let's include it too
{ echo '!includedir /etc/mysql/mysql.conf.d/'; } >> /etc/my.cnf; \
mkdir -p /etc/mysql/mysql.conf.d; \
\
# comment out a few problematic configuration values
find /etc/my.cnf /etc/mysql/ -name '*.cnf' -print0 \
| xargs -0 grep -lZE '^(bind-address|log)' \
| xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'; \
\
# ensure these directories exist and have useful permissions
# the rpm package has different opinions on the mode of `/var/run/mysqld`, so this needs to be after install
mkdir -p /var/lib/mysql /var/run/mysqld; \
chown mysql:mysql /var/lib/mysql /var/run/mysqld; \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
chmod 1777 /var/lib/mysql /var/run/mysqld; \
\
mkdir /docker-entrypoint-initdb.d; \
\
mysqld --version; \
mysql --version; \
mysqlsh --version; \
yum clean packages


VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306 33060
CMD ["mysqld"]
83 changes: 83 additions & 0 deletions library/mysql/8.0.40/Dockerfile.rpm
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#

#FROM oraclelinux:9-slim
#FROM cr.loongnix.cn/loongson/loongnix-server:8.4
FROM cr.loongnix.cn/openanolis/anolisos:8.9

RUN set -eux; \
groupadd --system --gid 1000 mysql; \
useradd --system --uid 1000 --gid 1000 --home-dir /var/lib/mysql --no-create-home mysql

# add gosu for easy step-down from root
# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.14
# 安装 MySQL Shell
RUN set -eux; \
dnf makecache && dnf install -y \
wget \
tar;

RUN wget https://github.com/Loongson-Cloud-Community/mysql-shell-rpm/releases/download/v8.0.30/mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
tar -xf mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
rpm -ivh --nodeps mysql-shell-8.0.30-LA-RPMS-mininal/loongarch64/*.rpm && \
rm -rf mysql-shell-8.0.30-LA-RPMS-mininal mysql-shell-8.0.30-LA-RPMS-mininal.tar.gz && \
wget -O /usr/local/bin/gosu "https://github.com/Loongson-Cloud-Community/gosu/releases/download/loongson-1.14/gosu-loongarch64" && \
chmod +x /usr/local/bin/gosu && \
gosu --version && \
gosu nobody true;

RUN set -eux; \
dnf install -y \
bzip2 \
gzip \
openssl \
xz \
zstd \
findutils \
; \
dnf clean all


ENV MYSQL_MAJOR 8.0
ENV MYSQL_VERSION 8.0.40-1.el9

# 下载mysql rpm包
RUN wget https://github.com/Loongson-Cloud-Community/mysql-rpm/releases/download/8.0.40/mysql-8.0.40-rpm.tar.gz && \
tar xf mysql-8.0.40-rpm.tar.gz && \
rpm -ivh --nodeps mysql-8.0.40/loongarch64/*.rpm && \
rm -rf mysql-8.0.40-rpm.tar.gz mysql-8.0.40;
# 安装mysql
RUN grep -F 'socket=/var/lib/mysql/mysql.sock' /etc/my.cnf; \
sed -i 's!^socket=.*!socket=/var/run/mysqld/mysqld.sock!' /etc/my.cnf; \
grep -F 'socket=/var/run/mysqld/mysqld.sock' /etc/my.cnf; \
{ echo '[client]'; echo 'socket=/var/run/mysqld/mysqld.sock'; } >> /etc/my.cnf; \
\
# make sure users dumping files in "/etc/mysql/conf.d" still works
! grep -F '!includedir' /etc/my.cnf; \
{ echo; echo '!includedir /etc/mysql/conf.d/'; } >> /etc/my.cnf; \
mkdir -p /etc/mysql/conf.d; \
# ensure these directories exist and have useful permissions
# the rpm package has different opinions on the mode of `/var/run/mysqld`, so this needs to be after install
mkdir -p /var/lib/mysql /var/run/mysqld; \
chown mysql:mysql /var/lib/mysql /var/run/mysqld; \
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
chmod 1777 /var/lib/mysql /var/run/mysqld; \
\
mkdir /docker-entrypoint-initdb.d; \
\
mysqld --version; \
mysql --version; \
mysqlsh --version;

VOLUME /var/lib/mysql

COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306 33060
CMD ["mysqld"]
21 changes: 21 additions & 0 deletions library/mysql/8.0.40/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is generated by the template.

REGISTRY?=cr.loongnix.cn
ORGANIZATION?=library
REPOSITORY?=mysql
TAG?=8.0.40

IMAGE=$(REGISTRY)/$(ORGANIZATION)/$(REPOSITORY):$(TAG)


default: image

image:
docker build \
--build-arg https_proxy=$(https_proxy) \
--build-arg http_proxy=$(http_proxy) \
-t $(IMAGE) \
.

push:
docker push $(IMAGE)
101 changes: 101 additions & 0 deletions library/mysql/8.0.40/build_and_install_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

# 需要安装的依赖包列表
DEPENDENCIES=(
"cmake"
"gcc"
"gcc-c++"
"make"
"rpcgen"
"diffutils"
"patch"
"libfido2-devel"
"rpcsvc-proto-devel"
"libicu-devel"
"libedit-devel"
"libevent-devel"
"curl-devel"
"libzstd-devel"
"lz4-devel"
"protobuf-devel"
"openssl-devel"
"libtirpc-devel"
"ncurses-devel"
"numactl-devel"
"systemd-devel"
"libaio-devel"
)

# 安装依赖包
echo "正在安装依赖包..."
dnf install -y "${DEPENDENCIES[@]}"

# 检查安装是否成功
if [ $? -ne 0 ]; then
echo "依赖包安装失败,请检查错误信息。"
exit 1
fi

# 设置一些变量
MYSQL_SRC_DIR="/tmp/mysql-8.0.40" # 替换为实际的 MySQL 源代码目录
BUILD_DIR="${MYSQL_SRC_DIR}/build" # 构建目录
INSTALL_DIR="/usr/local/mysql" # 安装目录

# 确保构建目录存在
mkdir -p "$BUILD_DIR"
cd "$MYSQL_SRC_DIR"

# 设置 CMake 配置选项
cmake \
-DCMAKE_C_FLAGS="-fPIC" \
-DCMAKE_CXX_FLAGS="-fPIC" \
-DBUILD_CONFIG="mysql_release" \
-DCMAKE_INSTALL_PREFIX="/usr/local/mysql" \
-DINSTALL_LIBDIR="lib" \
-DINSTALL_PLUGINDIR="lib/plugin" \
-DINSTALL_SUPPORTFILESDIR="share/support-files" \
-DINSTALL_LAYOUT=RPM \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DTMPDIR="/var/tmp" \
-DWITH_BOOST=boost \
-DWITH_EMBEDDED_SERVER=OFF \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_UNIT_TESTS=OFF \
-DWITH_ROUTER=OFF \
-DWITH_SYSTEM_LIBS=ON \
-DMYSQL_UNIX_ADDR="/usr/local/mysql/mysql.sock" \
-DDAEMON_NAME="mysqld" \
-DNICE_PROJECT_NAME="MySQL" \
-DWITH_SYSTEMD=1 \
-DSYSTEMD_SERVICE_NAME="mysqld" \
-DSYSTEMD_PID_DIR="/run/mysqld" \
-DWITH_PROTOBUF=bundled

# 编译 MySQL
make -j$(nproc)

# 安装 MySQL
make install

# 安装必要的目录
install -d -m 0751 "${INSTALL_DIR}/var/lib/mysql"
install -d -m 0755 "${INSTALL_DIR}/run/mysqld"
install -d -m 0750 "${INSTALL_DIR}/var/lib/mysql-files"
install -d -m 0750 "${INSTALL_DIR}/var/lib/mysql-keyring"

# 安装日志轮转和配置文件
install -D -m 0644 packaging/rpm-common/mysql.logrotate /etc/logrotate.d/mysql
install -D -m 0644 packaging/rpm-common/my.cnf /etc/my.cnf
install -d /etc/my.cnf.d

# 清理多余的文件
rm -rf "${INSTALL_DIR}/share/mysql-test" "${INSTALL_DIR}/lib64/*.a"

# 安装 sysusers 文件
#install -p -D -m 0644 "${MYSQL_SRC_DIR}/mysql.sysusers" /etc/sysusers.d/mysql.sysusers

# 更新共享库缓存
/sbin/ldconfig

echo "MySQL 已成功构建并安装!"

Loading
Loading