165 lines
4.6 KiB
Bash
165 lines
4.6 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# 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="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 (amd64,arm64)"
|
|
echo " -s, --system Specify the system image (ubuntu22.04,alpine3.20)"
|
|
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
|
|
case $PLATFORM in
|
|
amd64) ;;
|
|
arm64) ;;
|
|
*)
|
|
echo "Error: platform be: $PLATFORM"
|
|
echo "can only be amd64/arm64"
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|
|
echo "Platform: $PLATFORM"
|
|
|
|
# Determine if -s is passed in
|
|
if [ -n "$SYSTEM" ]; then
|
|
case $SYSTEM in
|
|
ubuntu22.04) ;;
|
|
alpine3.20) ;;
|
|
*)
|
|
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}
|
|
# Release Package name file
|
|
ReleaseFileName=omc-r${VERSION}-docker-${SYSTEM}-${PLATFORM}
|
|
|
|
|
|
# =================== 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=./linux/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}
|
|
|
|
# Replacement Tags {version} {arch}
|
|
sed -i "s/{version}/${VERSION}/g" ./${ReleaseFileName}/omc-docker.sh
|
|
sed -i "s/{arch}/${PLATFORM}/g" ./${ReleaseFileName}/omc-docker.sh
|
|
sed -i "s/{system}/${SYSTEM}/g" ./${ReleaseFileName}/omc-docker.sh
|
|
|
|
# check docker image
|
|
if ! docker images | grep -q "mariadb-$PLATFORM\s*10.6.21"; then
|
|
docker pull --platform linux/${PLATFORM} mariadb:10.6.21
|
|
docker tag mariadb:10.6.21 mariadb-$PLATFORM:10.6.21
|
|
fi
|
|
if [ ! -f ${BuildDir}/$ReleaseFileName/tar/mariadb_10.6.21_$PLATFORM.tar ]; then
|
|
docker save mariadb-$PLATFORM:10.6.21 -o ${BuildDir}/${ReleaseFileName}/tar/mariadb_10.6.21_$PLATFORM.tar
|
|
fi
|
|
if ! docker images | grep -q "keydb-$PLATFORM\s*6.3.4"; then
|
|
docker pull --platform linux/${PLATFORM} bitnami/keydb:6.3.4
|
|
docker tag bitnami/keydb:6.3.4 keydb-$PLATFORM:6.3.4
|
|
fi
|
|
if [ ! -f ${BuildDir}/$ReleaseFileName/tar/keydb_6.3.4_$PLATFORM.tar ]; then
|
|
docker save keydb-$PLATFORM:6.3.4 -o ${BuildDir}/${ReleaseFileName}/tar/keydb_6.3.4_$PLATFORM.tar
|
|
fi
|
|
|
|
# build omc
|
|
docker build --platform linux/${PLATFORM} --build-arg TARGETARCH=${PLATFORM} --build-arg VERSION=${VERSION} -t omc:${VERSION}-${SYSTEM}-${PLATFORM} .
|
|
docker save omc:${VERSION}-${SYSTEM}-${PLATFORM} -o ${BuildDir}/${ReleaseFileName}/tar/omc_${VERSION}-${SYSTEM}-${PLATFORM}.tar
|
|
|
|
# tar package
|
|
filename=${ReleaseFileName}.tar.gz
|
|
output=${ReleaseDir}/${filename}
|
|
tar -czf ${output} ./${ReleaseFileName}
|
|
echo "build success => ${output}"
|
|
|
|
# Generate HAX file
|
|
cd ${ReleaseDir}
|
|
md5sum ${filename} > ${filename}.md5
|
|
echo "md5 => $(cat ${filename}.md5)"
|
|
sha256sum ${filename} > ${filename}.sha256
|
|
echo "sha256 => $(cat ${filename}.sha256)"
|
|
}
|
|
|
|
|
|
# =================== building
|
|
echo
|
|
echo "building omc..."
|
|
mkdir -p ${BuildDir}/${ReleaseFileName}/tar
|
|
cp -rf ${BuildLinuxDir} ${BuildDir}
|
|
cp -rf ${BuildPackagelDir}/docker/linux ${BuildDir}
|
|
cp -rf ${BuildPackagelDir}/docker/tar/* ${BuildDir}/${ReleaseFileName}
|
|
cp -rf ${BuildPackagelDir}/docker/Dockerfile.${SYSTEM} ${BuildDir}/Dockerfile
|
|
app
|
|
docker_build
|
|
|
|
|
|
# bash build-docker.sh --version 2.2505.2 --platform amd64 --system ubuntu22.04
|
|
# bash build-docker.sh --version 2.2505.2 --platform amd64 --system alpine3.20
|