|
1 | | -IMAGE_NAME = bottlerocket-bootstrap-container:latest |
| 1 | +# IMAGE_NAME is the full name of the container image being built. |
| 2 | +IMAGE_NAME ?= $(notdir $(shell pwd -P))$(IMAGE_ARCH_SUFFIX):$(IMAGE_VERSION)$(addprefix -,$(SHORT_SHA)) |
| 3 | +# IMAGE_VERSION is the semver version that's tagged on the image. |
| 4 | +IMAGE_VERSION = $(shell cat VERSION) |
| 5 | +# SHORT_SHA is the revision that the container image was built with. |
| 6 | +SHORT_SHA ?= $(shell git describe --abbrev=8 --always --dirty='-dev' --exclude '*' || echo "unknown") |
| 7 | +# IMAGE_ARCH_SUFFIX is the runtime architecture designator for the container |
| 8 | +# image, it is appended to the IMAGE_NAME unless the name is specified. |
| 9 | +IMAGE_ARCH_SUFFIX ?= $(addprefix -,$(ARCH)) |
| 10 | +# DESTDIR is where the release artifacts will be written. |
| 11 | +DESTDIR ?= . |
| 12 | +# DISTFILE is the path to the dist target's output file - the container image |
| 13 | +# tarball. |
| 14 | +DISTFILE ?= $(subst /,,$(DESTDIR))/$(subst /,_,$(IMAGE_NAME)).tar.gz |
2 | 15 |
|
3 | | -.PHONY: all build clean |
| 16 | +UNAME_ARCH = $(shell uname -m) |
| 17 | +ARCH ?= $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:amd64 aarch64:arm64))) |
4 | 18 |
|
5 | | -# Run all build tasks for this container image |
6 | | -all: build_amd64 build_arm64 |
| 19 | +.PHONY: all build dist clean |
7 | 20 |
|
8 | | -# Build the container image for the amd64 architecture |
9 | | -build_amd64: |
10 | | - docker build --tag $(IMAGE_NAME)-amd64 -f Dockerfile . |
| 21 | +# Run all build tasks for this container image. |
| 22 | +all: build |
11 | 23 |
|
12 | | -# Build the container image for the arm64 architecture |
13 | | -build_arm64: |
14 | | - docker build --tag $(IMAGE_NAME)-arm64 -f Dockerfile . |
| 24 | +# Create a distribution container image tarball for release. |
| 25 | +dist: all |
| 26 | + @mkdir -p $(dir $(DISTFILE)) |
| 27 | + docker save $(IMAGE_NAME) | gzip > $(DISTFILE) |
| 28 | + |
| 29 | +# Build the container image. |
| 30 | +build: |
| 31 | + DOCKER_BUILDKIT=1 docker build $(DOCKER_BUILD_FLAGS) \ |
| 32 | + --tag $(IMAGE_NAME) \ |
| 33 | + --build-arg IMAGE_VERSION="$(IMAGE_VERSION)" \ |
| 34 | + -f Dockerfile . >&2 |
15 | 35 |
|
16 | | -# Clean up the build artifacts (if there are any to clean) |
17 | 36 | clean: |
18 | | - rm -f $(IMAGE_NAME) |
| 37 | + rm -f $(DISTFILE) |
0 commit comments