-
Notifications
You must be signed in to change notification settings - Fork 2
/
ContainerMakefile
50 lines (41 loc) · 1.68 KB
/
ContainerMakefile
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
LAST_COMMIT := $(shell git rev-parse HEAD | cut -c 1-7)
NAME := $(shell pwd | rev | cut -d '/' -f 1 | rev)-$(LAST_COMMIT)
TEMPDIR = ./.tmp
IMAGEDIRS = $(shell ls -d containers/* | cut -d '/' -f 2)
BOLD := $(shell tput -T linux bold)
PURPLE := $(shell tput -T linux setaf 5)
GREEN := $(shell tput -T linux setaf 2)
CYAN := $(shell tput -T linux setaf 6)
RED := $(shell tput -T linux setaf 1)
RESET := $(shell tput -T linux sgr0)
TITLE := $(BOLD)$(PURPLE)
SUCCESS := $(BOLD)$(GREEN)
define title
@printf '$(TITLE)$(1)$(RESET)\n'
endef
.PHONY: all
all: lint build
@printf '$(SUCCESS)All checks pass!$(RESET)\n'
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BOLD)$(CYAN)%-25s$(RESET)%s\n", $$1, $$2}'
.PHONY: lint
lint: ## TODO: with hadolint or similar
$(call title,Building container image anchore/test_image:$(NAME))
docker run --rm -i hadolint/hadolint hadolint --ignore DL3033 - < Dockerfile
.PHONY: build
build: ## build container with the current Dockerfile
# If a setup.sh is defined in the target's directory, then execute it. This is
# conditional because not all targets have a scripts/setup.sh
ifneq ("$(wildcard scripts/setup.sh)", "")
./scripts/setup.sh
endif
$(call title,Building container image anchore/test_image:$(NAME))
docker build -t anchore/test_images:$(NAME) .
.PHONY: push
push: build ## push built container to Docker Hub
$(call title,Pushing container image to docker hub anchore/test_image:$(NAME))
docker push anchore/test_images:$(NAME)
.PHONY: clean
clean: ## Remove images with the assigned tag for test_images
$(call title,Removing image anchore/test_image:$(NAME))
docker rmi anchore/test_images:$(NAME)