forked from groundnuty/k8s-wait-for
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
33 lines (27 loc) · 1.26 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
TAG = $(shell git rev-parse HEAD)
REPO_NAME = $(shell git config --get remote.origin.url | sed 's/\.git$$//' | tr ':.' '/' | rev | cut -d '/' -f 1 | rev)
BUILD_DATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
BUILD_FLAGS := $(if $(BUILD_FLAGS),$(BUILD_FLAGS),--load --no-cache)
BUILDER_NAME = k8s-wait-for-builder
NON_ROOT_DOCKERFILE = DockerfileNonRoot
DOCKER_TAGS = $(REPO_NAME):$(TAG_PREFIX)latest $(REPO_NAME):$(TAG_PREFIX)$(TAG)
images: image-root image-non-root
image-root: image-root
image-non-root: TAG_PREFIX = no-root-
image-non-root: BUILD_FLAGS += --file=$(NON_ROOT_DOCKERFILE)
image-non-root: generate-non-root-dockerfile
generate-non-root-dockerfile:
sed -e '/# Replace for non-root version/ {' -e 'n' -e 'r DockerfileNonRoot.snipset' -e 'd' -e '}' Dockerfile > $(NON_ROOT_DOCKERFILE)
image-%:
@echo TARGET IS $(TARGET)
if ! docker buildx inspect $(BUILDER_NAME) 2> /dev/null ; then docker buildx create --name $(BUILDER_NAME) ; fi
docker buildx build \
--builder=$(BUILDER_NAME) \
--platform=linux/amd64 \
$(BUILD_FLAGS) \
$(foreach TAG,$(DOCKER_TAGS),--tag $(TAG)) \
.
clean:
rm -f $(NON_ROOT_DOCKERFILE)
if docker buildx inspect $(BUILDER_NAME) 2> /dev/null ; then docker buildx rm $(BUILDER_NAME) ; fi
$(foreach TAG,$(DOCKER_TAGS),docker rmi -f $(TAG); )