-
Notifications
You must be signed in to change notification settings - Fork 9
/
Justfile
267 lines (207 loc) · 10.9 KB
/
Justfile
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
# Choose sell based on platform
shell := if os() == "macos" { "zsh" } else { "bash" }
docker := env_var_or_default("DOCKER", "docker")
git := env_var_or_default("GIT", "git")
tar := env_var_or_default("TAR", "tar")
strip := env_var_or_default("STRIP", "strip")
just := env_var_or_default("JUST", just_executable())
cargo := env_var_or_default("CARGO", "cargo")
cargo_get := env_var_or_default("CARGO_GET", "cargo-get")
cargo_generate_rpm := env_var_or_default("CARGO_GENERATE_RPM", "cargo-generate-rpm")
cargo_watch := env_var_or_default("CARGO_WATCH", "cargo-watch")
cargo_profile := env_var_or_default("CARGO_PROFILE", "")
cargo_profile_arg := if cargo_profile != "" {
"--profile " + cargo_profile
} else {
""
}
cargo_features := env_var_or_default("CARGO_FEATURES", "")
cargo_features_arg := if cargo_features != "" {
"--no-default-features --features " + cargo_features
} else {
""
}
changelog_file_path := absolute_path(justfile_directory() / "CHANGELOG")
pkg_pg_version := env_var_or_default("PKG_PG_VERSION", "17.0")
pkg_pg_config_path := env_var_or_default("PKG_PG_CONFIG_PATH", "~/.pgrx/" + pkg_pg_version + "/pgrx-install/bin/pg_config")
pkg_tarball_suffix := env_var_or_default("PKG_TARBALL_SUFFIX", "")
pgrx_pg_version := env_var_or_default("PGRX_PG_VERSION", "pg17")
pgrx_pkg_path_prefix := env_var_or_default("PGRX_PKG_PATH_PREFIX", "target")
# If /root, 'home' does not appear in the generated prefix
pkg_user_dir_prefix := if docker_build_user == "root" { docker_build_user } else { "home/" + docker_build_user }
pgrx_pkg_output_dir := pgrx_pkg_path_prefix / "release" / "pg_idkit-" + pgrx_pg_version / pkg_user_dir_prefix / ".pgrx" / pkg_pg_version / "pgrx-install"
docker_build_user := env_var_or_default('DOCKER_BUILD_USER', "root")
default:
{{just}} --list
###########
# Tooling #
###########
_check-installed-version tool msg:
#!/usr/bin/env -S {{shell}} -euo pipefail
if [ -z "$(command -v {{tool}})" ]; then
echo "{{msg}}";
exit 1;
fi
@_check-tool-cargo:
{{just}} _check-installed-version {{cargo}} "'cargo' not available, please install the Rust toolchain (see: https://github.com/rust-lang/cargo/)";
@_check-tool-cargo-watch:
{{just}} _check-installed-version {{cargo_watch}} "'cargo-watch' not available, please install cargo-watch (https://github.com/passcod/cargo-watch)"
@_check-tool-cargo-get:
{{just}} _check-installed-version {{cargo_get}} "'cargo-get' not available, please install cargo-get (https://crates.io/crates/cargo-get)"
@_check-tool-strip:
{{just}} _check-installed-version {{strip}} "'strip' not available, please install strip (https://www.man7.org/linux/man-pages/man1/strip.1.html)"
@_check-tool-cargo-generate-rpm:
{{just}} _check-installed-version {{cargo_generate_rpm}} "'cargo-generate-rpm' not available, please install cargo-generate-rpm (https://crates.io/crates/cargo-generate-rpm)"
#########
# Build #
#########
version := env_var_or_default("VERSION", `cargo get package.version`)
revision := env_var_or_default("REVISION", `git rev-parse --short HEAD`)
@get-version: _check-tool-cargo-get
echo -n {{version}}
@get-revision: _check-tool-cargo-get
echo -n {{revision}}
print-version:
#!/usr/bin/env -S {{shell}} -euo pipefail
echo -n `{{just}} get-version`
print-revision:
#!/usr/bin/env -S {{shell}} -euo pipefail
echo -n `{{just}} get-revision`
print-pkg-output-dir:
echo -n {{pgrx_pkg_output_dir}}
changelog:
{{git}} cliff --unreleased --tag={{version}} --prepend={{changelog_file_path}}
# Set the version on the package
set-version version:
{{cargo}} set-version {{version}}
lint:
{{cargo}} clippy {{cargo_features_arg}} {{cargo_profile_arg}} --all-targets
build:
{{cargo}} build {{cargo_features_arg}} {{cargo_profile_arg}}
build-release:
{{cargo}} build --release {{cargo_features_arg}}
build-watch: _check-tool-cargo _check-tool-cargo-watch
{{cargo_watch}} -x "build $(CARGO_BUILD_FLAGS)" --watch src
build-test-watch: _check-tool-cargo _check-tool-cargo-watch
{{cargo_watch}} -x "test $(CARGO_BUILD_FLAGS)" --watch src
build-package:
PGRX_IGNORE_RUST_VERSIONS=y {{cargo}} pgrx package --pg-config {{pkg_pg_config_path}} -vvv
package: build-package
mkdir -p pkg/pg_idkit-$({{just}} print-version)
cp -r $({{just}} print-pkg-output-dir)/* pkg/pg_idkit-$({{just}} print-version)
{{tar}} -C pkg -cvf pg_idkit-$(just print-version){{pkg_tarball_suffix}}.tar.gz pg_idkit-$({{just}} print-version)
test:
{{cargo}} test {{cargo_profile_arg}}
{{cargo}} pgrx test
pgrx-init:
#!/usr/bin/env -S {{shell}} -euo pipefail
if [ ! -d "{{pkg_pg_config_path}}" ]; then
echo "failed to find pgrx init dir [{{pkg_pg_config_path}}], running pgrx init...";
{{cargo}} pgrx init
fi
##########
# Docker #
##########
container_img_arch := env_var_or_default("CONTAINER_IMAGE_ARCH", "amd64")
pg_image_version := env_var_or_default("POSTGRES_IMAGE_VERSION", "17.0")
pg_os_image_version := env_var_or_default("POSTGRES_OS_IMAGE_VERSION", "alpine3.20.3")
pgidkit_image_name := env_var_or_default("PGIDKIT_IMAGE_NAME", "ghcr.io/vadosware/pg_idkit")
pgidkit_image_tag := env_var_or_default("POSGRES_IMAGE_VERSION", version + "-" + "pg" + pg_image_version + "-" + pg_os_image_version + "-" + container_img_arch)
pgidkit_image_tag_suffix := env_var_or_default("PGIDKIT_IMAGE_TAG_SUFFIX", "")
pgidkit_image_name_full := env_var_or_default("PGIDKIT_IMAGE_NAME_FULL", pgidkit_image_name + ":" + pgidkit_image_tag + pgidkit_image_tag_suffix)
pgidkit_dockerfile_path := env_var_or_default("PGIDKIT_DOCKERFILE_PATH", "infra" / "docker" / pgidkit_image_tag + ".Dockerfile")
docker_password_path := env_var_or_default("DOCKER_PASSWORD_PATH", "secrets/docker/password.secret")
docker_username_path := env_var_or_default("DOCKER_USERNAME_PATH", "secrets/docker/username.secret")
docker_image_registry := env_var_or_default("DOCKER_IMAGE_REGISTRY", "ghcr.io/vadosware/pg_idkit")
docker_config_dir := env_var_or_default("DOCKER_CONFIG", "secrets/docker")
img_dockerfile_path := "infra" / "docker" / "pg_idkit-pg" + pg_image_version + "-" + pg_os_image_version + "-" + container_img_arch + ".Dockerfile"
# Ensure that that a given file is present
_ensure-file file:
#!/usr/bin/env -S {{shell}} -euo pipefail
if [ ! -f "{{file}}" ] ; then
echo "[error] file [{{file}}] is required, but missing";
exit 1;
fi;
# Log in with docker using local credentials
docker-login:
{{just}} _ensure-file {{docker_password_path}}
{{just}} _ensure-file {{docker_username_path}}
cat {{docker_password_path}} | {{docker}} login {{docker_image_registry}} -u `cat {{docker_username_path}}` --password-stdin
cp {{docker_config_dir}}/config.json {{docker_config_dir}}/.dockerconfigjson
docker_platform_arg := env_var_or_default("DOCKER_PLATFORM_ARG", "")
docker_progress_arg := env_var_or_default("DOCKER_PROGRESS_ARG", "")
##########################
# Docker Image - builder #
##########################
#
# This image is used as a cache for speeding up CI builds,
# and for performing builds when building release artifacts
#
builder_gnu_dockerfile_path := env_var_or_default("BUILDER_DOCKERFILE_PATH", "infra" / "docker" / "builder-gnu.Dockerfile")
builder_gnu_image_name := env_var_or_default("BUILDER_IMAGE_NAME", "ghcr.io/vadosware/pg_idkit/builder-gnu")
builder_gnu_image_tag := env_var_or_default("BUILDER_IMAGE_TAG", "0.1.x")
builder_gnu_image_name_full := env_var_or_default("BUILDER_IMAGE_NAME_FULL", builder_gnu_image_name + ":" + builder_gnu_image_tag)
## TODO: uncomment and edit build-builder-image once musl machinery is available
## https://github.com/VADOSWARE/pg_idkit/issues/55
#
# builder_musl_dockerfile_path := env_var_or_default("BUILDER_DOCKERFILE_PATH", "infra" / "docker" / "builder-musl.Dockerfile")
# builder_musl_image_name := env_var_or_default("BUILDER_IMAGE_NAME", "ghcr.io/vadosware/pg_idkit/builder-musl")
# builder_musl_image_tag := env_var_or_default("BUILDER_IMAGE_TAG", "0.1.x")
# builder_musl_image_name_full := env_var_or_default("BUILDER_IMAGE_NAME_FULL", builder_musl_image_name + ":" + builder_musl_image_tag)
# Build the docker image used in BUILDER
build-builder-image:
{{docker}} build -f {{builder_gnu_dockerfile_path}} -t {{builder_gnu_image_name_full}} .
# Push the docker image used in BUILDER (to GitHub Container Registry)
push-builder-image:
{{docker}} push {{builder_gnu_image_name_full}}
###########################
# Docker Image - base-pkg #
###########################
#
# This image is used as a base for packaging flows, usually while building
# the end-user facing Docker image that is contains Postgres & pg_idkit
#
# Determine the Dockerfile to use when building the packaging utility base image
base_pkg_dockerfile_path := "infra/docker/base-pkg-" + pg_os_image_version + "-" + container_img_arch + ".Dockerfile"
base_pkg_image_name := env_var_or_default("PKG_IMAGE_NAME", "ghcr.io/vadosware/pg_idkit/base-pkg")
base_pkg_version := env_var_or_default("PKG_IMAGE_NAME", "0.1.x")
base_pkg_image_tag := env_var_or_default("POSGRES_IMAGE_VERSION", base_pkg_version + "-" + pg_os_image_version + "-" + container_img_arch)
base_pkg_image_name_full := env_var_or_default("PKG_IMAGE_NAME_FULL", base_pkg_image_name + ":" + base_pkg_image_tag)
# Build the base image for packaging
build-base-pkg-image:
{{docker}} build --build-arg USER={{docker_build_user}} -f {{base_pkg_dockerfile_path}} . -t {{base_pkg_image_name_full}};
# Push the base image for packaging
push-base-pkg-image:
{{docker}} push {{base_pkg_image_name_full}}
###########################
# Docker Image - pg_idkit #
###########################
#
# This image is the pg_idkit image itself, normally built FROM
# a image of base-pkg
#
# Build the docker image for pg_idkit
build-image:
{{docker}} build {{docker_platform_arg}} {{docker_progress_arg}} -f {{img_dockerfile_path}} -t {{pgidkit_image_name_full}} --build-arg USER={{docker_build_user}} --build-arg PGIDKIT_REVISION={{revision}} --build-arg PGIDKIT_VERSION={{pgidkit_image_tag}} .
# Push the docker image for pg_idkit
push-image:
{{docker}} push {{pgidkit_image_name_full}}
#######
# RPM #
#######
rpm_arch := env_var_or_default("RPM_ARCH", "x86_64")
rpm_file_name := env_var_or_default("RPM_OUTPUT_PATH", "pg_idkit-" + version + "-" + pgrx_pg_version + "." + rpm_arch + ".rpm")
rpm_output_path := "target" / "generate-rpm" / rpm_file_name
# Cargo.toml depends on this file being at the location below.
rpm_scratch_location := "/tmp/pg_idkit/rpm/scratch"
# Build an RPM distribution for pg_idkit
build-rpm: _check-tool-strip _check-tool-cargo-generate-rpm
CARGO_FEATURES={{pgrx_pg_version}} {{just}} package
{{strip}} -s {{pgrx_pkg_output_dir}}/lib/postgresql/pg_idkit.so
mkdir -p {{rpm_scratch_location}}
cp -r {{pgrx_pkg_output_dir}} {{rpm_scratch_location}}
{{cargo_generate_rpm}} --variant {{pgrx_pg_version}}
@print-rpm-output-file-name:
echo -n {{rpm_file_name}}
@print-rpm-output-path:
echo -n {{rpm_output_path}}