diff --git a/images/mod.just b/images/mod.just index 17ba711..96f8ec6 100644 --- a/images/mod.just +++ b/images/mod.just @@ -74,45 +74,38 @@ build project="" tag="" local="false": # For podman, build for each platform and create manifest IFS=',' read -ra PLATFORM_ARRAY <<< "$platforms" - # Build for each platform - for platform in "${PLATFORM_ARRAY[@]}"; do - echo -e "{{BLUE}}Building for platform: $platform{{NORMAL}}" - platform_tag="${image_name}-${platform//\//-}" + # For multi-platform builds with podman, build locally only for current platform + echo -e "{{BLUE}}Multi-platform build detected, building for local platform only{{NORMAL}}" - $runtime buildx build \ - --platform "$platform" \ - -f "$containerfile" \ - -t "$platform_tag" \ - --load \ - "$build_context" + # Detect local platform + if [ "$(uname -m)" = "x86_64" ]; then + local_platform="linux/amd64" + elif [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then + local_platform="linux/arm64" + else + local_platform="linux/amd64" + fi - # Push platform-specific image - $runtime push "$platform_tag" - done + echo -e "{{BLUE}}Building for local platform: $local_platform{{NORMAL}}" - # Create and push manifest - echo -e "{{BLUE}}Creating multi-platform manifest{{NORMAL}}" + $runtime buildx build \ + --platform "$local_platform" \ + -f "$containerfile" \ + -t "$image_name" \ + --load \ + "$build_context" - # Remove existing manifest if it exists - $runtime manifest rm "$image_name" 2>/dev/null || true - - manifest_cmd="$runtime manifest create $image_name" - for platform in "${PLATFORM_ARRAY[@]}"; do - platform_tag="${image_name}-${platform//\//-}" - manifest_cmd="$manifest_cmd $platform_tag" - done - eval "$manifest_cmd" - - echo -e "{{BLUE}}Pushing multi-platform manifest to registry{{NORMAL}}" - $runtime manifest push "$image_name" + echo -e "{{GREEN}}✓ Local build completed: $image_name{{NORMAL}}" + echo -e "{{YELLOW}}Note: For multi-platform registry deployment, use 'just images push'{{NORMAL}}" else if [[ "$platforms" == *","* ]]; then # Local build requested for multi-platform - use local platform only - local_platform="linux/$(uname -m)" if [ "$(uname -m)" = "x86_64" ]; then local_platform="linux/amd64" elif [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then local_platform="linux/arm64" + else + local_platform="linux/amd64" fi echo -e "{{BLUE}}Local-only build (from multi-platform): $local_platform{{NORMAL}}" platforms="$local_platform" @@ -213,23 +206,57 @@ push project="" tag="": echo -e "{{GREEN}}✓ Successfully pushed both commit and latest tags{{NORMAL}}" else - # Regular tag push + # Regular tag push - build and push multi-platform to registry image_name=$(just _get_image_name "$tag") - # Check if the image exists locally - if ! $runtime images "$image_name" >/dev/null 2>&1; then - echo "{{BOLD}}{{RED}}Error:{{NORMAL}} Image $image_name not found locally" >&2 - echo "{{YELLOW}}Build the image first with: just images build{{NORMAL}}" >&2 - echo "{{YELLOW}}Available images:{{NORMAL}}" >&2 - image_base=$(just _get_image_name "") - $runtime images | grep "$image_base" || echo "No images found for project: $project" >&2 - exit 1 - fi + echo -e "{{BLUE}}Building and pushing multi-platform image: $image_name{{NORMAL}}" - echo -e "{{BLUE}}Pushing image: $image_name{{NORMAL}}" - $runtime push "$image_name" + # Auto-discover containerfile + containerfile_info=$(just _discover_containerfile) + read -r containerfile project_name build_context <<< "$containerfile_info" - echo -e "{{GREEN}}✓ Successfully pushed: $image_name{{NORMAL}}" + # Detect platforms + platforms=$(just _detect_platforms "$containerfile") + echo -e "{{BLUE}}Platforms: $platforms{{NORMAL}}" + + # Build for each platform and push to registry + IFS=',' read -ra PLATFORM_ARRAY <<< "$platforms" + + for platform in "${PLATFORM_ARRAY[@]}"; do + echo -e "{{BLUE}}Building and pushing for platform: $platform{{NORMAL}}" + platform_tag="${image_name}-${platform//\//-}" + + $runtime buildx build \ + --platform "$platform" \ + -f "$containerfile" \ + -t "$platform_tag" \ + "$build_context" + + # Push platform-specific image to registry + $runtime push "$platform_tag" + done + + # Create and push manifest from registry images + echo -e "{{BLUE}}Creating multi-platform manifest{{NORMAL}}" + $runtime manifest rm "$image_name" 2>/dev/null || true + + manifest_cmd="$runtime manifest create $image_name" + for platform in "${PLATFORM_ARRAY[@]}"; do + platform_tag="${image_name}-${platform//\//-}" + manifest_cmd="$manifest_cmd $platform_tag" + done + eval "$manifest_cmd" + + echo -e "{{BLUE}}Pushing multi-platform manifest to registry{{NORMAL}}" + $runtime manifest push "$image_name" + + # Clean up local platform-specific tags + for platform in "${PLATFORM_ARRAY[@]}"; do + platform_tag="${image_name}-${platform//\//-}" + $runtime rmi "$platform_tag" 2>/dev/null || true + done + + echo -e "{{GREEN}}✓ Successfully pushed multi-platform image: $image_name{{NORMAL}}" fi # Pull project image from registry