mirror of
https://github.com/zabbix/zabbix-docker.git
synced 2024-11-21 15:23:26 +01:00
Optimized build.sh
This commit is contained in:
parent
b0e477fd13
commit
da2f2f073a
28
build.sh
28
build.sh
@ -9,15 +9,11 @@ fi
|
|||||||
|
|
||||||
os=${PWD##*/}
|
os=${PWD##*/}
|
||||||
|
|
||||||
version=$1
|
version=${1:-latest}
|
||||||
version=${version:-"latest"}
|
|
||||||
|
|
||||||
type=$2
|
type=${2:-build}
|
||||||
type=${type:-"build"}
|
|
||||||
|
|
||||||
cd ../
|
app_component=$(cd ../ && echo "${PWD##*/}")
|
||||||
app_component=${PWD##*/}
|
|
||||||
cd $os/
|
|
||||||
|
|
||||||
if [ "$app_component" == "zabbix-appliance" ]; then
|
if [ "$app_component" == "zabbix-appliance" ]; then
|
||||||
app_component="appliance"
|
app_component="appliance"
|
||||||
@ -29,10 +25,10 @@ if [[ ! $version =~ ^[0-9]*\.[0-9]*\.[0-9]*$ ]] && [ "$version" != "latest" ]; t
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$version" != "latest" ]; then
|
if [ "$version" != "latest" ]; then
|
||||||
VCS_REF=`git ls-remote https://git.zabbix.com/scm/zbx/zabbix.git refs/tags/$version | cut -c1-10`
|
VCS_REF=$(git ls-remote https://git.zabbix.com/scm/zbx/zabbix.git refs/tags/"$version" | cut -c1-10)
|
||||||
else
|
else
|
||||||
MAJOR_VERSION=`cat Dockerfile | grep "ARG MAJOR_VERSION" | head -n1 | cut -f2 -d"="`
|
MAJOR_VERSION=$(grep "ARG MAJOR_VERSION" Dockerfile | head -n1 | cut -f2 -d"=")
|
||||||
MINOR_VERSION=`cat Dockerfile | grep "ARG ZBX_VERSION" | head -n1 | cut -f2 -d"."`
|
MINOR_VERSION=$(grep "ARG ZBX_VERSION" Dockerfile | head -n1 | cut -f2 -d".")
|
||||||
|
|
||||||
VCS_REF=$MAJOR_VERSION.$MINOR_VERSION
|
VCS_REF=$MAJOR_VERSION.$MINOR_VERSION
|
||||||
fi
|
fi
|
||||||
@ -42,11 +38,11 @@ if hash docker 2>/dev/null; then
|
|||||||
elif hash podman 2>/dev/null; then
|
elif hash podman 2>/dev/null; then
|
||||||
exec_command='podman'
|
exec_command='podman'
|
||||||
else
|
else
|
||||||
echo >&2 "Build command requires docker or podman. Aborting.";
|
echo >&2 "Build command requires docker or podman. Aborting."
|
||||||
exit 1;
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DOCKER_BUILDKIT=1 $exec_command build -t zabbix-$app_component:$os-$version --build-arg VCS_REF="$VCS_REF" --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` -f Dockerfile .
|
DOCKER_BUILDKIT=1 $exec_command build -t "zabbix-$app_component:$os-$version" --build-arg VCS_REF="$VCS_REF" --build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" -f Dockerfile .
|
||||||
|
|
||||||
if [ "$type" != "build" ]; then
|
if [ "$type" != "build" ]; then
|
||||||
links=""
|
links=""
|
||||||
@ -54,10 +50,10 @@ if [ "$type" != "build" ]; then
|
|||||||
|
|
||||||
if [[ $app_component =~ .*mysql.* ]]; then
|
if [[ $app_component =~ .*mysql.* ]]; then
|
||||||
links="$links --link mysql-server:mysql"
|
links="$links --link mysql-server:mysql"
|
||||||
env_vars="$env_vars -e MYSQL_DATABASE=\"zabbix\" -e MYSQL_USER=\"zabbix\" -e MYSQL_PASSWORD=\"zabbix\" -e MYSQL_RANDOM_ROOT_PASSWORD=true"
|
env_vars=("$env_vars" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix" -e MYSQL_RANDOM_ROOT_PASSWORD=true)
|
||||||
|
|
||||||
$exec_command rm -f mysql-server
|
$exec_command rm -f mysql-server
|
||||||
$exec_command run --name mysql-server -t $env_vars -d mysql:5.7
|
$exec_command run --name mysql-server -t "${env_vars[@]}" -d mysql:8.0-oracle
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$links" != "" ]; then
|
if [ "$links" != "" ]; then
|
||||||
@ -66,5 +62,5 @@ if [ "$type" != "build" ]; then
|
|||||||
|
|
||||||
$exec_command rm -f zabbix-$app_component
|
$exec_command rm -f zabbix-$app_component
|
||||||
|
|
||||||
$exec_command run --name zabbix-$app_component -t -d $links $env_vars zabbix-$app_component:$os-$version
|
$exec_command run --name zabbix-$app_component -t -d "$links" "${env_vars[@]}" "zabbix-$app_component:$os-$version"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user