-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
129 lines (111 loc) · 6.56 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
NAME ?= imperative-container
TAG ?= latest
CONTAINER ?= $(NAME):$(TAG)
DISABLE_LINTERS ?= "-e VALIDATE_SHELL_SHFMT=false"
REGISTRY ?= localhost
UPLOADREGISTRY ?= quay.io/hybridcloudpatterns
TESTCOMMAND := "set -e; echo '* oc: '; oc version ; \
echo '* yq: '; yq --version ; \
echo '* Python: '; python --version ; \
echo '* Ansible: '; ansible --version ; \
echo '* kubernetes.core: '; ansible-galaxy collection list | grep kubernetes.core ; \
echo '* community.general: '; ansible-galaxy collection list | grep community.general ; \
echo '* ansible.posix: '; ansible-galaxy collection list | grep ansible.posix ; \
echo '* ansible.utils: '; ansible-galaxy collection list | grep ansible.utils ; \
echo '* rhvp.cluster_utils: '; ansible-galaxy collection list | grep rhvp.cluster_utils ; \
echo '* diff: '; diff --version ; \
echo '* find: '; find --version ;"
##@ Help-related tasks
.PHONY: help
help: ## Help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^(\s|[a-zA-Z_0-9-])+:.*?##/ { printf " \033[36m%-35s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build-related tasks
.PHONY: build
build: manifest podman-build test ## Build the container locally (all arches) and print installed test
.PHONY: amd64
amd64: manifest podman-build-amd64 test-amd64 ## Build and test the container on amd64
.PHONY: arm64
arm64: manifest podman-build-amd64 test-amd64 ## Build and test the container on amd64
.PHONY: manifest
manifest: ## creates the buildah manifest for multi-arch images
# The rm is needed due to bug https://www.github.com/containers/podman/issues/19757
buildah manifest rm "${REGISTRY}/${CONTAINER}" || /bin/true
buildah manifest create "${REGISTRY}/${CONTAINER}"
.PHONY: podman-build
podman-build: podman-build-amd64 podman-build-arm64 ## Build both amd64 and arm64
.PHONY: podman-build-amd64
podman-build-amd64: ## build the container in amd64
@echo "Building the utility container amd64"
buildah bud --arch=amd64 --build-arg TARGETARCH=amd64 --build-arg ALTTARGETARCH=x86_64 \
--build-arg OPTTARGETARCH='' --build-arg EXTRARPMS='' --format docker \
-f Containerfile -t "${CONTAINER}-amd64"
buildah manifest add --arch=amd64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-amd64"
.PHONY: podman-build-arm64
podman-build-arm64: ## build the container in arm64
@echo "Building the utility container arm64"
buildah bud --arch=arm64 --build-arg TARGETARCH=arm64 --build-arg ALTTARGETARCH=aarch64 \
--build-arg OPTTARGETARCH="arm64-" --build-arg EXTRARPMS="gcc python3-devel glibc-devel libxcrypt-devel" --format docker \
-f Containerfile -t "${CONTAINER}-arm64"
buildah manifest add --arch=arm64 "${REGISTRY}/${CONTAINER}" "${REGISTRY}/${CONTAINER}-arm64"
.PHONY: test-amd64
test-amd64: ## Prints the test of most tools inside the container amd64
@echo "** Testing linux/amd64"
@podman run --arch=amd64 --rm -it --net=host "${REGISTRY}/${CONTAINER}-amd64" bash -c \
$(TESTCOMMAND)
.PHONY: test-arm64
test-arm64: ## Prints the test of most tools inside the container arm64
@echo "** Testing linux/arm64"
@podman run --arch=arm64 --rm -it --net=host "${REGISTRY}/${CONTAINER}-arm64" bash -c \
$(TESTCOMMAND)
.PHONY: test
test: test-amd64 test-arm64 ## Tests the container for all the required bits both arm64 and amd64
##@ Run and upload tasks
.PHONY: versions
versions: ## Print all the versions of software in the locally-built container
@podman run --rm -it --net=host \
--security-opt label=disable \
-v ${HOME}:/pattern \
-v ${HOME}:${HOME} \
-w $$(pwd) "${REGISTRY}/${CONTAINER}-amd64" sh -c \
"set -e; \
echo -n \"|sshpass package \"; rpm -q --queryformat '%{VERSION}' sshpass; echo \" \"; \
echo -n \"|python3-pip package \"; rpm -q --queryformat '%{VERSION}' python3-pip; echo \" \"; \
echo -n \"|git-core package \"; rpm -q --qf '%{VERSION}' git-core; echo \" \"; \
echo -n \"|make package \"; rpm -q --qf '%{VERSION}' make; echo \" \"; \
echo -n \"|python package \"; /usr/bin/python3 --version | sed -e s'/Python //' | tr -d '\n'; echo \" \"; \
echo -n \"|jq package \"; rpm -q --qf '%{VERSION}' jq; echo \" \"; \
echo -n \"|openshift binary \"; oc version --client -o json | jq -j '.releaseClientVersion'; echo \" \"; \
echo -n \"|ansible pip \"; ansible --version -o json | grep core | cut -f3 -d\ | tr -d '\n]'; echo \" \"; \
echo -n \"|kubernetes pip \"; pip show kubernetes |grep ^Version: | cut -f2 -d\ | tr -d '\n'; echo \" \"; \
echo -n \"|jmespath pip \"; pip show jmespath| grep ^Version: | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|ansible-runner pip \"; pip show ansible-runner| grep ^Version: | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|kubernetes.core collection \"; ansible-galaxy collection list kubernetes.core |grep ^kubernetes.core | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|community.okd collection \"; ansible-galaxy collection list community.okd |grep ^community.okd | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|community.general collection \"; ansible-galaxy collection list community.general |grep ^community.general | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|ansible.posix collection \"; ansible-galaxy collection list ansible.posix |grep ^ansible.posix | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|ansible.utils collection \"; ansible-galaxy collection list ansible.utils |grep ^ansible.utils | cut -f2 -d\ |tr -d '\n'; echo \" \"; \
echo -n \"|rhvp.cluster_utils collection \"; ansible-galaxy collection list rhvp.cluster_utils |grep ^rhvp.cluster_utils | cut -f2 -d\ |tr -d '\n'; echo \" \"" | sort | column --table -o '|'
.PHONY: run
run: ## Runs the container interactively
podman run --rm -it --net=host \
--security-opt label=disable \
-v ${HOME}:/pattern \
-v ${HOME}:${HOME} \
-w $$(pwd) "${REGISTRY}/${CONTAINER}-amd64" sh
.PHONY: upload
upload: ## Uploads the container to quay.io/hybridcloudpatterns/${CONTAINER}
@echo "Uploading the ${REGISTRY}/${CONTAINER} container to ${UPLOADREGISTRY}/${CONTAINER}"
buildah manifest push --all "${REGISTRY}/${CONTAINER}" "docker://${UPLOADREGISTRY}/${CONTAINER}"
.PHONY: clean
clean: ## Removes any previously built artifact
buildah manifest rm "${REGISTRY}/${CONTAINER}"
.PHONY: super-linter
super-linter: ## Runs super linter locally
rm -rf .mypy_cache
podman run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true \
-e VALIDATE_MARKDOWN_PRETTIER=false \
-e VALIDATE_SHELL_SHFMT=false \
-e VALIDATE_YAML_PRETTIER=false \
-v $(PWD):/tmp/lint:rw,z \
-w /tmp/lint \
ghcr.io/super-linter/super-linter:slim-v7