diff --git a/mysql/8.3.0/22.03-lts-sp3/Dockerfile b/mysql/8.3.0/22.03-lts-sp3/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..ec66a8c3ed5e222f0166abb38e576db9fd5562d7 --- /dev/null +++ b/mysql/8.3.0/22.03-lts-sp3/Dockerfile @@ -0,0 +1,42 @@ +ARG BASE=openeuler/openeuler:22.03-lts-sp3 +FROM ${BASE} + +ARG TARGETARCH +ARG VERSION=8.3.0 +ARG GOSU_VERSION=1.17 + +RUN yum update -y && \ + yum install -y git wget g++ make ncurses-devel cmake openssl openssl-devel libtirpc-devel rpcgen bison m4 && \ + yum clean all && \ + mkdir -p /docker-entrypoint-initdb.d && \ + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${TARGETARCH}.asc" && \ + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${TARGETARCH}" && \ + wget -O mysql.tar.gz https://github.com/mysql/mysql-server/archive/refs/tags/mysql-${VERSION}.tar.gz && \ + mkdir -p /mysql && tar -xvf mysql.tar.gz -C /mysql --strip-components=1 && \ + mkdir -p /mysql/build && cd /mysql/build && \ + cmake /mysql \ + -DDEFAULT_CHARSET=utf8mb4 \ + -DDEFAULT_COLLATION=utf8mb4_unicode_ci \ + -DENABLED_LOCAL_INFILE=ON \ + -DWITH_SSL=system \ + -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/server \ + -DMYSQL_DATADIR=/usr/local/mysql/data \ + -DMYSQL_TCP_PORT=3306 \ + -DDOWNLOAD_BOOST=0 && \ + make -j "$(nproc)" && make install && \ + rm -f mysql.tar.gz + +ENV PATH=$PATH:/usr/local/mysql/server/bin +COPY config/ /etc/mysql/ +COPY entrypoint.sh /usr/local/bin/ + +RUN groupadd -r mysql && \ + useradd -r -g mysql mysql && \ + mkdir -p /usr/local/mysql/data && \ + chown mysql:mysql /usr/local/mysql/data && \ + chmod 755 /usr/local/mysql/data && \ + ln -s /usr/local/bin/entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["entrypoint.sh"] +EXPOSE 3306 33060 +CMD ["mysqld"] diff --git a/mysql/8.3.0/22.03-lts-sp3/config/conf.d/my.cnf b/mysql/8.3.0/22.03-lts-sp3/config/conf.d/my.cnf new file mode 100644 index 0000000000000000000000000000000000000000..248e0220178fe5abec1c05c90b21c39ca00b5980 --- /dev/null +++ b/mysql/8.3.0/22.03-lts-sp3/config/conf.d/my.cnf @@ -0,0 +1,3 @@ +[mysqld] +host_cache_size=0 +skip-name-resolve \ No newline at end of file diff --git a/mysql/8.3.0/22.03-lts-sp3/config/my.cnf b/mysql/8.3.0/22.03-lts-sp3/config/my.cnf new file mode 100644 index 0000000000000000000000000000000000000000..af9b69236d53636e78bbfd94f659013278f628e6 --- /dev/null +++ b/mysql/8.3.0/22.03-lts-sp3/config/my.cnf @@ -0,0 +1,29 @@ +# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +# +# The MySQL Server configuration file. +# +# For explanations see +# http://dev.mysql.com/doc/mysql/en/server-system-variables.html + +[mysqld] +pid-file = /var/run/mysqld/mysqld.pid +socket = /var/run/mysqld/mysqld.sock +datadir = /var/lib/mysql +secure-file-priv= NULL + +# Custom config should go here +!includedir /etc/mysql/conf.d/ \ No newline at end of file diff --git a/mysql/8.3.0/22.03-lts-sp3/entrypoint.sh b/mysql/8.3.0/22.03-lts-sp3/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..98e43d198c8f63c1823b26ce1a8442d6cf28ca64 --- /dev/null +++ b/mysql/8.3.0/22.03-lts-sp3/entrypoint.sh @@ -0,0 +1,416 @@ +#!/bin/bash +set -eo pipefail +shopt -s nullglob + +# logging functions +mysql_log() { + local type="$1"; shift + # accept argument string or stdin + local text="$*"; if [ "$#" -eq 0 ]; then text="$(cat)"; fi + local dt; dt="$(date --rfc-3339=seconds)" + printf '%s [%s] [Entrypoint]: %s\n' "$dt" "$type" "$text" +} +mysql_note() { + mysql_log Note "$@" +} +mysql_warn() { + mysql_log Warn "$@" >&2 +} +mysql_error() { + mysql_log ERROR "$@" >&2 + exit 1 +} + +# usage: file_env VAR [DEFAULT] +# ie: file_env 'XYZ_DB_PASSWORD' 'example' +# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of +# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + mysql_error "Both $var and $fileVar are set (but are exclusive)" + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +# check to see if this file is being run or sourced from another script +_is_sourced() { + # https://unix.stackexchange.com/a/215279 + [ "${#FUNCNAME[@]}" -ge 2 ] \ + && [ "${FUNCNAME[0]}" = '_is_sourced' ] \ + && [ "${FUNCNAME[1]}" = 'source' ] +} + +# usage: docker_process_init_files [file [file [...]]] +# ie: docker_process_init_files /always-initdb.d/* +# process initializer files, based on file extensions +docker_process_init_files() { + # mysql here for backwards compatibility "${mysql[@]}" + mysql=( docker_process_sql ) + + echo + local f + for f; do + case "$f" in + *.sh) + # https://github.com/docker-library/postgres/issues/450#issuecomment-393167936 + # https://github.com/docker-library/postgres/pull/452 + if [ -x "$f" ]; then + mysql_note "$0: running $f" + "$f" + else + mysql_note "$0: sourcing $f" + . "$f" + fi + ;; + *.sql) mysql_note "$0: running $f"; docker_process_sql < "$f"; echo ;; + *.sql.bz2) mysql_note "$0: running $f"; bunzip2 -c "$f" | docker_process_sql; echo ;; + *.sql.gz) mysql_note "$0: running $f"; gunzip -c "$f" | docker_process_sql; echo ;; + *.sql.xz) mysql_note "$0: running $f"; xzcat "$f" | docker_process_sql; echo ;; + *.sql.zst) mysql_note "$0: running $f"; zstd -dc "$f" | docker_process_sql; echo ;; + *) mysql_warn "$0: ignoring $f" ;; + esac + echo + done +} + +# arguments necessary to run "mysqld --verbose --help" successfully (used for testing configuration validity and for extracting default/configured values) +_verboseHelpArgs=( + --verbose --help + --log-bin-index="$(mktemp -u)" # https://github.com/docker-library/mysql/issues/136 +) + +mysql_check_config() { + local toRun=( "$@" "${_verboseHelpArgs[@]}" ) errors + if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then + mysql_error $'mysqld failed while attempting to check config\n\tcommand was: '"${toRun[*]}"$'\n\t'"$errors" + fi +} + +# Fetch value from server config +# We use mysqld --verbose --help instead of my_print_defaults because the +# latter only show values present in config files, and not server defaults +mysql_get_config() { + local conf="$1"; shift + "$@" "${_verboseHelpArgs[@]}" 2>/dev/null \ + | awk -v conf="$conf" '$1 == conf && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }' + # match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)" +} + +# Ensure that the package default socket can also be used +# since rpm packages are compiled with a different socket location +# and "mysqlsh --mysql" doesn't read the [client] config +# related to https://github.com/docker-library/mysql/issues/829 +mysql_socket_fix() { + local defaultSocket + defaultSocket="$(mysql_get_config 'socket' mysqld --no-defaults)" + if [ "$defaultSocket" != "$SOCKET" ]; then + ln -sfTv "$SOCKET" "$defaultSocket" || : + fi +} + +# Do a temporary startup of the MySQL server, for init purposes +docker_temp_server_start() { + # For 5.7+ the server is ready for use as soon as startup command unblocks + if ! "$@" --daemonize --skip-networking --default-time-zone=SYSTEM --socket="${SOCKET}"; then + mysql_error "Unable to start server." + fi +} + +# Stop the server. When using a local socket file mysqladmin will block until +# the shutdown is complete. +docker_temp_server_stop() { + if ! mysqladmin --defaults-extra-file=<( _mysql_passfile ) shutdown -uroot --socket="${SOCKET}"; then + mysql_error "Unable to shut down server." + fi +} + +# Verify that the minimally required password settings are set for new databases. +docker_verify_minimum_env() { + if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then + mysql_error <<-'EOF' + Database is uninitialized and password option is not specified + You need to specify one of the following as an environment variable: + - MYSQL_ROOT_PASSWORD + - MYSQL_ALLOW_EMPTY_PASSWORD + - MYSQL_RANDOM_ROOT_PASSWORD + EOF + fi + + # This will prevent the CREATE USER from failing (and thus exiting with a half-initialized database) + if [ "$MYSQL_USER" = 'root' ]; then + mysql_error <<-'EOF' + MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user + Remove MYSQL_USER="root" and use one of the following to control the root user password: + - MYSQL_ROOT_PASSWORD + - MYSQL_ALLOW_EMPTY_PASSWORD + - MYSQL_RANDOM_ROOT_PASSWORD + EOF + fi + + # warn when missing one of MYSQL_USER or MYSQL_PASSWORD + if [ -n "$MYSQL_USER" ] && [ -z "$MYSQL_PASSWORD" ]; then + mysql_warn 'MYSQL_USER specified, but missing MYSQL_PASSWORD; MYSQL_USER will not be created' + elif [ -z "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ]; then + mysql_warn 'MYSQL_PASSWORD specified, but missing MYSQL_USER; MYSQL_PASSWORD will be ignored' + fi +} + +# creates folders for the database +# also ensures permission for user mysql of run as root +docker_create_db_directories() { + local user; user="$(id -u)" + + local -A dirs=( ["$DATADIR"]=1 ) + local dir + dir="$(dirname "$SOCKET")" + dirs["$dir"]=1 + + # "datadir" and "socket" are already handled above (since they were already queried previously) + local conf + for conf in \ + general-log-file \ + keyring_file_data \ + pid-file \ + secure-file-priv \ + slow-query-log-file \ + ; do + dir="$(mysql_get_config "$conf" "$@")" + + # skip empty values + if [ -z "$dir" ] || [ "$dir" = 'NULL' ]; then + continue + fi + case "$conf" in + secure-file-priv) + # already points at a directory + ;; + *) + # other config options point at a file, but we need the directory + dir="$(dirname "$dir")" + ;; + esac + + dirs["$dir"]=1 + done + + mkdir -p "${!dirs[@]}" + + if [ "$user" = "0" ]; then + # this will cause less disk access than `chown -R` + find "${!dirs[@]}" \! -user mysql -exec chown --no-dereference mysql '{}' + + fi +} + +# initializes the database directory +docker_init_database_dir() { + mysql_note "Initializing database files" + "$@" --initialize-insecure --default-time-zone=SYSTEM + mysql_note "Database files initialized" +} + +# Loads various settings that are used elsewhere in the script +# This should be called after mysql_check_config, but before any other functions +docker_setup_env() { + # Get config + declare -g DATADIR SOCKET + DATADIR="$(mysql_get_config 'datadir' "$@")" + SOCKET="$(mysql_get_config 'socket' "$@")" + + # Initialize values that might be stored in a file + file_env 'MYSQL_ROOT_HOST' '%' + file_env 'MYSQL_DATABASE' + file_env 'MYSQL_USER' + file_env 'MYSQL_PASSWORD' + file_env 'MYSQL_ROOT_PASSWORD' + + declare -g DATABASE_ALREADY_EXISTS + if [ -d "$DATADIR/mysql" ]; then + DATABASE_ALREADY_EXISTS='true' + fi +} + +# Execute sql script, passed via stdin +# usage: docker_process_sql [--dont-use-mysql-root-password] [mysql-cli-args] +# ie: docker_process_sql --database=mydb <<<'INSERT ...' +# ie: docker_process_sql --dont-use-mysql-root-password --database=mydb /dev/null + + docker_init_database_dir "$@" + + mysql_note "Starting temporary server" + docker_temp_server_start "$@" + mysql_note "Temporary server started." + + mysql_socket_fix + docker_setup_db + docker_process_init_files /docker-entrypoint-initdb.d/* + + mysql_expire_root_user + + mysql_note "Stopping temporary server" + docker_temp_server_stop + mysql_note "Temporary server stopped" + + echo + mysql_note "MySQL init process done. Ready for start up." + echo + else + mysql_socket_fix + fi + fi + exec "$@" +} + +# If we are sourced from elsewhere, don't perform any further actions +if ! _is_sourced; then + _main "$@" +fi \ No newline at end of file diff --git a/mysql/README.md b/mysql/README.md new file mode 100644 index 0000000000000000000000000000000000000000..2b001c07aa8f7d577dd495b499e977093e73bbf2 --- /dev/null +++ b/mysql/README.md @@ -0,0 +1,31 @@ +# MySQL + +# Quick reference + +- The official mysql docker image. + +- Maintained by: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative) + +- Where to get help: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative), [openEuler](https://gitee.com/openeuler/community) + +# Build reference + +1. Build images and push: +```shell +docker buildx build -t "openeuler/mysql:$TAG" --platform linux/amd64,linux/arm64 . --push +``` + +We are using `buildx` in here to generate multi-arch images, see more in [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/) + +2. Run: +```shell +docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d openeuler/mysql:{TAG} +``` +where `mysql` is the name you want to assign to your container, `my-secret-pw` is the password to be set for the MySQL root user. + +# Supported tags and respective Dockerfile links + +- 8.3.0-oe2203sp3: mysql v8.3.0, openEuler 22.03 LTS SP3 + +## Operating System +Linux/Unix, ARM64 or x86-64 architecture. diff --git a/mysql/doc/image-info.yml b/mysql/doc/image-info.yml new file mode 100644 index 0000000000000000000000000000000000000000..819eac437e36a8871bf6e3e7fcc14ffe1b0b1c06 --- /dev/null +++ b/mysql/doc/image-info.yml @@ -0,0 +1,93 @@ +name: MySQL +category: database +description: MySQL是一种开源关系型数据库管理系统。与其他关系型数据库一样,MySQL将数据存储在由行和列组成的表中。用户可以使用结构化查询语言(通常称为SQL)定义、操作、控制和查询数据。MySQL凭借其经过验证的性能、可靠性和易用性成为基于Web的应用程序的领先数据库选择,涵盖从个人项目和网站,到电子商务和信息服务,一直到高端应用程序的整个范围。 +environment: | + 本应用以容器镜像的方式供用户使用,运行于预置docker的Linux环境。Docker的推荐安装方式如下: + ## apt安装 + ### 1.更新系统软件包依赖 + ``` + sudo spt update + sudo apt install ca-certificates curl gnupg lsb-release + ``` + ### 2.添加Docker官方GPG密钥 + ``` + sudo mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg + sudo chmod a+r /etc/apt/keyrings/docker.gpg + ``` + ### 3.添加Docker官方APT源 + ``` + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + ``` + ### 4.再次更新软件包索引 + ``` + sudo apt update + ``` + ### 5.安装Docker + ``` + sudo apt install docker-ce docker-ce-cli containerd.io + ``` + + ## yum安装 + ### 1.安装yum-utils + ``` + sudo yum install -y yum-utils + ``` + ### 2.添加Docker源 + ``` + sudo yum-config-manager \ + > --add-repo \ + > https://download.docker.com/linux/centos/docker-ce.repo + ``` + ### 3.安装Docker + ``` + sudo yum install -y docker-ce docker-ce-cli containerd.io + ``` + + 注意,在openEuler环境安装docker时,可执行如下命令一键安装 + ``` + yum install -y docker + ``` + + ## 脚本安装 + ### 1.下载安装脚本 + ``` + curl -fsSL https://get.docker.com -o get-docker.sh + ``` + ### 2.使用root权限执行脚本 + ``` + sudo sh get-docker.sh + ``` + 使用脚本安装方式时,如果用户要指定安装的docker版本,需要自行修改`get-docker.sh`的源码内容。 + + ## 验证 + ``` + sudo docker run hello-world + ``` + +download: | + 获取容器镜像 + ``` + docker pull openeuler/mysql:{TAG} + ``` + +install: | + 启动容器 + ``` + docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d openeuler/mysql:{TAG} + ``` + 其中,mysql是分配给容器的名称,my-secret-pw是为MySQL根用户设置的密码。用户可根据自身需求,自定义启动选项。 + +license: View license +similar_packages: + - PostgreSQL: PostgreSQL是一个功能强大的开源关系型数据库管理系统,它提供了与MySQL类似的功能,并且支持广泛的标准SQL语法。PostgreSQL具有高度的可扩展性、可靠性和数据一致性,同时还提供了许多高级功能,如复杂查询、事务控制和触发器等。 + - Oracle Database: Oracle Database是一款商业的关系型数据库管理系统,它是市场上最受欢迎和广泛使用的数据库之一。Oracle Database提供了丰富的功能集,包括高级查询、分布式数据库、数据复制和高可用性选项等。 + - Microsoft SQL Server: Microsoft SQL Server是由Microsoft开发的关系型数据库管理系统。它提供了与MySQL类似的功能,同时还与Microsoft的其他产品和技术集成紧密。Microsoft SQL Server适用于Windows操作系统,并提供了高性能、可伸缩性和企业级功能。 + - SQLite: SQLite是一种嵌入式关系型数据库管理系统,它提供了轻量级的、零配置的数据库解决方案。SQLite具有小巧、高效、可嵌入的特点,适用于嵌入式设备和移动应用程序。 +dependency: + - ncurses-devel + - openssl + - libtirpc-devel + - rpcgen + - bison + - m4 \ No newline at end of file diff --git a/mysql/doc/picture/logo.png b/mysql/doc/picture/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..79eb4f36dbb1416c240b608f53413d77ee8f4b4f Binary files /dev/null and b/mysql/doc/picture/logo.png differ diff --git a/mysql/meta.yml b/mysql/meta.yml new file mode 100644 index 0000000000000000000000000000000000000000..6d231d7ce21b78cf087658a505ab42a9a1c3b383 --- /dev/null +++ b/mysql/meta.yml @@ -0,0 +1,2 @@ +8.3.0-oe2203sp3: + mysql/8.3.0/22.03-lts-sp3/Dockerfile \ No newline at end of file