Skip to content

Commit

Permalink
feat: add cos-uploader build script
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Pomponio <[email protected]>
  • Loading branch information
AlessandroPomponio committed Jul 30, 2024
1 parent da435c8 commit 295f5fc
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/cos-uploader/build_multiarch_cos_uploader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
set -e

print_usage() {
echo "usage: $0 [-p] <REGISTRY_URL> <VERSION>"
echo "Use -p to build and push multiarch images"
}

PUSH="false"
while getopts 'p' flag; do
case "$flag" in
p)
PUSH="true"
;;
?)
print_usage >&2
exit 1
;;
esac
done

shift $((OPTIND-1))

REGISTRY_URL="${1:-quay.io/datashim-io}"
VERSION="${2:-latest}"

docker_build () {
docker buildx build --platform linux/amd64 -t ${REGISTRY_URL}/cos-uploader:${VERSION} .
docker buildx build --load -t ${REGISTRY_URL}/cos-uploader:${VERSION} .
}

docker_build_and_push () {
docker buildx build --platform linux/amd64,linux/arm64 --push -t ${REGISTRY_URL}/cos-uploader:${VERSION} .
}

podman_build () {
podman manifest create ${REGISTRY_URL}/cos-uploader:${VERSION}
podman buildx build --platform linux/amd64,linux/arm64 --manifest ${REGISTRY_URL}/cos-uploader:${VERSION} .
}

podman_push () {
podman manifest push ${REGISTRY_URL}/cos-uploader:${VERSION}

}

DOCKERCMD="docker"
ALTDOCKERCMD="podman"
if !(command -v ${DOCKERCMD} &> /dev/null)
then
echo "Docker command not found"
if !(command -v ${ALTDOCKERCMD} &> /dev/null)
then
echo "Neither ${DOCKERCMD} nor ${ALTDOCKERCMD} commands found.. cannot build "
exit 1
else
DOCKERCMD=${ALTDOCKERCMD}
fi
else
echo "Docker command found"
cmd_type=$(type -t ${DOCKERCMD})
if [ $cmd_type == "alias" ]
then
echo "${DOCKERCMD} is an alias, switching to ${ALTDOCKERCMD}"
DOCKERCMD=${ALTDOCKERCMD}
fi
fi

if [ $PUSH == "true" ]
then
echo "pushing images to the registry"
if [ ${DOCKERCMD} == "docker" ]
then
docker_build_and_push
else
podman_build
podman_push
fi
else
echo "building image locally"
if [ ${DOCKERCMD} == "docker" ]
then
docker_build
else
podman_build
fi
fi

0 comments on commit 295f5fc

Please sign in to comment.