#!/bin/bash # Check if Docker is installed if command -v docker &> /dev/null then echo $(docker --version) else echo "Docker is not installed" exit 1 fi # Default Version VERSION="1.0.0" # Default Platform PLATFORM="linux/amd64" # Default Platform Architecture PLATFORM_ARCH="amd64" # Default System SYSTEM="ubuntu22.04" # usage usage() { echo "Usage: bash $0 [OPTION]" echo echo "Build Software Package OPTION:" echo " -v, --version Specify the version" echo " -p, --platform Specify the platform architecture (linux/amd64,linux/arm64)" echo " -s, --system Specify the system image (ubuntu22.04)" echo " -h Display this help message" echo exit 1 } # Read command line arguments while [[ $# -gt 0 ]]; do case "$1" in -v|--version) VERSION="$2"; shift 2 ;; # Processing the version after -v -p|--platform) PLATFORM="$2"; shift 2 ;; # Processing the platform after -p -s|--system) SYSTEM="$2"; shift 2 ;; # Processing the system after -s *) usage ;; esac done # output result echo "Version: $VERSION" # =================== Compile System Information # Determine if -p is passed in if [ -n "$PLATFORM" ]; then if [[ "$PLATFORM" != "linux/amd64" && "$PLATFORM" != "linux/arm64" ]]; then echo "Error: platform can only be 'linux/amd64' or 'linux/arm64'." exit 1 fi fi echo "Platform: $PLATFORM" # Get the platform architecture get_platform_arch() { if [[ "$PLATFORM" = "linux/amd64" ]]; then echo "amd64" elif [[ "$PLATFORM" = "linux/arm64" ]]; then echo "arm64" else echo "unknown platform" exit 1 fi } PLATFORM_ARCH=$(get_platform_arch) # Determine if -s is passed in if [ -n "$SYSTEM" ]; then case $SYSTEM in ubuntu22.04) ;; *) echo "unknown system image: $SYSTEM" exit 1 ;; esac fi echo "System: $SYSTEM" # =================== Compile Variable Information # Script Path RootDir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) # Compile Linux System Directory BuildLinuxDir=${RootDir}/linux # Compile Package Management Directory BuildPackagelDir=${RootDir}/pkg # Compile the build directory BuildDir=${RootDir}/tmp # Release Package directory ReleaseDir=${RootDir}/release/docker/${PLATFORM_ARCH} # Release Package name file ReleaseFileName=omc-r${VERSION}-${SYSTEM}-docker # =================== file processing # Apply file handling app() { cd ${BuildDir} # Database scripts within common are rebuild scripts modeList="std lite" for v in ${modeList}; do # . /Located in the temporary directory path=./usr/local/etc/omc/database/${v} cp -rf $path/common/* $path/install/ cp -rf $path/common/* $path/upgrade/ rm -rf $path/common done } # =================== compile docker_build() { cd ${BuildDir} # check docker image if ! docker images | grep -q "mariadb:10.6.21"; then docker pull mariadb:10.6.21 fi if [ ! -f $ReleaseFileName/tar/mariadb_10.6.21.tar ]; then docker save mariadb:10.6.21 -o ${ReleaseFileName}/tar/mariadb_10.6.21.tar fi if ! docker images | grep -q "bitnami/keydb:6.3.4"; then docker pull bitnami/keydb:6.3.4 fi if [ ! -f $ReleaseFileName/tar/keydb_6.3.4.tar ]; then docker save bitnami/keydb:6.3.4 -o ${ReleaseFileName}/tar/keydb_6.3.4.tar fi # build omc docker build --platform ${PLATFORM} --build-arg VERSION=${VERSION} -t omc:${VERSION} . docker save omc:${VERSION} -o ${ReleaseFileName}/tar/omc_${VERSION}.tar # tar package tar -czvf ${ReleaseDir}/${ReleaseFileName}.tar ${ReleaseFileName}/ # Generate MD5 file rm -f omc_md5sum.txt md5sum ${ReleaseDir}/${ReleaseFileName}.tar >${ReleaseDir}/omc_md5sum.txt cat ${ReleaseDir}/omc_md5sum.txt } # =================== building echo echo "building omc..." rm -rf ${BuildDir} && mkdir -p ${BuildDir}/${ReleaseFileName} cp -rf ${BuildPackagelDir}/docker/Dockerfile.${SYSTEM}.${PLATFORM_ARCH} ${BuildDir}/Dockerfile cp -rf ${BuildPackagelDir}/docker/script/* ${BuildDir}/${ReleaseFileName} cp -rf ${BuildLinuxDir} ${BuildDir} app docker_build # bash build-docker.sh --version 2.2505.2 --platform linux/arm64 --system ubuntu22.04