-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
133 lines (109 loc) · 4.13 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
130
131
132
133
PWD := $(shell pwd)
LOCAL_BIN ?= $(PWD)/bin
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29.x
# Keep an existing GOPATH, make a private one if it is undefined
GOPATH_DEFAULT := $(PWD)/.go
export GOPATH ?= $(GOPATH_DEFAULT)
GOBIN_DEFAULT := $(GOPATH)/bin
export GOBIN ?= $(GOBIN_DEFAULT)
export PATH := $(LOCAL_BIN):$(GOBIN):$(PATH)
# Default architecture to amd64
ARCH ?= $(shell go env GOARCH)
ifndef ARCH
ARCH = amd64
endif
include build/common/Makefile.common.mk
# Image URL to use all building/pushing image targets;
# Use your own docker registry and image name for dev/test by overridding the IMG and REGISTRY environment variable.
IMG ?= acm-cli
REGISTRY ?= quay.io/stolostron
TAG ?= latest
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/$(IMG)
############################################################
# clean section
############################################################
.PHONY: clean
clean:
-rm -rf build/_output/*
-rm kubeconfig_*
-rm gosec.json
-rm kubeconfig_*
-rm -rf external/*
kind delete cluster --name $(KIND_NAME)
############################################################
# build section
############################################################
CONTAINER_ENGINE ?= podman
BUILD_DIR ?= build/_output
RELEASE_TAG ?= main
REMOTE_SOURCES_DIR ?= $(PWD)/external
REMOTE_SOURCES_SUBDIR ?=
.PHONY: build
build:
CGO_ENABLED=1 go build -o $(BUILD_DIR)/acm-cli-server ./server/main.go
.PHONY: build-image
build-image:
$(CONTAINER_ENGINE) build --platform linux/$(ARCH) $(BUILD_ARGS) -t $(IMAGE_NAME_AND_VERSION):$(TAG) .
.PHONY: clone-build-package
clone-build-package: clone-repos build-and-package
.PHONY: build-and-package
build-and-package: build-binaries package-binaries
.PHONY: clone-repos
clone-repos:
while IFS=, read -r git_url build_cmd build_dir; do \
if [[ "$${git_url}" != "GIT REPO URL" ]]; then \
git clone --branch=${RELEASE_TAG} --depth=1 $${git_url} $(REMOTE_SOURCES_DIR)/$${git_url##*/}/$(REMOTE_SOURCES_SUBDIR); \
fi; \
done < ./build/cli_map.csv
.PHONY: build-binaries
build-binaries:
BUILD_DIR=$(BUILD_DIR) REMOTE_SOURCES_DIR=$(REMOTE_SOURCES_DIR) REMOTE_SOURCES_SUBDIR=$(REMOTE_SOURCES_SUBDIR) \
./build/cli-builder.sh
.PHONY: package-binaries
package-binaries:
BUILD_DIR=$(BUILD_DIR) ./build/cli-packager.sh
############################################################
# deploy section
############################################################
.PHONY: deploy-openshift
deploy-openshift:
# Preflight check for OCP cluster
@if ! (kubectl get ingresses.config.openshift.io 1>/dev/null); then \
echo "info: Unable to fetch Ingress, or not an Openshift cluster. Exiting."; exit 1; \
fi
# Creating the acm-cli-downloads deployment with ConsoleCLIDownload in namespace default
helm template deploy/ \
--set isOpenshift=true --set imagePullPolicy=IfNotPresent \
--set ingress.domain=$$(kubectl get ingresses.config.openshift.io cluster -o jsonpath={.spec.domain}) \
| oc apply -n default -f -
.PHONY: deploy
deploy:
# Creating the acm-cli-downloads deployment in namespace default
helm template deploy/ | kubectl apply -n default -f -
kubectl rollout status deployment -n default acm-cli-downloads
############################################################
# lint section
############################################################
.PHONY: fmt
fmt:
.PHONY: lint
lint:
############################################################
# test section
############################################################
CLUSTER_NAME = acm-cli
.PHONY: kind-bootstrap-cluster
kind-bootstrap-cluster: KIND_ARGS = --config test/kind_config.yaml
kind-bootstrap-cluster: kind-create-cluster
kind load --name $(KIND_NAME) docker-image quay.io/stolostron/acm-cli:latest
$(MAKE) deploy
.PHONY: e2e-test
e2e-test: kind-bootstrap-cluster
# Checking availability of CLI server endpoint
for i in $$(seq 1 5); do \
curl -sS http://localhost:30000 1>/dev/null || \
{ echo "Connection failed. Retrying ($${i}/5)"; sleep 3; }; \
done
# Validating returned file list against test/cli_list.html
curl -s http://localhost:30000 | diff test/cli_list.html - && echo "Success!"