Files
bestofpb/scripts/build-images.sh
2025-12-23 17:41:30 -08:00

52 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Usage: ./scripts/build-images.sh [version]
set -e
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):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 pb-backend:$VERSION ./backend
echo "Building frontend image..."
podman build --platform=linux/arm64 -t pb-frontend:$VERSION ./frontend
echo "\nBuild complete. Images:"
echo " pb-backend:$VERSION"
echo " pb-frontend:$VERSION"
echo "\nSaving images to tar files:"
podman image save -o frontend.tar pb-frontend:$VERSION
podman image save -o backend.tar pb-backend:$VERSION