forked from bottlerocket-os/bottlerocket-control-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (51 loc) · 2.37 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# IMAGE_NAME is the full name of the container image being built.
IMAGE_NAME ?= $(notdir $(shell pwd -P))$(IMAGE_ARCH_SUFFIX):$(IMAGE_VERSION)$(addprefix -,$(SHORT_SHA))
# IMAGE_VERSION is the semver version that's tagged on the image.
IMAGE_VERSION = $(shell cat VERSION)
# SHORT_SHA is the revision that the container image was built with.
SHORT_SHA ?= $(shell git describe --abbrev=8 --always --dirty='-dev' --exclude '*' || echo "unknown")
# IMAGE_ARCH_SUFFIX is the runtime architecture designator for the container
# image, it is appended to the IMAGE_NAME unless the name is specified.
IMAGE_ARCH_SUFFIX ?= $(addprefix -,$(ARCH))
# DESTDIR is where the release artifacts will be written.
DESTDIR ?= .
# DISTFILE is the path to the dist target's output file - the container image
# tarball.
DISTFILE ?= $(subst /,,$(DESTDIR))/$(subst /,_,$(IMAGE_NAME)).tar.gz
# These values derive ARCH and DOCKER_ARCH which are needed by dependencies in
# image build defaulting to system's architecture when not specified.
#
# UNAME_ARCH is the runtime architecture of the building host.
UNAME_ARCH = $(shell uname -m)
# ARCH is the target architecture which is being built for.
ARCH ?= $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:amd64 aarch64:arm64)))
# DOCKER_ARCH is the docker specific architecture specifier used for building on
# multiarch container images.
DOCKER_ARCH ?= $(lastword $(subst :, ,$(filter $(ARCH):%,amd64:amd64 arm64:arm64v8)))
# SSM_AGENT_VERSION is the SSM Agent's distributed RPM Version to install.
SSM_AGENT_VERSION ?= 3.1.192.0
.PHONY: all build check check-static-bash
# Run all build tasks for this container image.
all: build check
# Create a distribution container image tarball for release.
dist: all
@mkdir -p $(dir $(DISTFILE))
docker save $(IMAGE_NAME) | gzip > $(DISTFILE)
# Build the container image.
build:
docker build \
--tag $(IMAGE_NAME) \
--build-arg IMAGE_VERSION="$(IMAGE_VERSION)" \
--build-arg ARCH="$(ARCH)" \
--build-arg DOCKER_ARCH="$(DOCKER_ARCH)" \
--build-arg SSM_AGENT_VERSION="$(SSM_AGENT_VERSION)" \
-f Dockerfile . >&2
# Run checks against the container image.
check: check-ssm-agent
# Check that the SSM Agent is the expected version.
check-ssm-agent:
docker run --rm --entrypoint /usr/bin/bash \
$(IMAGE_NAME) \
-c 'rpm -q amazon-ssm-agent --queryformat "%{version}\n" | grep -qFw "$(SSM_AGENT_VERSION)"' >&2
clean:
rm -f $(DISTFILE)