generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathMakefile
More file actions
297 lines (257 loc) · 10.2 KB
/
Makefile
File metadata and controls
297 lines (257 loc) · 10.2 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
OUTPUT = main # Referenced as Handler in sar-template.json
PACKAGED_TEMPLATE = packaged.yaml
STACK_NAME := $(STACK_NAME)
S3_BUCKET := $(S3_BUCKET)
S3_PREFIX := $(S3_PREFIX)
TEMPLATE = template.yaml
APP_NAME ?= ssosync
GOREL_ARGS ?=
GOREL ?= goreleaser
# Verbose flag support
# Use VERBOSE=1 for verbose output (e.g., 'make test VERBOSE=1')
VERBOSE ?= 0
ifeq ($(VERBOSE),1)
VERBOSE_FLAG = -v
VERBOSE_TEST_FLAG = -v
VERBOSE_BUILD_FLAG = --verbose
VERBOSE_CURL_FLAG = -v
Q =
else
VERBOSE_FLAG =
VERBOSE_TEST_FLAG =
VERBOSE_BUILD_FLAG =
VERBOSE_CURL_FLAG = -s
Q = @
endif
# Tool versions
MOCKERY_VERSION ?= v3.5.2
GOLANGCI_LINT_VERSION ?= v2.3.1
GORELEASER_VERSION ?= v2.11.2
UPX_VERSION ?= v4.2.4
# Tool installation paths
TOOLS_DIR := $(shell pwd)/.bin
MOCKERY := $(TOOLS_DIR)/mockery
GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint
GORELEASER_BIN := $(TOOLS_DIR)/goreleaser
UPX := $(TOOLS_DIR)/upx
# Detect OS and architecture
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
ifeq ($(ARCH),x86_64)
ARCH := x86_64
endif
ifeq ($(ARCH),aarch64)
ARCH := arm64
endif
.PHONY: install-deps
install-deps: install-mockery install-golangci-lint install-goreleaser install-upx
$(Q)echo "All development dependencies installed"
.PHONY: install-mockery
install-mockery:
$(Q)echo "Installing mockery $(MOCKERY_VERSION)..."
$(Q)mkdir -p $(TOOLS_DIR)
@if [ ! -f $(MOCKERY) ] || [ "$$($(MOCKERY) version 2>/dev/null | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')" != "$(MOCKERY_VERSION)" ]; then \
MOCKERY_ARCH=$(ARCH); \
MOCKERY_OS=$(OS); \
if [ "$(ARCH)" = "amd64" ]; then MOCKERY_ARCH="x86_64"; fi; \
if [ "$(OS)" = "darwin" ]; then MOCKERY_OS="Darwin"; fi; \
if [ "$(OS)" = "linux" ]; then MOCKERY_OS="Linux"; fi; \
curl $(VERBOSE_CURL_FLAG)SfL https://github.com/vektra/mockery/releases/download/$(MOCKERY_VERSION)/mockery_$(MOCKERY_VERSION:v%=%)_$${MOCKERY_OS}_$${MOCKERY_ARCH}.tar.gz | tar -xz -C $(TOOLS_DIR) mockery; \
chmod +x $(MOCKERY); \
echo "mockery $(MOCKERY_VERSION) installed"; \
else \
echo "mockery $(MOCKERY_VERSION) already installed"; \
fi
.PHONY: install-golangci-lint
install-golangci-lint:
$(Q)echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."
$(Q)mkdir -p $(TOOLS_DIR)
@if [ ! -f $(GOLANGCI_LINT) ] || [ "$$($(GOLANGCI_LINT) --version 2>/dev/null | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')" != "$(GOLANGCI_LINT_VERSION)" ]; then \
curl $(VERBOSE_CURL_FLAG)SfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_DIR) $(GOLANGCI_LINT_VERSION); \
echo "golangci-lint $(GOLANGCI_LINT_VERSION) installed"; \
else \
echo "golangci-lint $(GOLANGCI_LINT_VERSION) already installed"; \
fi
.PHONY: install-goreleaser
install-goreleaser:
$(Q)echo "Installing goreleaser $(GORELEASER_VERSION)..."
$(Q)mkdir -p $(TOOLS_DIR)
@if [ ! -f $(GORELEASER_BIN) ] || [ "$$($(GORELEASER_BIN) --version 2>/dev/null | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')" != "$(GORELEASER_VERSION)" ]; then \
curl $(VERBOSE_CURL_FLAG)SfL https://github.com/goreleaser/goreleaser/releases/download/$(GORELEASER_VERSION)/goreleaser_$(OS)_$(ARCH).tar.gz | tar -xz -C $(TOOLS_DIR) goreleaser; \
chmod +x $(GORELEASER_BIN); \
echo "goreleaser $(GORELEASER_VERSION) installed"; \
else \
echo "goreleaser $(GORELEASER_VERSION) already installed"; \
fi
.PHONY: install-upx
install-upx:
$(Q)echo "Installing upx $(UPX_VERSION)..."
$(Q)mkdir -p $(TOOLS_DIR)
@if [ ! -f $(UPX) ] || [ "$$($(UPX) --version 2>/dev/null | head -1 | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')" != "$(UPX_VERSION)" ]; then \
UPX_ARCH=$(ARCH); \
if [ "$(ARCH)" = "x86_64" ]; then UPX_ARCH="amd64"; fi; \
if [ "$(ARCH)" = "arm64" ]; then UPX_ARCH="arm64"; fi; \
if [ "$(OS)" = "linux" ]; then \
UPX_FILE="upx-$(UPX_VERSION:v%=%)-$${UPX_ARCH}_linux"; \
elif [ "$(OS)" = "darwin" ]; then \
UPX_FILE="upx-$(UPX_VERSION:v%=%)-amd64_macos"; \
else \
echo "Error: Unsupported OS $(OS) for UPX installation"; \
exit 1; \
fi; \
curl $(VERBOSE_CURL_FLAG)SfL https://github.com/upx/upx/releases/download/$(UPX_VERSION)/$${UPX_FILE}.tar.xz | tar -xJ -C $(TOOLS_DIR) --strip-components=1 $${UPX_FILE}/upx; \
chmod +x $(UPX); \
echo "upx $(UPX_VERSION) installed"; \
else \
echo "upx $(UPX_VERSION) already installed"; \
fi
.PHONY: generate-mock
generate-mock: install-mockery
$(MOCKERY)
.PHONY: test
test: generate-mock
$(Q)go test $(VERBOSE_TEST_FLAG) ./... -coverprofile=coverage.out
.PHONY: test-verbose
test-verbose: generate-mock
$(Q)go test -v ./... -coverprofile=coverage.out
.PHONY: test-coverage
test-coverage: test
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: go-build
go-build: install-goreleaser
$(Q)$(GORELEASER_BIN) build --snapshot --clean --id ssosync $(VERBOSE_BUILD_FLAG) $(GOREL_ARGS)
.PHONY: clean
clean:
rm -f $(OUTPUT) $(PACKAGED_TEMPLATE) bootstrap coverage.out coverage.html
rm -rf dist/ internal/mocks/*
.PHONY: clean-all
clean-all: clean
rm -rf $(TOOLS_DIR)
build-SSOSyncFunction: go-build
cp dist/ssosync_linux_arm64_v8.2/ssosync $(ARTIFACTS_DIR)/bootstrap
.PHONY: config
config:
go mod download
.PHONY: vet
vet: install-golangci-lint generate-mock
$(GOLANGCI_LINT) run
.PHONY: lint
lint: vet
.PHONY: fmt
fmt:
$(Q)go fmt $(VERBOSE_FLAG) ./...
$(Q)go mod tidy $(VERBOSE_FLAG)
main: main.go install-goreleaser
$(Q)echo $(GORELEASER_BIN) build --clean $(VERBOSE_BUILD_FLAG) $(GOREL_ARGS)
$(Q)$(GORELEASER_BIN) build --clean $(VERBOSE_BUILD_FLAG) $(GOREL_ARGS)
# compile the code to run in Lambda (local or real)
.PHONY: lambda
lambda: main
.PHONY: build
build: clean main
.PHONY: release
release: install-goreleaser
$(Q)$(GORELEASER_BIN) release --clean $(VERBOSE_BUILD_FLAG) $(GOREL_ARGS)
.PHONY: dry-run
dry-run:
$(MAKE) GOREL_ARGS=--skip=publish release
.PHONY: api
api: build
sam local start-api
.PHONY: publish
publish:
sam publish -t packaged.yaml
.PHONY: package
package: build
@if [ "$(ARCH)" = "arm64" ]; then \
cp dist/ssosync_$(OS)_arm64_v8.2/ssosync ./bootstrap; \
elif [ "$(ARCH)" = "x86_64" ]; then \
cp dist/ssosync_$(OS)_amd64_v1/ssosync ./bootstrap; \
else \
echo "Error: Unsupported architecture $(ARCH)"; \
exit 1; \
fi
sam package --s3-bucket $(S3_BUCKET) --output-template-file $(PACKAGED_TEMPLATE) --s3-prefix $(S3_PREFIX)
.PHONY: deploy
deploy: package
sam deploy --stack-name $(STACK_NAME) --template-file $(PACKAGED_TEMPLATE) --capabilities CAPABILITY_IAM
.PHONY: dev
dev: go-build
@echo "Running development build for $(OS)/$(ARCH)..."
@if [ "$(ARCH)" = "arm64" ]; then \
BINARY_PATH="dist/ssosync_$(OS)_arm64_v8.2/ssosync"; \
elif [ "$(ARCH)" = "x86_64" ]; then \
BINARY_PATH="dist/ssosync_$(OS)_amd64_v1/ssosync"; \
else \
BINARY_PATH=$$(find dist/ -name "ssosync_$(OS)_*" -type f | head -1); \
fi; \
if [ ! -f "$$BINARY_PATH" ]; then \
echo "Error: Binary not found at $$BINARY_PATH. Available binaries:"; \
find dist/ -name "ssosync*" -type f || echo "No binaries found in dist/"; \
exit 1; \
fi; \
echo "Using binary: $$BINARY_PATH"; \
$$BINARY_PATH -g "name:AWS*" \
-t $$(jq '.["ssosync/aws-sso/scimEndpointAccessToken"]' ./cicd/cloudformation/cdk/cdk.context.json -r) \
-r $$(jq '.["ssosync/aws-sso/region"]' ./cicd/cloudformation/cdk/cdk.context.json -r) \
-e $$(jq '.["ssosync/aws-sso/scimEndpointUrl"]' ./cicd/cloudformation/cdk/cdk.context.json -r) \
-u $$(jq '.["ssosync/secrets/googleAdminEmail"]' ./cicd/cloudformation/cdk/cdk.context.json -r) \
-i $$(jq '.["ssosync/aws-sso/identityStoreId"]' ./cicd/cloudformation/cdk/cdk.context.json -r) \
-c ./cicd/cloudformation/cdk/google-service-account.json \
--log-level debug
.PHONY: check-tools
check-tools:
@echo "Checking installed tools..."
@if [ -f $(MOCKERY) ]; then echo "✓ mockery: $$($(MOCKERY) version)"; else echo "✗ mockery: not installed"; fi
@if [ -f $(GOLANGCI_LINT) ]; then echo "✓ golangci-lint: $$($(GOLANGCI_LINT) --version)"; else echo "✗ golangci-lint: not installed"; fi
@if [ -f $(GORELEASER_BIN) ]; then echo "✓ goreleaser: $$($(GORELEASER_BIN) --version)"; else echo "✗ goreleaser: not installed"; fi
@if [ -f $(UPX) ]; then echo "✓ upx: $$($(UPX) --version 2>/dev/null | head -1)"; else echo "✗ upx: not installed"; fi
@echo "Go version: $$(go version)"
.PHONY: setup
setup: install-deps config
@echo "Development environment setup complete"
.PHONY: ci
ci: vet test
@echo "CI pipeline completed successfully"
.PHONY: help
help:
@echo "Available targets:"
@echo " setup - Install all dependencies and setup development environment"
@echo " install-deps - Install all development dependencies (mockery, golangci-lint, goreleaser, upx)"
@echo " check-tools - Check status of installed tools"
@echo " fmt - Format code and tidy modules"
@echo " generate-mock - Generate mocks using mockery"
@echo " test - Run tests with coverage"
@echo " test-verbose - Run tests with verbose output"
@echo " test-coverage - Generate HTML coverage report"
@echo " vet/lint - Run linters"
@echo " go-build - Build application using goreleaser"
@echo " build - Clean and build application"
@echo " release - Create release using goreleaser"
@echo " dry-run - Test release without publishing"
@echo " clean - Clean build artifacts"
@echo " clean-all - Clean everything including development tools (.bin/)"
@echo " ci - Run CI pipeline (fmt, vet, test)"
@echo " dev - Run development build (auto-detects $(OS)/$(ARCH))"
@echo " dev-help - Show help for development build"
@echo " help - Show this help message"
@echo ""
@echo "Verbose mode:"
@echo " Use VERBOSE=1 with any target for verbose output (e.g., 'make test VERBOSE=1')"
.PHONY: dev-help
dev-help: go-build
@echo "Running development build help for $(OS)/$(ARCH)..."
@if [ "$(ARCH)" = "arm64" ]; then \
BINARY_PATH="dist/ssosync_$(OS)_arm64_v8.2/ssosync"; \
elif [ "$(ARCH)" = "x86_64" ]; then \
BINARY_PATH="dist/ssosync_$(OS)_amd64_v1/ssosync"; \
else \
BINARY_PATH=$$(find dist/ -name "ssosync_$(OS)_*" -type f | head -1); \
fi; \
if [ ! -f "$$BINARY_PATH" ]; then \
echo "Error: Binary not found at $$BINARY_PATH"; \
exit 1; \
fi; \
echo "Using binary: $$BINARY_PATH"; \
$$BINARY_PATH --help