全网独家:基于openeuler-20.03-lts底包构建opengauss数据库V5.0.1LTS的单机容器

发布时间:2024年01月03日

近期想测试一下opengauss数据库,官网上单机容器部署只有x86-64平台CentOS 7.6和ARM64平台 openEuler20.03 LTS两种底包方案。本文系全网独家在x86平台上基于openeuler-20.03-lts底包构建opengauss数据库V5.0.1LTS的单机容器。

opengauss官网上单机容器部署只有x86-64平台CentOS 7.6和ARM64平台 openEuler20.03 LTS两种方案:

本文探索在 x86-64  openEuler20.03 LTS容器底包上进行数据库容器打包。

一、基础环境

1、宿主机环境

 宿主机为x86平台,操作系统为openEuler 22.03 LTS

# cat /etc/os-release 
NAME="openEuler"
VERSION="22.03 LTS"
ID="openEuler"
VERSION_ID="22.03"
PRETTY_NAME="openEuler 22.03 LTS"
ANSI_COLOR="0;31"
2、容器底包

openeuler-20.03-lts:latest

# docker images 
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
openeuler-20.03-lts   latest              eeb84ae20ad2        3 years ago         469MB
3、openGauss版本

如下:x86-64架构、操作系统openeuler-20.03-lts、openGauss——5.0.1企业版安装包

 该文件的SHA256值为:c4687aa6bb02ffc1402b972a01a2515ba8524def624f4c8227c40dcaf38aa9e4

openGauss-5.0.1-openEuler-64bit-all.tar.gz

4、下载安装程序脚本

下载官方安装程序

直接下载链接

二、打包环境准备

1、准备目录和数据库安装包、容器repo源
# mkdir -p dockerfiles/5.0.1
# wget https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.1/x86_openEuler/openGauss-5.0.1-openEuler-64bit-all.tar.gz
# sha256sum openGauss-5.0.1-openEuler-64bit-all.tar.gz >sha256_file_amd64
# mv openGauss-5.0.1-openEuler-64bit-all.tar.gz sha256_file_amd64 dockerfiles
# wget https://mirrors.huaweicloud.com/repository/conf/openeuler_x86_64.repo
# mv openeuler_x86_64.repo dockerfiles/5.0.1
2、准备安装脚本

将前面下载的官方安装程序包解压,拷贝文件到相应目录

buildDockerImage.sh------当前目录

dockerfiles目录下应有以下文件:

dockerfile_amd
entrypoint.sh
generatexml.py
gosu-amd64
gs_createtrust.py
install.sh
openGauss-5.0.1-openEuler-64bit-all.tar.gz   (本文件是上一步下载并转移过来的)
sha256_file_amd64                                         (本文件是上一步生成的)
util.sh

完成后的目录结构:

# tree 
.
├── buildDockerImage.sh
└── dockerfiles
    ├── 5.0.1
    │   └── openeuler_x86_64.repo
    ├── dockerfile_amd
    ├── entrypoint.sh
    ├── generatexml.py
    ├── gosu-amd64
    ├── gs_createtrust.py
    ├── install.sh
    ├── openEuler-20.03-LTS.tar.xz
    ├── openGauss-5.0.1-openEuler-64bit-all.tar.gz
    ├── sha256_file_amd64
    └── util.sh

3、修改dockerfiles/dockerfile_amd文件

修改后内容如下:

# vi dockerfiles/dockerfile_amd 
# cat dockerfiles/dockerfile_amd 
FROM openeuler-20.03-lts:latest

ENV OPENGAUSS_VERSION 5.0.1

COPY openGauss-${OPENGAUSS_VERSION}-openEuler-64bit-all.tar.gz .
COPY gosu-amd64 /usr/local/bin/gosu
COPY gs_createtrust.py .
ENV LANG en_US.utf8
COPY 5.0.1/openeuler_x86_64.repo /etc/yum.repos.d/openeuler_x86_64.repo

RUN set -eux; \  
    yum install -y bzip2 bzip2-devel curl libaio readline-devel expect which git python3 python3-devel openssl-devel net-tools openssh-server vim shadow && \  
    /usr/sbin/groupadd -g 70 omm; \  
    /usr/sbin/useradd -u 70 -g omm -d /home/omm omm; \  
    mkdir -p /opengauss && \  
    chmod 700 /opengauss && \  
    mv openGauss-${OPENGAUSS_VERSION}-openEuler-64bit-all.tar.gz /opengauss && \  
    mv gs_createtrust.py /opengauss && \  
    mkdir -p /volume && \  
    chmod -R 755 /volume && \  
    chown -R omm:omm /opengauss

ENV LANG en_US.utf8


ENV GOSU_VERSION 1.12
RUN set -eux; \
     chmod +x /usr/local/bin/gosu


COPY entrypoint.sh /usr/local/bin/
COPY entrypoint.sh /usr/local/bin/
COPY install.sh /usr/local/bin/
COPY util.sh /usr/local/bin/
COPY generatexml.py /usr/local/bin/
RUN chmod 755 /usr/local/bin/entrypoint.sh;ln -s /usr/local/bin/entrypoint.sh /
RUN chmod 755 /usr/local/bin/install.sh;ln -s /usr/local/bin/install.sh /
RUN chmod 755 /usr/local/bin/util.sh;ln -s /usr/local/bin/util.sh /
RUN chmod 755 /usr/local/bin/generatexml.py /

ENTRYPOINT ["entrypoint.sh"]

EXPOSE 5432
4、修改buildDockerImage.sh文件

改后的内容如下:

#!/bin/bash
# Build docker image
# Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
#
#openGauss is licensed under Mulan PSL v2.
#You can use this software according to the terms and conditions of the Mulan PSL v2.
#You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
#-------------------------------------------------------------------------
#
# buildDockerImage.sh
#    Build docker image
#
# IDENTIFICATION
#    openGauss-container/buildDockerImage.sh
#
#-------------------------------------------------------------------------

usage() {
  cat << EOF

Usage: buildDockerImage.sh -v [version]  [-i]  [Docker build option]
Builds a Docker Image for openGauss
  
Parameters:
   -v: version to build
   -i: ignores the SHA256 checksums

LICENSE MulanPSL2

EOF

}

# Validate packages
checksum_packages() {
if [ "${arch}" = "amd64" ]; then
    sha256_file="sha256_file_amd64"
    else
    sha256_file="sha256_file_arm64"
fi

  if hash sha256sum 2>/dev/null; then
    echo "Checking if required packages are present and valid..."   
    if ! sha256sum -c "$sha256_file"; then
      echo "SHA256 for required packages to build this image did not match!"
      echo "Make sure to download missing files in folder $VERSION."
      exit 1;
    fi
  else
    echo "Ignored SHA256 sum, 'sha256sum' command not available.";
  fi
}


# Check Docker version
check_docker_version() {
  # Get Docker Server version
  echo "Checking Docker version."
  DOCKER_VERSION=$(docker version --format '{
  {.Server.Version | printf "%.5s" }}'|| exit 0)
  # Remove dot in Docker version
  docker_version_major=$(echo $DOCKER_VERSION | awk -F . '{print $1}')

  if [ -z "$DOCKER_VERSION" ]; then
    # docker could be aliased to podman and errored out (https://github.com/containers/libpod/pull/4608)
    echo "Please check if docker is installed." && exit 1
  elif [ "$docker_version_major" -lt "${MIN_DOCKER_VERSION_MAJOR}" ]; then
    echo "Docker version is below the minimum required version $MIN_DOCKER_VERSION_MAJOR.$MIN_DOCKER_VERSION_MINOR"
    echo "Please upgrade your Docker installation to proceed."
    exit 1;
  fi
}

##############
#### MAIN ####
##############

# Parameters
VERSION="5.0.1"
SKIPCHECKSUM=0
DOCKEROPS=""
MIN_DOCKER_VERSION_MAJOR="17"
MIN_DOCKER_VERSION_MINOR="09"
arch=$(case $(uname -m) in i386)   echo "386" ;; i686)   echo "386" ;; x86_64) echo "amd64";; aarch64)echo "arm64";; esac)
if [ "${arch}" = "amd64" ]; then
    DOCKERFILE="dockerfile_amd"
    else
    DOCKERFILE="dockerfile_arm"
fi

if [ "$#" -eq 0 ]; then
  usage;
  exit 1;
fi

while getopts "hesxiv:o:" optname; do
  case "$optname" in
    "h")
      usage
      exit 0;
      ;;
    "i")
      SKIPCHECKSUM=1
      ;;
    "v")
      VERSION="$OPTARG"
      ;;
    "o")
      DOCKEROPS="$OPTARG"
      ;;
    "?")
      usage;
      exit 1;
      ;;
    *)
    # Should not occur
      echo "Unknown error while processing options inside buildDockerImage.sh"
      ;;
  esac
done

check_docker_version


# openGauss Database Image Name
IMAGE_NAME="opengauss:$VERSION"

# check package exist
if [ "`ls dockerfiles/ |grep openGauss-${VERSION}`" == "" ]; then
  echo "Could not find openGauss $VERSION package.";
  exit 1;
fi

cd dockerfiles/


if [ ! "$SKIPCHECKSUM" -eq 1 ]; then
  checksum_packages
else
  echo "Ignored SHA256 checksum."
fi
echo "=========================="
echo "DOCKER info:"
docker info
echo "=========================="

# Proxy settings
PROXY_SETTINGS=""
if [ "${http_proxy}" != "" ]; then
  PROXY_SETTINGS="$PROXY_SETTINGS --build-arg http_proxy=${http_proxy}"
fi

if [ "${https_proxy}" != "" ]; then
  PROXY_SETTINGS="$PROXY_SETTINGS --build-arg https_proxy=${https_proxy}"
fi

if [ "${ftp_proxy}" != "" ]; then
  PROXY_SETTINGS="$PROXY_SETTINGS --build-arg ftp_proxy=${ftp_proxy}"
fi

if [ "${no_proxy}" != "" ]; then
  PROXY_SETTINGS="$PROXY_SETTINGS --build-arg no_proxy=${no_proxy}"
fi

if [ "$PROXY_SETTINGS" != "" ]; then
  echo "Proxy settings were found and will be used during the build."
fi

# ################## #
# BUILDING THE IMAGE #
# ################## #
echo "Building image '$IMAGE_NAME' ..."

# BUILD THE IMAGE (replace all environment variables)
BUILD_START=$(date '+%s')
docker build --force-rm=true --no-cache=true \
       $DOCKEROPS $PROXY_SETTINGS  \
       -t $IMAGE_NAME -f $DOCKERFILE . || {
  echo ""
  echo "ERROR: openGauss Database
文章来源:https://blog.csdn.net/forestqq/article/details/135345855
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。