2021-02-10 11:58:02 -05:00
|
|
|
#!/bin/bash
|
2021-02-18 16:15:49 -05:00
|
|
|
# Official docker image build script.
|
2021-02-10 11:58:02 -05:00
|
|
|
|
2021-11-09 08:15:16 -05:00
|
|
|
# docker buildx create --name multiarch \
|
|
|
|
# --platform linux/arm/v7,linux/arm/v6,linux/arm64,linux/amd64 \
|
|
|
|
# --config ./buildkit.toml --use --driver-opt image=moby/buildkit:master
|
|
|
|
|
2021-02-18 18:59:08 -05:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat << EOF
|
|
|
|
usage: $0 options
|
|
|
|
|
|
|
|
OPTIONS:
|
2022-11-25 10:05:16 -05:00
|
|
|
-h Show help
|
2021-02-18 18:59:08 -05:00
|
|
|
-t The tag/version (${TAG}) (default = master)
|
|
|
|
-d Use Dockerfile-dev for a git clone build
|
2022-11-25 10:05:16 -05:00
|
|
|
-b Branch to use (default = master)
|
2022-12-12 19:29:45 -05:00
|
|
|
-r Destroy and rebuild the buildx environment
|
2021-02-18 18:59:08 -05:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ALL_PLATFORMS=0
|
|
|
|
DEV=0
|
2022-12-12 19:29:45 -05:00
|
|
|
REBUILD_BUILDX=0
|
2021-10-07 10:56:09 -04:00
|
|
|
TAG="latest"
|
2022-11-25 10:05:16 -05:00
|
|
|
BRANCH=${BRANCH:-master}
|
2022-12-12 19:29:45 -05:00
|
|
|
VERSION="2.6.0"
|
2021-02-18 18:59:08 -05:00
|
|
|
|
2022-12-12 19:29:45 -05:00
|
|
|
while getopts “hdart:b:v:” OPTION
|
2021-02-18 18:59:08 -05:00
|
|
|
do
|
|
|
|
case $OPTION in
|
|
|
|
t)
|
|
|
|
TAG=$OPTARG
|
|
|
|
;;
|
2021-10-07 10:56:09 -04:00
|
|
|
b)
|
|
|
|
BRANCH=$OPTARG
|
|
|
|
;;
|
2021-02-18 18:59:08 -05:00
|
|
|
a)
|
|
|
|
ALL_PLATFORMS=1
|
|
|
|
;;
|
2022-12-12 19:29:45 -05:00
|
|
|
r)
|
|
|
|
REBUILD_BUILDX=1
|
|
|
|
;;
|
2021-02-18 18:59:08 -05:00
|
|
|
d)
|
|
|
|
DEV=1
|
|
|
|
;;
|
2022-12-12 19:29:45 -05:00
|
|
|
v)
|
|
|
|
VERSION=$OPTARG
|
|
|
|
;;
|
2022-11-25 10:05:16 -05:00
|
|
|
h)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2021-02-18 18:59:08 -05:00
|
|
|
?)
|
|
|
|
usage
|
2022-11-25 10:05:16 -05:00
|
|
|
exit -1
|
2021-02-18 18:59:08 -05:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-02-16 10:05:11 -05:00
|
|
|
|
2021-02-18 18:59:08 -05:00
|
|
|
if [ $ALL_PLATFORMS -eq 1 ]
|
|
|
|
then
|
2021-11-09 08:15:16 -05:00
|
|
|
PLATFORMS="linux/arm/v7,linux/arm64,linux/amd64"
|
|
|
|
#PLATFORMS="linux/arm/v7,linux/arm/v6,linux/amd64"
|
2021-02-18 18:59:08 -05:00
|
|
|
else
|
2022-12-12 19:29:45 -05:00
|
|
|
PLATFORMS="linux/amd64"
|
2021-02-18 18:59:08 -05:00
|
|
|
fi
|
|
|
|
|
2021-10-07 10:56:09 -04:00
|
|
|
|
|
|
|
|
2022-12-12 19:29:45 -05:00
|
|
|
if [ $REBUILD_BUILDX -eq 1 ]
|
|
|
|
then
|
|
|
|
echo "Destroying old multiarch build container"
|
|
|
|
docker buildx rm multiarch
|
|
|
|
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
|
|
|
echo "Creating new buildx container"
|
|
|
|
docker buildx create --name multiarch --driver docker-container --use \
|
|
|
|
--config ./buildkit.toml --use \
|
|
|
|
--driver-opt image=moby/buildkit:master
|
|
|
|
docker buildx inspect --bootstrap
|
|
|
|
fi
|
2021-10-07 10:56:09 -04:00
|
|
|
|
2021-02-18 18:59:08 -05:00
|
|
|
if [ $DEV -eq 1 ]
|
|
|
|
then
|
2021-10-07 10:56:09 -04:00
|
|
|
echo "Build -DEV- with tag=${TAG} BRANCH=${BRANCH} platforms?=${PLATFORMS}"
|
2021-02-18 18:59:08 -05:00
|
|
|
# Use this script to locally build the docker image
|
|
|
|
docker buildx build --push --platform $PLATFORMS \
|
|
|
|
-t harbor.hemna.com/hemna6969/aprsd:$TAG \
|
2021-10-07 10:56:09 -04:00
|
|
|
-f Dockerfile-dev --build-arg branch=$BRANCH --no-cache .
|
2021-02-18 18:59:08 -05:00
|
|
|
else
|
|
|
|
# Use this script to locally build the docker image
|
2022-12-12 19:29:45 -05:00
|
|
|
echo "Build with tag=${TAG} BRANCH=${BRANCH} dev?=${DEV} platforms?=${PLATFORMS} VERSION=${VERSION}"
|
2021-02-18 18:59:08 -05:00
|
|
|
docker buildx build --push --platform $PLATFORMS \
|
2022-12-12 19:29:45 -05:00
|
|
|
--build-arg VERSION=$VERSION \
|
2021-02-18 18:59:08 -05:00
|
|
|
-t hemna6969/aprsd:$VERSION \
|
2021-10-07 10:56:09 -04:00
|
|
|
-t hemna6969/aprsd:$TAG \
|
2022-01-08 09:41:17 -05:00
|
|
|
-t hemna6969/aprsd:latest \
|
2021-02-18 18:59:08 -05:00
|
|
|
-f Dockerfile .
|
|
|
|
fi
|