zabbix-docker/build.sh

67 lines
1.8 KiB
Bash
Raw Normal View History

2018-06-07 05:47:07 +02:00
#!/bin/bash
set +e
if [ ! -f "Dockerfile" ]; then
echo "Dockerfile is missing!"
exit 1
fi
os=${PWD##*/}
2022-08-05 09:42:15 +02:00
version=${1:-latest}
2018-06-07 05:47:07 +02:00
2022-08-05 09:42:15 +02:00
type=${2:-build}
2018-06-07 05:47:07 +02:00
2022-08-05 09:42:15 +02:00
app_component=$(cd ../ && echo "${PWD##*/}")
2018-06-07 05:47:07 +02:00
if [ "$app_component" == "zabbix-appliance" ]; then
app_component="appliance"
fi
if [[ ! $version =~ ^[0-9]*\.[0-9]*\.[0-9]*$ ]] && [ "$version" != "latest" ]; then
echo "Incorrect syntax of the version"
exit 1
fi
if [ "$version" != "latest" ]; then
2022-08-05 09:42:15 +02:00
VCS_REF=$(git ls-remote https://git.zabbix.com/scm/zbx/zabbix.git refs/tags/"$version" | cut -c1-10)
2018-06-07 05:47:07 +02:00
else
2022-08-05 09:42:15 +02:00
MAJOR_VERSION=$(grep "ARG MAJOR_VERSION" Dockerfile | head -n1 | cut -f2 -d"=")
MINOR_VERSION=$(grep "ARG ZBX_VERSION" Dockerfile | head -n1 | cut -f2 -d".")
2018-06-07 05:47:07 +02:00
VCS_REF=$MAJOR_VERSION.$MINOR_VERSION
fi
2021-10-16 17:49:19 +02:00
if hash docker 2>/dev/null; then
exec_command='docker'
elif hash podman 2>/dev/null; then
exec_command='podman'
else
2022-08-05 09:42:15 +02:00
echo >&2 "Build command requires docker or podman. Aborting."
exit 1
2021-10-16 17:49:19 +02:00
fi
2022-08-05 09:42:15 +02:00
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 .
2018-06-07 05:47:07 +02:00
if [ "$type" != "build" ]; then
links=""
env_vars=""
if [[ $app_component =~ .*mysql.* ]]; then
links="$links --link mysql-server:mysql"
2022-08-05 09:42:15 +02:00
env_vars=("$env_vars" -e MYSQL_DATABASE="zabbix" -e MYSQL_USER="zabbix" -e MYSQL_PASSWORD="zabbix" -e MYSQL_RANDOM_ROOT_PASSWORD=true)
2018-06-07 05:47:07 +02:00
2021-10-16 17:49:19 +02:00
$exec_command rm -f mysql-server
2022-08-05 09:42:15 +02:00
$exec_command run --name mysql-server -t "${env_vars[@]}" -d mysql:8.0-oracle
2018-06-07 05:47:07 +02:00
fi
if [ "$links" != "" ]; then
sleep 5
fi
2021-10-16 17:49:19 +02:00
$exec_command rm -f zabbix-$app_component
2018-06-07 05:47:07 +02:00
2022-08-05 09:42:15 +02:00
$exec_command run --name zabbix-$app_component -t -d "$links" "${env_vars[@]}" "zabbix-$app_component:$os-$version"
2021-10-16 17:49:19 +02:00
fi