60 lines
1.9 KiB
Bash
Executable File
60 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Usage: ./scripts/build-images.sh [version]
|
|
|
|
set -e
|
|
|
|
HARBOR_REGISTRY="harbor.scottyah.com/bestofpb"
|
|
|
|
get_latest_version() {
|
|
# Get the latest version tag from podman images for pb-backend or pb-frontend
|
|
podman images --format '{{.Repository}}:{{.Tag}}' | \
|
|
grep -E '(pb-(backend|frontend)|harbor\.scottyah\.com/bestofpb/pb-(backend|frontend)):v[0-9]+\.[0-9]+\.[0-9]+' | \
|
|
sed -E 's/.*:(v[0-9]+\.[0-9]+\.[0-9]+)$/\1/' | \
|
|
sort -V | tail -n 1
|
|
}
|
|
|
|
increment_minor_version() {
|
|
# Takes a version string like v1.2.3 and increments the minor version
|
|
local version=$1
|
|
local major_minor_patch=$(echo $version | sed -E 's/v([0-9]+)\.([0-9]+)\.([0-9]+)/\1 \2 \3/')
|
|
set -- $major_minor_patch
|
|
local major=$1
|
|
local minor=$2
|
|
local patch=$3
|
|
minor=$((minor + 1))
|
|
echo "v${major}.${minor}.0"
|
|
}
|
|
|
|
if [ -z "$1" ]; then
|
|
LATEST=$(get_latest_version)
|
|
if [ -z "$LATEST" ]; then
|
|
VERSION="v1.0.0"
|
|
else
|
|
VERSION=$(increment_minor_version $LATEST)
|
|
fi
|
|
echo "No version argument provided. Using auto-incremented version: $VERSION"
|
|
else
|
|
VERSION=$1
|
|
fi
|
|
|
|
# Build backend image
|
|
echo "Building backend image..."
|
|
podman build --platform=linux/arm64 -t ${HARBOR_REGISTRY}/pb-backend:$VERSION ./backend
|
|
podman tag ${HARBOR_REGISTRY}/pb-backend:$VERSION ${HARBOR_REGISTRY}/pb-backend:latest
|
|
|
|
echo "Building frontend image..."
|
|
podman build --platform=linux/arm64 -t ${HARBOR_REGISTRY}/pb-frontend:$VERSION ./frontend
|
|
podman tag ${HARBOR_REGISTRY}/pb-frontend:$VERSION ${HARBOR_REGISTRY}/pb-frontend:latest
|
|
|
|
echo "\nBuild complete. Images:"
|
|
echo " ${HARBOR_REGISTRY}/pb-backend:$VERSION"
|
|
echo " ${HARBOR_REGISTRY}/pb-frontend:$VERSION"
|
|
|
|
echo "\nPushing images to Harbor..."
|
|
podman push ${HARBOR_REGISTRY}/pb-backend:$VERSION
|
|
podman push ${HARBOR_REGISTRY}/pb-backend:latest
|
|
podman push ${HARBOR_REGISTRY}/pb-frontend:$VERSION
|
|
podman push ${HARBOR_REGISTRY}/pb-frontend:latest
|
|
|
|
echo "\nImages pushed successfully to Harbor registry" |