Skip to content

Commit

Permalink
feat(infra): add RPM package
Browse files Browse the repository at this point in the history
While pg_idkit is not limited to linux distributions that support
RPMs, given that some users have requested an RPM package be produced
for pg_idkit, and there exists easy integration for publishing
RPMs (thakns to `cargo-generate-rpm`), it is easy to add some support
for RPMs

This commit adds an RPM package that is produced upon every major
release tag, utilizing cargo-generate-rpm.

While the pg_idkit does not currently go as far as to register the RPM
with any official entity, RPM releases will be made available vai GitHub releases.

Signed-off-by: vados <[email protected]>
  • Loading branch information
t3hmrman committed Nov 29, 2023
1 parent 0ba46a8 commit e03df11
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 6 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/rpm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: rpm

on:
push:
branches:
- feat/infra/add-rpm-package
tags:
- v[0-9]+\.[0-9]+\.[0-9]+

jobs:
build:
strategy:
matrix:
config:
- gh:
runner: ubuntu-latest
rpm:
arch: x86_64
pgrx:
version: pg15
runs-on: ${{ matrix.config.gh.runner }}
env:
CARGO_PROFILE: "ci"
PGRX_PG_VERSION: ${{ matrix.config.pgrx.version }}
RPM_ARCH: ${{ matrix.config.rpm.arch }}

steps:
- uses: actions/checkout@v3

- uses: Swatinem/rust-cache@v2

- name: Cache default PGRX_HOME
uses: actions/cache@v2
continue-on-error: false
with:
path: |
/home/runner/.pgrx
key: pg_idkit-pkg-rpm-pgrx-${{ matrix.config.rpm.arch }}-${{ runner.os }}

- name: Install Rust deps
uses: taiki-e/install-action@v2
with:
tool: cargo-binstall,cargo-get,just,cargo-generate-rpm,[email protected]

- name: Initialize cargo-pgrx
run: |
[[ -d /home/runner/.pgrx ]] || cargo pgrx init
- name: Build RPM
run: just package build-rpm

- name: Get RPM output path
id: rpm-output
run: |
echo path=$(just print-rpm-output-path) >> $GITHUB_OUTPUT
echo filename=$(just print-rpm-output-file-name) >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.rpm-output.outputs.filename }}
path: ${{ steps.rpm-output.outputs.path }}
51 changes: 50 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "pg_idkit"
version = "0.1.0"
edition = "2021"
authors = ["Victor Adossi <[email protected]>"]
license = "MIT"
rust-version = "1.73.0"
description = """
A Postgres extension for generating UUIDs
Expand Down Expand Up @@ -56,4 +57,52 @@ codegen-units = 1

[profile.ci]
inherits = "test"
incremental = false
incremental = false

[package.metadata.generate-rpm]
assets = []

[package.metadata.generate-rpm.variants.pg11]
assets = [
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/lib/postgresql/pg_idkit.so", dest = "/usr/lib64/pgsql/pg_idkit.so", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit--0.1.0.sql", dest = "/usr/share/pgsql/extension/pg_idkit--0.1.0.sql", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit.control", dest = "/usr/share/pgsql/extension/pg_idkit.control", mode = "755" },
]
requires = { postgresql-server = "> 11", glibc = "*" }
release = "pg11"

[package.metadata.generate-rpm.variants.pg12]
assets = [
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/lib/postgresql/pg_idkit.so", dest = "/usr/lib64/pgsql/pg_idkit.so", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit--0.1.0.sql", dest = "/usr/share/pgsql/extension/pg_idkit--0.1.0.sql", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit.control", dest = "/usr/share/pgsql/extension/pg_idkit.control", mode = "755" },
]
requires = { postgresql-server = "> 12", glibc = "*" }
release = "pg12"

[package.metadata.generate-rpm.variants.pg13]
assets = [
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/lib/postgresql/pg_idkit.so", dest = "/usr/lib64/pgsql/pg_idkit.so", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit--0.1.0.sql", dest = "/usr/share/pgsql/extension/pg_idkit--0.1.0.sql", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit.control", dest = "/usr/share/pgsql/extension/pg_idkit.control", mode = "755" },
]
requires = { postgresql-server = "> 13", glibc = "*" }
release = "pg13"

[package.metadata.generate-rpm.variants.pg14]
assets = [
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/lib/postgresql/pg_idkit.so", dest = "/usr/lib64/pgsql/pg_idkit.so", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit--0.1.0.sql", dest = "/usr/share/pgsql/extension/pg_idkit--0.1.0.sql", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit.control", dest = "/usr/share/pgsql/extension/pg_idkit.control", mode = "755" },
]
requires = { postgresql-server = "> 14", glibc = "*" }
release = "pg14"

[package.metadata.generate-rpm.variants.pg15]
assets = [
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/lib/postgresql/pg_idkit.so", dest = "/usr/lib64/pgsql/pg_idkit.so", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit--0.1.0.sql", dest = "/usr/share/pgsql/extension/pg_idkit--0.1.0.sql", mode = "755" },
{ source = "/tmp/pg_idkit/rpm/scratch/pgrx-install/share/postgresql/extension/pg_idkit.control", dest = "/usr/share/pgsql/extension/pg_idkit.control", mode = "755" },
]
requires = { postgresql-server = "> 15", glibc = "*" }
release = "pg15"
58 changes: 53 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
user := env_var('USER')

docker := env_var_or_default("DOCKER", "docker")
git := env_var_or_default("GIT", "git")
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 != "" {
"--features " + cargo_features
} else {
""
}

changelog_path := "CHANGELOG"

pkg_pg_version := env_var_or_default("PKG_PG_VERSION", "15.5")
pkg_pg_config_path := env_var_or_default("PKG_PG_CONFIG_PATH", "~/.pgrx/" + pkg_pg_version + "/pgrx-install/bin/pg_config")

pgrx_pg_version := env_var_or_default("PGRX_PG_VERSION", "pg15")
pgrx_pkg_output_dir := "target" / "release" / "pg_idkit-" + pgrx_pg_version / "home" / user / ".pgrx" / pkg_pg_version / "pgrx-install"

default:
{{just}} --list

Expand All @@ -37,6 +53,12 @@ _check-installed-version tool msg:
@_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 #
#########
Expand Down Expand Up @@ -64,19 +86,19 @@ changelog:
{{git}} cliff --unreleased --tag=$(VERSION) --prepend=$(CHANGELOG_FILE_PATH)

build:
{{cargo}} build {{cargo_profile_arg}}
{{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

pkg_pg_version := env_var_or_default("PKG_PG_VERSION", "15.5")
pkg_pg_config_path := env_var_or_default("PKG_PG_CONFIG_PATH", "~/.pgrx/" + pkg_pg_version + "/pgrx-install/bin/pg_config")

package:
{{cargo}} pgrx package --pg-config {{pkg_pg_config_path}}
PGRX_IGNORE_RUST_VERSIONS=y {{cargo}} pgrx package --pg-config {{pkg_pg_config_path}}

test:
{{cargo}} test {{cargo_profile_arg}}
Expand Down Expand Up @@ -185,3 +207,29 @@ build-image:
# 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}} build-release
{{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}}

0 comments on commit e03df11

Please sign in to comment.