-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
164 lines (134 loc) · 8.89 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
153
154
155
156
157
158
159
160
161
162
163
164
GITHUB_REPO_OWNER := Nordstrom
GITHUB_REPO_NAME := kubelogin
GITHUB_RELEASE_PRERELASE_BOOLEAN := true
GITHUB_RELEASES_UI_URL := https://github.com/$(GITHUB_REPO_OWNER)/$(GITHUB_REPO_NAME)/releases
GITHUB_RELEASES_API_URL := https://api.github.com/repos/$(GITHUB_REPO_OWNER)/$(GITHUB_REPO_NAME)/releases
GITHUB_INDIVIDUAL_RELEASE_ASSET_URL := https://uploads.github.com/repos/$(GITHUB_REPO_OWNER)/$(GITHUB_REPO_NAME)/releases
GITHUB_REPO_HOST_AND_PATH := github.com/$(GITHUB_REPO_OWNER)/$(GITHUB_REPO_NAME)
IMAGE_NAME := artifactory.nordstrom.com/docker/app00738/kubelogin
BUILD := build
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
CURRENT_TAG := v0.0.8
GOLANG_TOOLCHAIN_VERSION := 1.17.6
.PHONY: image/build image/push
.PHONY: release/tag/local release/tag/push
.PHONY: release/github/draft release/github/draft/create release/github/publish
.PHONY: release/assets release/assets/cli release/assets/server
.PHONY: release/assets/cli/% release/assets/server/%
.PHONY: clean
image/push: image/build
docker push $(IMAGE_NAME):$(CURRENT_TAG)
binaries/build: $(BUILD)/cli/mac/kubelogin $(BUILD)/cli/linux/kubelogin $(BUILD)/cli/windows/kubelogin.exe $(BUILD)/server/linux/kubelogin-server
# image/build: $(BUILD)/cli/mac/kubelogin-cli-$(CURRENT_TAG)-darwin.tar.gz
# image/build: $(BUILD)/cli/linux/kubelogin-cli-$(CURRENT_TAG)-linux.tar.gz
# image/build: $(BUILD)/cli/windows/kubelogin-cli-$(CURRENT_TAG)-windows-$(CURRENT_TAG).zip
# image/build: $(BUILD)/server/linux/kubelogin-server-$(CURRENT_TAG)-linux
image/build: $(BUILD)/Dockerfile release/github/publish
docker build --build-arg CURRENT_TAG=$(CURRENT_TAG) --tag $(IMAGE_NAME):$(CURRENT_TAG) $(<D)
release/github/draft: release/tag/local release/tag/push release/github/draft/create release/assets $(BUILD)/github-release-$(CURRENT_TAG)-id
@echo "\n\nPlease inspect the release and run make release/github/publish if it looks good"
open "$(GITHUB_RELEASES_UI_URL)/$(CURRENT_TAG)"
release/github/publish: release/github/draft $(BUILD)/github-release-$(CURRENT_TAG)-published-response-body.json
$(BUILD)/github-release-$(CURRENT_TAG)-published-response-body.json: $(BUILD)/github-release-$(CURRENT_TAG)-published-request-body.json $(BUILD)/github-release-$(CURRENT_TAG)-id
curl -u $(GITHUB_USERNAME) -XPATCH -d@"$<" "$(GITHUB_RELEASES_API_URL)/$$(cat $(BUILD)/github-release-$(CURRENT_TAG)-id)" > $@
$(BUILD)/github-release-$(CURRENT_TAG)-published-request-body.json: $(BUILD)/github-release-$(CURRENT_TAG)-draft-request-body.json
jq '.draft = false' "$<" > "$@"
release/tag/local:
@if [ -n "$$(git status --porcelain)" ]; then echo "Won't tag a dirty working copy. Commit or stash and try again."; exit 1; fi
-git tag $(CURRENT_TAG)
release/tag/push: $(BUILD)/tags-$(CURRENT_TAG)-pushed
$(BUILD)/tags-$(CURRENT_TAG)-pushed: | $(BUILD)
git push --tags > "$@"
release/github/draft/create: $(BUILD)/github-release-$(CURRENT_TAG)-response-body.json
RELEASE_ASSETS_CLI_TARGETS += $(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-darwin.json
RELEASE_ASSETS_CLI_TARGETS += $(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-linux.json
RELEASE_ASSETS_CLI_TARGETS += $(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-windows.json
RELEASE_ASSETS_SERVER_TARGETS += $(BUILD)/github-release-asset-response-kubelogin-server-$(CURRENT_TAG)-linux.json
release/assets: release/assets/cli release/assets/server
release/assets/cli: $(RELEASE_ASSETS_CLI_TARGETS)
release/assets/cli/%: $(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-%-asset-response.json
release/assets/server: $(RELEASE_ASSETS_SERVER_TARGETS)
release/assets/server/%: $(BUILD)/github-release-asset-response-kubelogin-server-$(CURRENT_TAG)-%.json
# release/assets/cli/darwin: $(BUILD)/cli/mac/kubelogin-cli-$(CURRENT_TAG)-darwin.tar.gz $(BUILD)/github-release-$(CURRENT_TAG)-id
# release/assets/cli/linux: $(BUILD)/cli/linux/kubelogin-cli-$(CURRENT_TAG)-linux.tar.gz $(BUILD)/github-release-$(CURRENT_TAG)-id
# release/assets/cli/windows: $(BUILD)/cli/windows/kubelogin-cli-$(CURRENT_TAG)-windows.zip $(BUILD)/github-release-$(CURRENT_TAG)-id
# $(RELEASE_ASSETS_CLI_TARGETS): |
# @if [ -z "$(GITHUB_USERNAME)" ]; then echo "Please set GITHUB_USERNAME"; exit 1; fi
# curl -u $(GITHUB_USERNAME) \
# --data-binary @"$<" \
# -H "Content-Type: application/octet-stream" \
# "$(GITHUB_INDIVIDUAL_RELEASE_ASSET_URL)/$$(cat $(BUILD)/github-release-$(CURRENT_TAG)-id)/assets?name=$(<F)"
$(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-darwin.json: $(BUILD)/cli/mac/kubelogin-cli-$(CURRENT_TAG)-darwin.tar.gz $(BUILD)/github-release-$(CURRENT_TAG)-id
$(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-linux.json: $(BUILD)/cli/linux/kubelogin-cli-$(CURRENT_TAG)-linux.tar.gz $(BUILD)/github-release-$(CURRENT_TAG)-id
$(BUILD)/github-release-asset-response-kubelogin-cli-$(CURRENT_TAG)-windows.json: $(BUILD)/cli/windows/kubelogin-cli-$(CURRENT_TAG)-windows.zip $(BUILD)/github-release-$(CURRENT_TAG)-id
$(BUILD)/github-release-asset-response-kubelogin-server-$(CURRENT_TAG)-linux.json: $(BUILD)/server/linux/kubelogin-server-$(CURRENT_TAG)-linux.tar.gz $(BUILD)/github-release-$(CURRENT_TAG)-id
$(RELEASE_ASSETS_CLI_TARGETS) $(RELEASE_ASSETS_SERVER_TARGETS):
@if [ -z "$(GITHUB_USERNAME)" ]; then echo "Please set GITHUB_USERNAME"; exit 1; fi
curl -u $(GITHUB_USERNAME) \
--data-binary @"$<" \
-H "Content-Type: application/octet-stream" \
"$(GITHUB_INDIVIDUAL_RELEASE_ASSET_URL)/$$(cat $(BUILD)/github-release-$(CURRENT_TAG)-id)/assets?name=$(<F)" \
| jq '.' > "$@"
$(BUILD)/github-release-$(CURRENT_TAG)-id: $(BUILD)/github-release-$(CURRENT_TAG)-response-body.json
jq -r '.id' "$<" > "$@"
# find an existing, non-draft GH release or create one for the tag $(CURRENT_TAG)
$(BUILD)/github-release-$(CURRENT_TAG)-response-body.json: | $(BUILD)
curl -s "$(GITHUB_RELEASES_API_URL)/tags/$(CURRENT_TAG)" > "$@"
if [[ $$(jq -e 'has("id") | not' "$@") ]]; then \
make "$(BUILD)/github-release-$(CURRENT_TAG)-draft-response-body-new.json"; \
cp "$(BUILD)/github-release-$(CURRENT_TAG)-draft-response-body-new.json" "$@"; \
fi
$(BUILD)/github-release-$(CURRENT_TAG)-draft-response-body-new.json: $(BUILD)/github-release-$(CURRENT_TAG)-draft-request-body.json release/tag/push
@if [ -z "$(GITHUB_USERNAME)" ]; then echo "Please set GITHUB_USERNAME"; exit 1; fi
curl -u $(GITHUB_USERNAME) -XPOST -d@"$<" "$(GITHUB_RELEASES_API_URL)" > "$@"
$(BUILD)/github-release-$(CURRENT_TAG)-draft-request-body.json: Makefile | $(BUILD)
jq -n '{ \
tag_name: "$(CURRENT_TAG)", \
target_commitish: "$(CURRENT_BRANCH)", \
name: "$(CURRENT_TAG)", \
body: "kubelogin release $(CURRENT_TAG)", \
draft: true, \
prerelease: $(GITHUB_RELEASE_PRERELASE_BOOLEAN) \
}' > "$@"
$(BUILD)/cli/mac/kubelogin-cli-$(CURRENT_TAG)-darwin.tar.gz: $(BUILD)/cli/mac/kubelogin
$(BUILD)/cli/linux/kubelogin-cli-$(CURRENT_TAG)-linux.tar.gz: $(BUILD)/cli/linux/kubelogin
$(BUILD)/cli/mac/kubelogin-cli-$(CURRENT_TAG)-darwin.tar.gz $(BUILD)/cli/linux/kubelogin-cli-$(CURRENT_TAG)-linux.tar.gz:
tar -C "$(@D)" -czf $@ "$(<F)"
$(BUILD)/server/linux/kubelogin-server-$(CURRENT_TAG)-linux.tar.gz: $(BUILD)/server/linux/kubelogin-server
tar -C "$(@D)" -czf $@ "$(<F)"
$(BUILD)/cli/windows/kubelogin-cli-$(CURRENT_TAG)-windows.zip: $(BUILD)/cli/windows/kubelogin.exe
cd "$(@D)" && zip -r -X "$(@F)" "$(<F)"
$(BUILD)/cli/mac/kubelogin: $(BUILD)/cli/kubelogin-cli-$(CURRENT_TAG)-darwin | $(BUILD)/cli/mac
$(BUILD)/cli/linux/kubelogin: $(BUILD)/cli/kubelogin-cli-$(CURRENT_TAG)-linux | $(BUILD)/cli/linux
$(BUILD)/cli/windows/kubelogin.exe: $(BUILD)/cli/kubelogin-cli-$(CURRENT_TAG)-windows | $(BUILD)/cli/windows
$(BUILD)/server/linux/kubelogin-server: $(BUILD)/server/kubelogin-server-$(CURRENT_TAG)-linux | $(BUILD)/server/linux
$(BUILD)/Dockerfile: Dockerfile | $(BUILD)
$(BUILD)/cli/mac/kubelogin $(BUILD)/cli/linux/kubelogin $(BUILD)/cli/windows/kubelogin.exe $(BUILD)/server/linux/kubelogin-server $(BUILD)/Dockerfile:
cp "$<" "$@"
# Build your golang app for the target OS
# GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-X main.Version=$(CURRENT_TAG)"
$(BUILD)/server/kubelogin-server-$(CURRENT_TAG)-%: cmd/server/*.go | $(BUILD)/server
docker run -it \
-v $(PWD):/go/src/$(GITHUB_REPO_HOST_AND_PATH) \
-v $(PWD)/$(@D):/go/bin \
-e GOARCH=amd64 \
-e GOOS=$* \
golang:$(GOLANG_TOOLCHAIN_VERSION) \
go build -v -o /go/bin/$(@F) \
$(GITHUB_REPO_HOST_AND_PATH)/cmd/server/
$(BUILD)/cli/kubelogin-cli-$(CURRENT_TAG)-%: cmd/cli/*.go | $(BUILD)/cli
docker run -it \
-v $(PWD):/go/src/$(GITHUB_REPO_HOST_AND_PATH) \
-v $(PWD)/$(@D):/go/bin \
-e GOARCH=amd64 \
-e GOOS=$* \
golang:$(GOLANG_TOOLCHAIN_VERSION) \
go build -v -o /go/bin/$(@F) \
$(GITHUB_REPO_HOST_AND_PATH)/cmd/cli/ \
.PHONY: test_app
test_app:
go test ./...
build $(BUILD)/server $(BUILD)/server/linux $(BUILD)/cli $(BUILD)/cli/mac $(BUILD)/cli/linux $(BUILD)/cli/windows:
mkdir -p $@
clean:
rm -rf build