|
| 1 | +// Variables with defaults that can be overridden |
| 2 | +variable "REGISTRY" { |
| 3 | + default = "ghcr.io" |
| 4 | +} |
| 5 | + |
| 6 | +variable "IMAGE_NAME" { |
| 7 | + default = "mvp" |
| 8 | +} |
| 9 | + |
| 10 | +variable "TAG" { |
| 11 | + default = "latest" |
| 12 | +} |
| 13 | + |
| 14 | +// Base target with shared configuration |
| 15 | +target "docker-metadata-action" { |
| 16 | + tags = [ |
| 17 | + "${REGISTRY}/${IMAGE_NAME}:${TAG}", |
| 18 | + "${REGISTRY}/${IMAGE_NAME}:latest", |
| 19 | + ] |
| 20 | +} |
| 21 | + |
| 22 | +// Default target that extends the base |
| 23 | +target "build" { |
| 24 | + inherits = ["docker-metadata-action"] |
| 25 | + context = "." |
| 26 | + dockerfile = "Dockerfile" |
| 27 | + // Platform will be set from GitHub Actions |
| 28 | + // cache-from and cache-to will also be set from GitHub Actions |
| 29 | + args = { |
| 30 | + PYTHON_VERSION = "3.12.10" |
| 31 | + // Additional build args can be defined here |
| 32 | + } |
| 33 | + // Output image will be pushed if push=true is set in GitHub Actions |
| 34 | +} |
| 35 | + |
| 36 | +// Group target to build both platforms |
| 37 | +group "default" { |
| 38 | + targets = ["build"] |
| 39 | +} |
| 40 | + |
| 41 | +// Optional specific targets for each platform if needed |
| 42 | +target "amd64" { |
| 43 | + inherits = ["build"] |
| 44 | + platforms = ["linux/amd64"] |
| 45 | + cache-from = ["type=gha,scope=linux/amd64"] |
| 46 | + cache-to = ["type=gha,mode=max,scope=linux/amd64"] |
| 47 | +} |
| 48 | + |
| 49 | +target "arm64" { |
| 50 | + inherits = ["build"] |
| 51 | + platforms = ["linux/arm64"] |
| 52 | + cache-from = ["type=gha,scope=linux/arm64"] |
| 53 | + cache-to = ["type=gha,mode=max,scope=linux/arm64"] |
| 54 | + // Optional arm64-specific args |
| 55 | + args = { |
| 56 | + PYTHON_VERSION = "3.12.10" |
| 57 | + OPENBLAS_NUM_THREADS = "1" |
| 58 | + MKL_NUM_THREADS = "1" |
| 59 | + NUMEXPR_NUM_THREADS = "1" |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +// Matrix build target if you prefer to use it directly in bake |
| 64 | +target "multi-platform" { |
| 65 | + inherits = ["build"] |
| 66 | + platforms = ["linux/amd64", "linux/arm64"] |
| 67 | +} |
0 commit comments