update docker publish script

This commit is contained in:
Saeed Vaziry 2025-02-26 21:22:59 +01:00
parent 7cda14cb76
commit f54c754971

View File

@ -1,21 +1,54 @@
#!/bin/bash
TAG=$1
BRANCH=""
TAGS=()
if [ -z "$TAG" ]; then
echo "No tag provided"
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--branch)
BRANCH="$2"
shift 2
;;
--tags)
IFS=',' read -r -a TAGS <<< "$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Validate inputs
if [ -z "$BRANCH" ]; then
echo "No branch provided. Use --branch <git_branch>"
exit 1
fi
if [ ${#TAGS[@]} -eq 0 ]; then
echo "No tags provided. Use --tags tag1,tag2,tag3"
exit 1
fi
# Clone the specified branch of the repo
rm -rf /tmp/vito
git clone git@github.com:vitodeploy/vito.git /tmp/vito
git clone --branch "$BRANCH" --depth 1 git@github.com:vitodeploy/vito.git /tmp/vito
cd /tmp/vito || exit
# Prepare tag arguments for docker buildx
TAG_ARGS=()
for TAG in "${TAGS[@]}"; do
# Trim whitespace to avoid invalid tag formatting
TAG_CLEANED=$(echo -n "$TAG" | xargs)
TAG_ARGS+=("-t" "vitodeploy/vito:$TAG_CLEANED")
done
# Build and push the image
docker buildx build . \
-f docker/Dockerfile \
-t vitodeploy/vito:"$TAG" \
"${TAG_ARGS[@]}" \
--platform linux/amd64,linux/arm64 \
--no-cache \
--push