mirror of
https://github.com/zokradonh/kopano-docker
synced 2025-06-25 16:56:38 +00:00
Improved build script, likely supporting kopano_version_watch
This commit is contained in:
parent
cd4d3caf79
commit
df8f8fdef8
129
build.sh
129
build.sh
@ -2,16 +2,57 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
if [ $# -lt 2 ]
|
branch="master"
|
||||||
then
|
buildcontext_base="https://github.com/zokradonh/kopano-docker.git#:"
|
||||||
echo "Usage: build.sh core|webapp serial [master|final|pre-final] [buildcontext]"
|
networkname="buildproxy_net"
|
||||||
echo "Example: build.sh core ABC123456789DEF final"
|
customBuildArgs=()
|
||||||
echo "If no branch is given, 'master' will be built by default."
|
serial=""
|
||||||
echo "If no buildcontext is given, it will build from git repository. Normally, you do not need to specify this."
|
component=""
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$1" in
|
function _usage()
|
||||||
|
{
|
||||||
|
echo "Usage: build.sh -c core|webapp [-s serial] [-b master|final|pre-final] [-p buildcontext] [-n networkname] [[-a buildarg] ...]"
|
||||||
|
echo "Example: build.sh -c core -s ABC123456789DEF -b final"
|
||||||
|
echo "If no branch is specified, 'master' will be built by default."
|
||||||
|
echo "If no buildcontext is specified, it will be built from git repository. Normally, you do not need to specify this."
|
||||||
|
echo "If no networkname is specified, it will create and use a network named 'buildproxy_net'."
|
||||||
|
echo "You can specify custom build args via e.g. -a KOPANO_CORE_REPOSITORY_URL=http://thisismy/url -a KOPANO_WEBAPP_REPOSITORY_URL=http://thisismy/url."
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts ":s:c:b:p:n:a:" opt; do
|
||||||
|
case $opt in
|
||||||
|
s)
|
||||||
|
serial=$OPTARG
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
component=${OPTARG,,}
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
branch=${OPTARG,,}
|
||||||
|
;;
|
||||||
|
p)
|
||||||
|
buildcontext_base=$OPTARG
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
networkname=$OPTARG
|
||||||
|
;;
|
||||||
|
a)
|
||||||
|
customBuildArgs[${#customBuildArgs[*]}]=$OPTARG
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo "Option -$OPTARG requires an argument."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
case "$component" in
|
||||||
core)
|
core)
|
||||||
mainpackage="kopano-server"
|
mainpackage="kopano-server"
|
||||||
;;
|
;;
|
||||||
@ -19,32 +60,40 @@ case "$1" in
|
|||||||
mainpackage="kopano-webapp"
|
mainpackage="kopano-webapp"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid component."
|
_usage
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
component=${1,,}
|
if [ ! -z "$serial" ]
|
||||||
serial=$2
|
|
||||||
branch=${3-master}
|
|
||||||
branch=${branch,,}
|
|
||||||
defaulturl="https://github.com/ZokRadonh/KopanoDocker.git#:"
|
|
||||||
buildcontext_base="${4-${defaulturl}}"
|
|
||||||
|
|
||||||
# get current version to brand and tag the image correctly
|
|
||||||
currentVersion=$(curl -s -S -L https://serial:$serial@download.kopano.io/supported/$component:/$branch/Debian_9.0/Packages.gz |\
|
|
||||||
gzip -d | grep -A 8 "^Package: $mainpackage$" | awk '/Version/ { print $2 }')
|
|
||||||
|
|
||||||
currentVersionDocker=$(echo $currentVersion | sed 's/+/plus/')
|
|
||||||
|
|
||||||
# check if buildproxy helper container is running
|
|
||||||
isproxyup=$(docker ps | grep kopano_buildproxy | wc -l)
|
|
||||||
|
|
||||||
if [ $isproxyup -eq 0 ]
|
|
||||||
then
|
then
|
||||||
echo "Build proxy container not runnning - now building..."
|
# get current version to brand and tag the image correctly
|
||||||
docker build -t kopano_buildproxy ${buildcontext_base}repoproxy
|
currentVersion=$(curl -s -S -L https://serial:$serial@download.kopano.io/supported/$component:/$branch/Debian_9.0/Packages.gz |\
|
||||||
echo "Start buildproxy helper..."
|
gzip -d | grep -A 8 "^Package: $mainpackage$" | awk '/Version/ { print $2 }')
|
||||||
docker run --rm -ti -d -e KOPANO_SERIAL=$serial --network buildkopano_bnet --network-alias buildproxy kopano_buildproxy
|
|
||||||
|
currentVersionDocker=$(echo $currentVersion | sed 's/+/plus/')
|
||||||
|
|
||||||
|
# check existence of network
|
||||||
|
isnetup=$(docker network ls | grep $networkname | wc -l)
|
||||||
|
|
||||||
|
if [ $isnetup -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Missing build network. Creating network $networkname..."
|
||||||
|
docker network create --attachable $networkname
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check if buildproxy helper container is running
|
||||||
|
isproxyup=$(docker ps | grep kopano_buildproxy | wc -l)
|
||||||
|
|
||||||
|
if [ $isproxyup -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Build proxy container not runnning - now building..."
|
||||||
|
docker build -t kopano_buildproxy ${buildcontext_base}repoproxy
|
||||||
|
echo "Start buildproxy helper..."
|
||||||
|
proxyContainerId=$(docker run --rm -ti -d -e KOPANO_SERIAL=$serial --network $networkname --network-alias buildproxy kopano_buildproxy)
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
currentVersion="newest"
|
||||||
|
currentVersionDocker="custom"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# only tag the master branch with ":latest"
|
# only tag the master branch with ":latest"
|
||||||
@ -55,13 +104,27 @@ else
|
|||||||
tagLatest=" "
|
tagLatest=" "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
customBuildString=""
|
||||||
|
# prepare custom build args
|
||||||
|
for buildArg in "${customBuildArgs[@]}"
|
||||||
|
do
|
||||||
|
customBuildString="$customBuildString --build-arg $buildArg"
|
||||||
|
done
|
||||||
|
|
||||||
# build it
|
# build it
|
||||||
echo "Start building kopano $component image version ($currentVersion)..."
|
echo "Start building kopano $component image version ($currentVersion)..."
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg KOPANO_REPOSITORY_BRANCH=$branch \
|
--build-arg KOPANO_REPOSITORY_BRANCH=$branch \
|
||||||
--build-arg KOPANO_${component^^}_VERSION=$currentVersion \
|
--build-arg KOPANO_${component^^}_VERSION=$currentVersion \
|
||||||
|
$customBuildString \
|
||||||
$tagLatest \
|
$tagLatest \
|
||||||
-t zokradonh/kopano_$component:$currentVersionDocker \
|
-t zokradonh/kopano_$component:$currentVersionDocker \
|
||||||
-t zokradonh/kopano_$component:latest-$branch \
|
-t zokradonh/kopano_$component:latest-$branch \
|
||||||
--network buildkopano_bnet \
|
--network $networkname \
|
||||||
${buildcontext_base}${component}
|
${buildcontext_base}${component}
|
||||||
|
|
||||||
|
# stop proxy container if we started it
|
||||||
|
if [ ! -z "$proxyContainerId" ]
|
||||||
|
then
|
||||||
|
docker stop $proxyContainerId
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user