-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
152 lines (123 loc) · 4.75 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
VERSION ?= 0.9.0-dev
CONTAINER_MANAGER ?= podman
# Image URL to use all building/pushing image targets
IMG ?= quay.io/redhat-developer/mapt:v${VERSION}
TKN_IMG ?= quay.io/redhat-developer/mapt:v${VERSION}-tkn
# Integrations
# renovate: datasource=github-releases depName=cirruslabs/cirrus-cli
CIRRUS_CLI ?= v0.135.0
# renovate: datasource=github-releases depName=actions/runner
GITHUB_RUNNER ?= 2.317.0
# Go and compilation related variables
GOPATH ?= $(shell go env GOPATH)
BUILD_DIR ?= out
SOURCE_DIRS = cmd pkg
SOURCES := $(shell find . -name "*.go" -not -path "./vendor/*")
# repo
ORG := github.com/redhat-developer
MODULEPATH = $(ORG)/mapt
# Linker flags
VERSION_VARIABLES := -X $(MODULEPATH)/pkg/manager/context.OCI=$(IMG) \
-X $(MODULEPATH)/pkg/integrations/cirrus.version=$(CIRRUS_CLI) \
-X $(MODULEPATH)/pkg/integrations/github.runnerVersion=$(GITHUB_RUNNER)
LDFLAGS := $(VERSION_VARIABLES) ${GO_EXTRA_LDFLAGS}
GCFLAGS := all=-N -l
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
# Tools
TOOLS_DIR := tools
include tools/tools.mk
# Functions
define tkn_update
rm tkn/*.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-fedora.yaml > tkn/infra-aws-fedora.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-mac.yaml > tkn/infra-aws-mac.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-rhel.yaml > tkn/infra-aws-rhel.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-windows-server.yaml > tkn/infra-aws-windows-server.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-aks.yaml > tkn/infra-azure-aks.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-rhel.yaml > tkn/infra-azure-rhel.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-fedora.yaml > tkn/infra-azure-fedora.yaml
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-windows-desktop.yaml > tkn/infra-azure-windows-desktop.yaml
endef
# Add default target
.PHONY: default
default: install
# Create and update the vendor directory
.PHONY: vendor
vendor:
go mod tidy
go mod vendor
.PHONY: check
check: build test lint
# Start of the actual build targets
.PHONY: install
install: $(SOURCES)
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt
$(BUILD_DIR)/mapt: $(SOURCES)
GOOS="$(GOOS)" GOARCH=$(GOARCH) go build -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/mapt $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt
.PHONY: build
build: $(BUILD_DIR)/mapt
.PHONY: test
test:
CGO_ENABLED=1 go test -race --tags build -v -ldflags="$(VERSION_VARIABLES)" ./pkg/... ./cmd/...
.PHONY: clean ## Remove all build artifacts
clean:
rm -rf $(BUILD_DIR)
rm -f $(GOPATH)/bin/mapt
.PHONY: fmt
fmt:
@gofmt -l -w $(SOURCE_DIRS)
# Run golangci-lint against code
.PHONY: lint
lint: $(TOOLS_BINDIR)/golangci-lint
"$(TOOLS_BINDIR)"/golangci-lint run -v --timeout 10m
# Build the container image
.PHONY: oci-build
oci-build: clean oci-build-amd64 oci-build-arm64
# Build for amd64 architecture only
.PHONY: oci-build-amd64
oci-build-amd64: clean
# Build the container image for amd64
${CONTAINER_MANAGER} build --platform linux/amd64 --manifest $(IMG)-amd64 -f oci/Containerfile .
# Build for arm64 architecture only
.PHONY: oci-build-arm64
oci-build-arm64: clean
# Build the container image for arm64
${CONTAINER_MANAGER} build --platform linux/arm64 --manifest $(IMG)-arm64 -f oci/Containerfile .
# Save images for amd64 architecture only
.PHONY: oci-save-amd64
oci-save-amd64:
${CONTAINER_MANAGER} save -m -o $(MAPT_SAVE)-amd64.tar $(IMG)-amd64
# Save images for arm64 architecture only
.PHONY: oci-save-arm64
oci-save-arm64:
${CONTAINER_MANAGER} save -m -o $(MAPT_SAVE)-arm64.tar $(IMG)-arm64
MAPT_SAVE ?= mapt
.PHONY: oci-save
oci-save: oci-save-amd64 oci-save-arm64
oci-load:
${CONTAINER_MANAGER} load -i $(MAPT_SAVE)-arm64/$(MAPT_SAVE)-arm64.tar
${CONTAINER_MANAGER} load -i $(MAPT_SAVE)-amd64/$(MAPT_SAVE)-amd64.tar
# Push the docker image
.PHONY: oci-push
oci-push:
${CONTAINER_MANAGER} push $(IMG)-arm64
${CONTAINER_MANAGER} push $(IMG)-amd64
${CONTAINER_MANAGER} manifest create $(IMG)
${CONTAINER_MANAGER} manifest add $(IMG) docker://$(IMG)-arm64
${CONTAINER_MANAGER} manifest add $(IMG) docker://$(IMG)-amd64
${CONTAINER_MANAGER} manifest push --all $(IMG)
# Update tekton with new version
.PHONY: tkn-update
tkn-update:
$(call tkn_update,$(IMG),$(VERSION))
# Create tekton task bundle
.PHONY: tkn-push
tkn-push: install-out-of-tree-tools
$(TOOLS_BINDIR)/tkn bundle push $(TKN_IMG) \
-f tkn/infra-aws-fedora.yaml \
-f tkn/infra-aws-mac.yaml \
-f tkn/infra-aws-rhel.yaml \
-f tkn/infra-aws-windows-server.yaml \
-f tkn/infra-azure-rhel.yaml \
-f tkn/infra-azure-windows-desktop.yaml