-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
executable file
·177 lines (145 loc) · 4.68 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
165
166
167
168
169
170
171
172
173
174
175
176
177
# renovate: datasource=docker depName=grafana/k6 versioning=docker
export K6_VERSION=0.55.0
export K6_LOCATION?=$(GOPATH)/bin/k6
REPO=github.com/leonyork/xk6-output-timestream
ENV?=dev
export IMAGE_NAME=k6
.PHONY: all
all: build test-unit format check build-image deploy-infra test-integration destroy-infra
.PHONY: build
build:
xk6 build v$(K6_VERSION) --with xk6-output-timestream=$(CURDIR) --output $(K6_DIST_LOCATION)
.PHONY: test-unit
test-unit:
go test
export K6_TIMESTREAM_DATABASE_NAME?=dev-xk6-output-timestream-test
export K6_TIMESTREAM_TABLE_NAME?=test
.PHONY: test-integration
test-integration:
make -C test test
INFRA_STACK_NAME?=dev-xk6-output-timestream-test
INFRA_STACK_PARAMETERS="DatabaseName"="$(K6_TIMESTREAM_DATABASE_NAME)" \
"TableName"="$(K6_TIMESTREAM_TABLE_NAME)"
INFRA_STACK_TAGS="Repo=$(REPO)" "Env=$(ENV)"
ifneq ($(INFRA_ROLE_ARN),)
ROLE_ARN_ARG=--role-arn $(INFRA_ROLE_ARN)
endif
.PHONY: deploy-infra
deploy-infra:
aws cloudformation deploy --template-file test/infra/cloudformation.yaml --stack-name $(INFRA_STACK_NAME) --tags $(INFRA_STACK_TAGS) --parameter-overrides $(INFRA_STACK_PARAMETERS) $(ROLE_ARN_ARG)
.PHONY: destroy-infra
destroy-infra:
aws cloudformation delete-stack --stack-name $(INFRA_STACK_NAME)
aws cloudformation wait stack-delete-complete --stack-name $(INFRA_STACK_NAME)
#################################################
# Dev tooling (including code formatting
# + checking)
#################################################
# Init development mode - ensures code is in a
# good state when commiting.
.PHONY: init-dev
init-dev:
pre-commit install
# Format the code - will change your files
.PHONY: format
format: prettier shfmt
@echo Formatting complete
# Check the code - will fail if checks fail
.PHONY: check
check: prettier-check hadolint-check shfmt-check go-vet-check golangci-check
@echo Code checking complete
# Lint with golangci-lint
.PHONY: golangci-check
golangci-check:
golangci-lint run ./...
# Formatting with prettier (json)
.PHONY: prettier
prettier:
prettier --write .
.PHONY: prettier-check
prettier-check:
@prettier --check .
# Formatting with hadolint (dockerfile)
.PHONY: hadolint-check
hadolint-check:
@hadolint Dockerfile
@hadolint test/Dockerfile
@hadolint test/test.Dockerfile
@hadolint grafana/Dockerfile
@hadolint .devcontainer/Dockerfile
@echo Hadolint Passed
.PHONY: go-vet-check
go-vet-check:
@go vet
@echo go vet Passed
# Formatting with shfmt (shell scripts)
.PHONY: shfmt
shfmt:
shfmt -l -w .
.PHONY: shfmt-check
shfmt-check:
@shfmt -l -d .
@echo shfmt Passed
# All pre-commit hooks
.PHONY: check-all
check-all:
pre-commit run --all-files
VERSION=$(shell git tag -l --contains HEAD | grep '^v')
VERSION_NO_V=$(subst v,,$(VERSION))
ifneq ($(VERSION_NO_V),)
export FULL_IMAGE_NAME?=$(IMAGE_NAME):$(K6_VERSION)-timestream$(VERSION_NO_V)
else
# In Dockerhub the versions are without the leading 'v'
export FULL_IMAGE_NAME?=$(IMAGE_NAME):$(K6_VERSION)
endif
DOCKER_BUILD_CMD=build
ifneq ($(GOOS),)
ifneq ($(GOARCH),)
PLATFORM_ARG=--platform $(GOOS)/$(GOARCH)
EXTRA_ARGS=$(PLATFORM_ARG) --load
DOCKER_BUILD_CMD=buildx build
endif
endif
K6_DIST_LOCATION?=dist/k6
.PHONY: build-image
build-image: build
$(MAKE) K6_LOCATION=$(K6_DIST_LOCATION) build
docker $(DOCKER_BUILD_CMD) --target k6 --build-arg K6_VERSION=$(K6_VERSION) --build-arg VERSION=$(VERSION) --build-arg K6_HOST_LOCATION=$(K6_DIST_LOCATION) $(EXTRA_ARGS) -t $(FULL_IMAGE_NAME) $(CACHE_CMD) .
.PHONY: push-image
push-image:
docker push $(FULL_IMAGE_NAME)
.PHONY: image-name
image-name:
@echo $(FULL_IMAGE_NAME)
.PHONY: update-changelog
update-changelog:
echo '\nTo pull the image for this release, run\n\n`docker pull $(FULL_IMAGE_NAME)`' >> CHANGELOG.md
.PHONY: retag-image
retag-image:
docker buildx imagetools create -t $(FULL_IMAGE_NAME) $(CACHE_NAME)
# Tags the repo
# See https://upliftci.dev/
.PHONY: release-tag
release-tag:
uplift release --skip-changelog
.PHONY: release-go
release-go:
GOPROXY=proxy.golang.org go list -m $(REPO)@$(VERSION)
.PHONY: changelog
changelog:
uplift changelog --no-stage --no-push --ignore-detached
#################################################
# Example grafana setup
# Run `make grafana-{target}` to run any of the
# targets in ./grafana/Makefile
# e.g. `make grafana-build`
#################################################
GRAFANA_ARGS:=K6_TIMESTREAM_DATABASE_NAME=$(K6_TIMESTREAM_DATABASE_NAME) \
K6_TIMESTREAM_TABLE_NAME=$(K6_TIMESTREAM_TABLE_NAME) \
$(if $(GRAFANA_IMAGE_NAME),IMAGE_NAME=$(GRAFANA_IMAGE_NAME),) \
$(if $(GRAFANA_FULL_IMAGE_NAME),FULL_IMAGE_NAME=$(GRAFANA_FULL_IMAGE_NAME),) \
$(if $(CACHE_NAME),CACHE_NAME=$(CACHE_NAME),) \
VERSION=$(VERSION)
.PHONY: grafana-%
grafana-%:
make $(GRAFANA_ARGS) -C grafana $*