diff --git a/justfile b/justfile deleted file mode 100644 index 64b4549..0000000 --- a/justfile +++ /dev/null @@ -1,267 +0,0 @@ -# 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", "16.2") -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", "pg16") -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" / "uids-postgres" + 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/uids-postgres$({{just}} print-version) - cp -r $({{just}} print-pkg-output-dir)/* pkg/uids-postgres$({{just}} print-version) - {{tar}} -C pkg -cvf uids-postgres$(just print-version){{pkg_tarball_suffix}}.tar.gz uids-postgres$({{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", "16.2") -pg_os_image_version := env_var_or_default("POSTGRES_OS_IMAGE_VERSION", "alpine3.18") - -uids_postgres_image_name := env_var_or_default("UIDS_POSTGRES_IMAGE_NAME", "ghcr.io/spa5k/pg_idkit") -uids_postgres_image_tag := env_var_or_default("POSGRES_IMAGE_VERSION", version + "-" + "pg" + pg_image_version + "-" + pg_os_image_version + "-" + container_img_arch) -uids_postgres_image_tag_suffix := env_var_or_default("UIDS_POSTGRES_IMAGE_TAG_SUFFIX", "") -uids_postgres_image_name_full := env_var_or_default("UIDS_POSTGRES_IMAGE_NAME_FULL", uids_postgres_image_name + ":" + uids_postgres_image_tag + uids_postgres_image_tag_suffix) -uids_postgres_dockerfile_path := env_var_or_default("UIDS_POSTGRES_DOCKERFILE_PATH", "infra" / "docker" / uids_postgres_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/spa5k/pg_idkit") -docker_config_dir := env_var_or_default("DOCKER_CONFIG", "secrets/docker") - -img_dockerfile_path := "infra" / "docker" / "uids-postgrespg" + 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/spa5k/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/spa5k/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/spa5k/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/spa5k/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 {{uids_postgres_image_name_full}} --build-arg USER={{docker_build_user}} --build-arg UIDS_POSTGRES_REVISION={{revision}} --build-arg UIDS_POSTGRES_VERSION={{uids_postgres_image_tag}} . - -# Push the docker image for pg_idkit -push-image: - {{docker}} push {{uids_postgres_image_name_full}} - -####### -# RPM # -####### - -rpm_arch := env_var_or_default("RPM_ARCH", "x86_64") - -rpm_file_name := env_var_or_default("RPM_OUTPUT_PATH", "uids-postgres" + 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}} \ No newline at end of file