11# ==============================================================================
22# Project: Python Build System (Containerized & Secured)
3- # Description: Multi-stage build system with caching and security gates.
43# ==============================================================================
54
65# --- Configuration & Defaults -------------------------------------------------
1413 Q :=
1514endif
1615
17- # --- Versioning ---------------------------------------------------------------
16+ # Versioning
1817PYTHON_VERSION ?= 3.13.3
1918ACTIONS_PYTHON_VERSIONS ?= 3.13.3-14344076652
2019POWERSHELL_VERSION ?= v7.5.2
2120POWERSHELL_NATIVE_VERSION ?= v7.4.0
2221UBUNTU_VERSION ?= 24.04
2322
24- # --- Security Scanning --------------------------------------------------------
25- # Latest Trivy version (Dec 2025)
26- TRIVY_VERSION ?= v0.68.2
27-
28- # Gates: 0 = Log Only, 1 = Fail Build
23+ # Security Scanning & Gates
24+ TRIVY_VERSION ?= v0.58.1
2925FAIL_ON_CRITICAL ?= 1
3026FAIL_ON_HIGH ?= 1
3127FAIL_ON_MEDIUM ?= 0
3228FAIL_ON_SECRET ?= 1
3329
34- # --- System Architecture ------------------------------------------------------
30+ # Architecture
3531ARCH_RAW := $(shell uname -m)
3632ifeq ($(ARCH_RAW ) ,x86_64)
3733 ARCH := amd64
4137 ARCH := $(ARCH_RAW )
4238endif
4339
44- # --- Container Engine ---------------------------------------------------------
40+ # Container Engine
4541CONTAINER_ENGINE := $(shell command -v podman 2>/dev/null || command -v docker)
4642ifeq ($(strip $(CONTAINER_ENGINE ) ) ,)
4743 $(error No container runtime found. Please install `docker` or `podman`)
4844endif
4945
5046# --- Internal Variables -------------------------------------------------------
5147
52- # The base image tag used internally between stages
5348BASE_IMAGE := powershell:ubuntu-$(UBUNTU_VERSION )
5449
5550OUTPUT_DIR := python-versions/output
5651IMAGE_NAME := python:$(PYTHON_VERSION ) -ubuntu-$(UBUNTU_VERSION ) -$(ARCH )
5752TEMP_CONTAINER_NAME := python-build-$(PYTHON_VERSION ) -$(ARCH ) -tmp
5853
59- # Artifact filenames
6054INTERNAL_ARTIFACT_NAME := python-$(PYTHON_VERSION ) -linux-$(ARCH ) .tar.gz
6155HOST_ARTIFACT_NAME := python-$(PYTHON_VERSION ) -linux-$(UBUNTU_VERSION ) -$(ARCH ) .tar.gz
6256
@@ -69,13 +63,13 @@ PS_PREREQS := \
6963
7064# --- Build Strategy Logic -----------------------------------------------------
7165
72- # Default: Standard local build (Works for local dev)
66+ # Default: Standard local build
7367BUILD_CMD := $(CONTAINER_ENGINE ) build
7468BUILD_OPTS :=
7569
7670# GHA Override: Use Buildx with Caching
77- # Critical Fix: We use '--load' to ensure the built image is exported
78- # from the isolated BuildKit container to the local Docker daemon.
71+ # [CRITICAL FIX] We utilize specific scopes per target in the recipes below
72+ # and rely on '--load' to export the image to the local daemon.
7973ifeq ($(USE_GHA_CACHE ) ,1)
8074 BUILDX_BUILDER ?= gha-builder
8175 BUILD_CMD := $(CONTAINER_ENGINE ) buildx build
8983all : $(OUTPUT_DIR ) /$(HOST_ARTIFACT_NAME ) verify-gate
9084
9185# 1. Build the Python Artifact (Stage 2)
92- # Depends on 'powershell' target being run first to create the BASE_IMAGE
9386$(OUTPUT_DIR ) /$(HOST_ARTIFACT_NAME ) : powershell | $(OUTPUT_DIR )
9487 @echo " --- Building Python $( PYTHON_VERSION) Image ($( ARCH) ) ---"
9588 @echo " Security Gate: CRIT=$( FAIL_ON_CRITICAL) HIGH=$( FAIL_ON_HIGH) SECRET=$( FAIL_ON_SECRET) "
@@ -143,7 +136,7 @@ verify-gate:
143136 fi
144137
145138# 3. Build Base PowerShell Image (Stage 1)
146- # Uses separate cache scope to prevent overwriting the Python cache
139+ # [CRITICAL] This forces the build to load into local Docker so Stage 2 can see it
147140powershell : $(PS_PREREQS )
148141 @echo " --- Building PowerShell Base Image ---"
149142 $(Q ) cd $(PS_DIR ) && $(BUILD_CMD ) $(BUILD_OPTS ) \
0 commit comments