This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
328 lines (280 loc) · 12.6 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
.DEFAULT_GOAL := help
ARCH ?= $(shell uname -m)
# This little workaround allows usage of the '#' character on both gnu make 3.8 and 4.3+
H := \#
# We want to be able to execute `sudo make install`, but cargo and rustc are probably both
# not available for sudo, so we use `command -v` to only run them if they are available
EXT_VERSION ?= $(shell command -v cargo >/dev/null && ./extract-extension-version.sh | tr -d '\n')
RUST_VERSION ?= $(shell command -v rustc >/dev/null && rustc --version | cut -d' ' -f2)
SQL_FILENAME ?= sql/promscale--${EXT_VERSION}.sql
IMAGE_NAME ?= timescaledev/promscale-extension
OS_NAME ?= debian
OS_VERSION ?= 11
PG_CONFIG ?= pg_config
PG_RELEASE_VERSION ?= $(shell ${PG_CONFIG} --version | awk -F'[ \. ]' '{print $$2}')
PG_BUILD_VERSION = $(shell ${PG_CONFIG} --version | awk -F'[ \. ]' '{print $$2}')
# If set to a non-empty value, docker builds will be pushed to the registry
PUSH ?=
TIMESCALEDB_VERSION_FULL=2.9.1
TIMESCALEDB_VERSION_MAJMIN=$(shell echo $(TIMESCALEDB_VERSION_FULL) | cut -d. -f 1,2)
TIMESCALEDB_VERSION_MAJOR=$(shell echo $(TIMESCALEDB_VERSION_FULL) | cut -d. -f 1)
TS_DOCKER_IMAGE ?= local/dev_promscale_extension:head-ts2-pg14
export TS_DOCKER_IMAGE
# Transform ARCH to its Docker platform equivalent
ifeq ($(ARCH),arm64)
DOCKER_PLATFORM=linux/arm64
endif
ifeq ($(ARCH),aarch64)
DOCKER_PLATFORM=linux/arm64
endif
ifeq ($(ARCH),x86_64)
DOCKER_PLATFORM=linux/amd64
endif
ifeq ($(ARCH),amd64)
DOCKER_PLATFORM=linux/amd64
endif
# Calculate the correct dockerfile to use when running the release target
ifeq ($(OS_NAME),debian)
DOCKERFILE = deb.dockerfile
TESTDOCKERFILE = deb.test.dockerfile
DOCKER_DISTRO_NAME = debian
PKG_TYPE = deb
endif
ifeq ($(OS_NAME),ubuntu)
DOCKERFILE = deb.dockerfile
TESTDOCKERFILE = deb.test.dockerfile
DOCKER_DISTRO_NAME = ubuntu
PKG_TYPE = deb
endif
ifeq ($(OS_NAME),centos)
DOCKERFILE = rpm.dockerfile
TESTDOCKERFILE = rpm.test.dockerfile
DOCKER_DISTRO_NAME = centos
PKG_TYPE = rpm
endif
ifeq ($(OS_NAME),rocky)
DOCKERFILE = rpm.dockerfile
TESTDOCKERFILE = rpm.test.dockerfile
DOCKER_DISTRO_NAME = rockylinux
PKG_TYPE = rpm
endif
RELEASE_IMAGE_NAME = promscale-extension-pkg:$(EXT_VERSION)-$(OS_NAME)$(OS_VERSION)-pg$(PG_RELEASE_VERSION)
RELEASE_FILE_NAME = promscale-extension-$(EXT_VERSION).pg$(PG_RELEASE_VERSION).$(OS_NAME)$(OS_VERSION).$(ARCH).$(PKG_TYPE)
.PHONY: help
help:
@echo "promscale_extension $(EXT_VERSION)"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: promscale.control ## Build the extension
cargo build --release --features pg${PG_BUILD_VERSION} $(EXTRA_RUST_ARGS)
.PHONY: clean
clean: clean-generated ## Clean up latest build
cargo clean
.PHONY: clean-generated
clean-generated:
-rm ${SQL_FILENAME}
-rm promscale.control
.PHONY: run-12
run-12: PG_BUILD_VERSION=12
run-12: run
.PHONY: run-13
run-13: PG_BUILD_VERSION=13
run-13: run
.PHONY: run-14
run-14: PG_BUILD_VERSION=14
run-14: run
.PHONY: run
run: promscale.control ## Custom wrapper around cargo pgx run
PGX_FORCE_CREATE_OR_REPLACE=true cargo pgx run pg${PG_BUILD_VERSION}
.PHONY: dependencies
dependencies: promscale.control ## Used in docker build to improve build caching
# both of these steps are also run in the `package` target, so we run them here to provide better caching
cargo pgx schema pg${PG_BUILD_VERSION} --out ${SQL_FILENAME} --release
cargo pgx package --pg-config ${PG_CONFIG}
rm ${SQL_FILENAME}
.PHONY: package
package: promscale.control ## Generate extension artifacts for packaging
cargo pgx schema pg${PG_BUILD_VERSION} --release >/dev/null
cargo pgx schema pg${PG_BUILD_VERSION} --out ${SQL_FILENAME} --release
bash create-upgrade-symlinks.sh
cargo pgx package --pg-config ${PG_CONFIG}
.PHONY: install
install: ## Install the extension in the Postgres found via pg_config
cp -R ./target/release/promscale-pg${PG_BUILD_VERSION}/* /
.PHONY: release
release: dist/$(RELEASE_FILE_NAME) ## Produces release artifacts based on OS_NAME, OS_VERSION, and PG_RELEASE_VERSION
.PHONY: release-builder
release-builder: dist/$(DOCKERFILE) ## Build image with the release artifact for OS_NAME, OS_VERSION, and PG_RELEASE_VERSION
ifndef DOCKERFILE
$(error Unsupported OS_NAME '$(OS_NAME)'! Expected one of debian,ubuntu,centos,rocky)
endif
ifndef DOCKER_PLATFORM
$(error Unsupported ARCH '$(ARCH)'! Expected one of arm64,x86_64)
endif
docker buildx build --load --platform $(DOCKER_PLATFORM) \
--build-arg DOCKER_DISTRO_NAME=$(DOCKER_DISTRO_NAME) \
--build-arg OS_NAME=$(OS_NAME) \
--build-arg OS_VERSION=$(OS_VERSION) \
--build-arg PG_VERSION=$(PG_RELEASE_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg RELEASE_FILE_NAME=$(RELEASE_FILE_NAME) \
--target packager \
-t $(RELEASE_IMAGE_NAME) \
-f dist/$(DOCKERFILE) \
.
dist/$(RELEASE_FILE_NAME): dist/$(DOCKERFILE)
ifndef DOCKERFILE
$(error Unsupported OS_NAME '$(OS_NAME)'! Expected one of debian,ubuntu,centos,rocky)
endif
ifndef DOCKER_PLATFORM
$(error Unsupported ARCH '$(ARCH)'! Expected one of arm64,x86_64)
endif
docker buildx build --progress plain --platform $(DOCKER_PLATFORM) \
--build-arg DOCKER_DISTRO_NAME=$(DOCKER_DISTRO_NAME) \
--build-arg OS_NAME=$(OS_NAME) \
--build-arg OS_VERSION=$(OS_VERSION) \
--build-arg PG_VERSION=$(PG_RELEASE_VERSION) \
--build-arg RUST_VERSION=$(RUST_VERSION) \
--build-arg RELEASE_FILE_NAME=$(RELEASE_FILE_NAME) \
--target bundler \
--load \
-t $(RELEASE_IMAGE_NAME) \
-f dist/$(DOCKERFILE) \
.
docker save --output=./dist/$(RELEASE_FILE_NAME)-docker $(RELEASE_IMAGE_NAME)
@container="$$(docker create $(RELEASE_IMAGE_NAME))"; \
docker cp "$${container}:/dist/$(RELEASE_FILE_NAME)" ./dist; \
touch ./dist/${RELEASE_FILE_NAME}; \
docker rm -f "$${container}"
dist/$(RELEASE_FILE_NAME)-docker-test: dist/$(RELEASE_FILE_NAME) dist/$(TESTDOCKERFILE) ## Build image used for testing a specific release package
ifndef DOCKERFILE
$(error Unsupported OS_NAME '$(OS_NAME)'! Expected one of debian,ubuntu,centos,rocky)
endif
ifndef DOCKER_PLATFORM
$(error Unsupported ARCH '$(ARCH)'! Expected one of arm64,x86_64)
endif
docker buildx build --platform $(DOCKER_PLATFORM) \
--build-arg=DOCKER_DISTRO_NAME=$(DOCKER_DISTRO_NAME) \
--build-arg=DISTRO=$(OS_NAME) \
--build-arg=DISTRO_VERSION=$(OS_VERSION) \
--build-arg=PG_VERSION=$(PG_RELEASE_VERSION) \
--build-arg=RELEASE_FILE_NAME=dist/$(RELEASE_FILE_NAME) \
--load \
-t "$(RELEASE_IMAGE_NAME)-test" \
-f dist/$(TESTDOCKERFILE) \
.
docker save --output=./dist/$(RELEASE_FILE_NAME)-docker-test "$(RELEASE_IMAGE_NAME)-test"
.PHONY: release-test
release-test: dist/$(RELEASE_FILE_NAME)-docker-test ## Test the currently selected release package
docker load --input dist/$(RELEASE_FILE_NAME)-docker-test
./tools/smoke-test "$(RELEASE_IMAGE_NAME)-test" $(DOCKER_PLATFORM)
.PHONY: post-release
post-release: promscale.control
cargo pgx schema pg${PG_BUILD_VERSION} --out ${SQL_FILENAME} --release
bash create-upgrade-symlinks.sh
.PHONY: docker-image-build-12 docker-image-build-13 docker-image-build-14
docker-image-build-12 docker-image-build-13 docker-image-build-14: alpine.Dockerfile $(SQL_FILES) $(SRCS) Cargo.toml Cargo.lock $(RUST_SRCS)
docker buildx build $(if $(PUSH),--push,--load) \
--build-arg TIMESCALEDB_VERSION_FULL=$(TIMESCALEDB_VERSION_FULL) \
--build-arg TIMESCALEDB_VERSION_MAJOR=$(TIMESCALEDB_VERSION_MAJOR) \
--build-arg TIMESCALEDB_VERSION_MAJMIN=$(TIMESCALEDB_VERSION_MAJMIN) \
--build-arg PG_VERSION=$(PG_BUILD_VERSION) \
-t local/dev_promscale_extension:head-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):$(EXT_VERSION)-ts$(TIMESCALEDB_VERSION_FULL)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):$(EXT_VERSION)-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):latest-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
-f alpine.Dockerfile \
.
.PHONY: docker-image-12
docker-image-12: PG_BUILD_VERSION=12
docker-image-12: docker-image-build-12
.PHONY: docker-image-13
docker-image-13: PG_BUILD_VERSION=13
docker-image-13: docker-image-build-13
.PHONY: docker-image-14
docker-image-14: PG_BUILD_VERSION=14
docker-image-14: docker-image-build-14
.PHONY: docker-image
docker-image: docker-image-14 docker-image-13 docker-image-12 ## Build Timescale images with the extension
.PHONY: docker-quick-build-12 docker-quick-build-13 docker-quick-build-14
docker-quick-build-12 docker-quick-build-13 docker-quick-build-14: promscale.control ## A quick way to rebuild the extension image with only SQL changes
cargo pgx schema pg$(PG_BUILD_VERSION)
docker build -f quick.Dockerfile \
--build-arg TIMESCALEDB_VERSION_MAJOR=$(TIMESCALEDB_VERSION_MAJOR) \
--build-arg PG_VERSION=$(PG_BUILD_VERSION) \
--build-arg EXTENSION_VERSION=$(EXT_VERSION) \
-t local/dev_promscale_extension:head-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):$(EXT_VERSION)-ts$(TIMESCALEDB_VERSION_FULL)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):$(EXT_VERSION)-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
-t $(IMAGE_NAME):latest-ts$(TIMESCALEDB_VERSION_MAJOR)-pg$(PG_BUILD_VERSION) \
.
.PHONY: docker-quick-14
docker-quick-14: PG_BUILD_VERSION=14
docker-quick-14: docker-quick-build-14
.PHONY: docker-quick-13
docker-quick-13: PG_BUILD_VERSION=13
docker-quick-13: docker-quick-build-13
.PHONY: docker-quick-12
docker-quick-12: PG_BUILD_VERSION=12
docker-quick-12: docker-quick-build-12
.PHONY: setup-buildx
setup-buildx: ## Setup a Buildx builder
@if ! docker buildx ls | grep buildx-builder >/dev/null; then \
docker buildx create \
--buildkitd-flags '--allow-insecure-entitlement security.insecure' \
--append \
--name buildx-builder \
--driver docker-container \
--use && \
docker buildx inspect --bootstrap --builder buildx-builder; \
fi
promscale.control: ## A hack to boostrap the build, some pgx commands require this file. It gets re-generated later.
cp templates/promscale.control ./promscale.control
DEVENV_CONTAINER_NAME = promscale-extension-devcontainer
.PHONY: devcontainer
devcontainer: ## Builds an image for an interactive development container, that includes TimescaleDB with this extension
docker build -f dev.Dockerfile -t ${DEVENV_CONTAINER_NAME} .
DEVENV_PG_VERSION ?= ${PG_BUILD_VERSION}
DEVENV_PG_INTERNAL_PORT ?= 288${DEVENV_PG_VERSION}
.PHONY: devenv-internal-build-install
devenv-internal-build-install: clean-generated promscale.control
cargo pgx install --features="pg${DEVENV_PG_VERSION}"
DEVENV_ENTR ?= 1
.PHONY: devenv
devenv: VOLUME_NAME=promscale-extension-build-cache
devenv: devcontainer promscale.control ## Starts an interactive container from an image built by devcontainer target. It monitors working directory and re-builds/re-installs the extension.
docker volume inspect ${VOLUME_NAME} 1>/dev/null 2>&1 || docker volume create ${VOLUME_NAME}
docker run --rm -v ${VOLUME_NAME}:/tmp/target ubuntu bash -c "chmod a+w /tmp/target"
docker run -ti -e DEVENV_ENTR=${DEVENV_ENTR} -e DEVENV_PG_VERSION=${DEVENV_PG_VERSION} --rm -v ${VOLUME_NAME}:/tmp/target -p54321:${DEVENV_PG_INTERNAL_PORT} -v$(shell pwd):/code --name ${DEVENV_CONTAINER_NAME} ${DEVENV_CONTAINER_NAME}
.PHONY: devenv-no-entr
devenv-no-entr: DEVENV_ENTR=0
devenv-no-entr: devenv
POSTGRES_URL ?= $(shell $(MAKE) devenv-url)
.PHONY: devenv-export-url
devenv-export-url:
@echo "export POSTGRES_URL=${POSTGRES_URL}"
.PHONY: devenv-url
devenv-url: ## Outputs PSQL url that can be used to connect to the devenv
@echo "postgres://ubuntu@localhost:54321/"
.PHONY: sql-tests
sql-tests: ## Run tests from sql-tests workspace
POSTGRES_URL=${POSTGRES_URL} cargo test -p sql-tests
.PHONY: gendoc
gendoc: ## Generate SQL API documentation
POSTGRES_URL=${POSTGRES_URL} cargo run -p gendoc > docs/sql-api.md
DEVENV_EXEC ?= docker exec -it -e POSTGRES_URL=postgres://ubuntu@localhost:${DEVENV_PG_INTERNAL_PORT}/ ${DEVENV_CONTAINER_NAME}
.PHONY: dev-sql-tests
dev-sql-tests: ## Run tests from sql-tests workspace within the devenv. The devenv must be started separately.
${DEVENV_EXEC} make sql-tests
.PHONY: dev-gendoc
dev-gendoc: ## Generate SQL API documentation within the devenv. The devenv must be started separately.
${DEVENV_EXEC} make gendoc
.PHONY: dev-build
dev-build: ## (Re)builds and installs the extension inside the devenv container. The devenv must be started separately.
${DEVENV_EXEC} make devenv-internal-build-install
.PHONY: dev-bash
dev-bash: ## Gets a bash shell inside the devenv container. The devenv must be started separately.
${DEVENV_EXEC} bash
.PHONY: dev-psql
dev-psql: ## Gets a psql shell connected to the devenv container. The devenv must be started separately.
psql "${POSTGRES_URL}"