Skip to content

Commit

Permalink
using docker buildx for csi plugins
Browse files Browse the repository at this point in the history
Signed-off-by: SRIKUMAR VENUGOPAL <[email protected]>
  • Loading branch information
srikumar003 committed Nov 21, 2024
1 parent 2cce833 commit e81a024
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 21 deletions.
81 changes: 62 additions & 19 deletions build-tools/build_csi_plugins.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,76 @@
#!/bin/bash

set -e

print_usage() {
echo "Usage: $0 [-p]"
echo "Usage: $0 [-k] [-p] [-s]"
echo "Use -k to avoid creating another buildx context"
echo "Use -p to build and push multiarch images"
echo "Use -s to skip logging in to the container registry"
}

MAKE_ARGS="build-csi-plugins"

while getopts 'p' PUSH
BUILD_AND_PUSH="no"
CREATE_NEW_BUILDX_CONTEXT="yes"
SKIP_LOGIN="no"
while getopts 'kps' OPTION
do
case "$PUSH" in
p)
MAKE_ARGS+=" push-csi-plugins"
;;
esac
case "$OPTION" in
k)
CREATE_NEW_BUILDX_CONTEXT="no"
;;
p)
BUILD_AND_PUSH="yes"
;;
s)
SKIP_LOGIN="yes"
;;
?)
print_usage >&2
exit 1
;;
esac
done

if [ -n "$DOCKER_REGISTRY" ]
shift $((OPTIND-1))

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

DOCKERCMD="docker"
ALTDOCKERCMD="podman"
if !(command -v ${DOCKERCMD} &> /dev/null)
then
#MAKE_ARGS+=" push-csi-plugins"
:
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
DOCKER_REGISTRY="local"
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 [ ${DOCKERCMD} == "docker" ]
then
if [ $CREATE_NEW_BUILDX_CONTEXT = "yes" ]; then
docker buildx create --use
fi
fi

export ARCH=`arch`;
if [ "$ARCH" == "x86_64" ]; then export ARCH="amd64"; fi
if [ "$ARCH" == "i386" ]; then export ARCH="amd64"; fi
if [ "$ARCH" == "aarch64" ]; then export ARCH="arm64"; fi
make ARCH=$ARCH DOCKER_REGISTRY=$DOCKER_REGISTRY $MAKE_ARGS
if [ $BUILD_AND_PUSH = "yes" ]; then
if [ $SKIP_LOGIN = "no" ]; then
echo $REGISTRY_PASSWORD | docker login -u $REGISTRY_USERNAME --password-stdin $REGISTRY_URL
fi
(cd ../src/csi-s3 && ./build_multiarch_csis3.sh -p $REGISTRY_URL $VERSION)
(cd ../src/csi-nfs && ./build_multiarch_csinfs.sh -p $REGISTRY_URL $VERSION)
else
(cd ../src/csi-s3 && ./build_multiarch_csis3.sh $REGISTRY_URL $VERSION)
(cd ../src/csi-nfs && ./build_multiarch_csinfs.sh $REGISTRY_URL $VERSION)
fi
83 changes: 82 additions & 1 deletion src/csi-driver-nfs/build_and_push_multiarch_csinfs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +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 buildx build --platform linux/amd64,linux/arm64,linux/ppc64le --push -t ${REGISTRY_URL}/csi-nfs:${VERSION} .

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

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

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

podman_push () {
podman manifest push ${REGISTRY_URL}/csi-nfs:${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
83 changes: 82 additions & 1 deletion src/csi-s3/build_and_push_multiarch_csis3.sh
Original file line number Diff line number Diff line change
@@ -1,5 +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 buildx build --platform linux/amd64,linux/arm64,linux/ppc64le --network host --push -t ${REGISTRY_URL}/csi-s3:${VERSION} -f ./cmd/s3driver/Dockerfile .

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

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

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

podman_push () {
podman manifest push ${REGISTRY_URL}/csi-s3:${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 e81a024

Please sign in to comment.