Skip to content

Commit 94f5c26

Browse files
committed
fix: postgres example dockerfile
1 parent 3ba559b commit 94f5c26

File tree

6 files changed

+56
-21
lines changed

6 files changed

+56
-21
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[target.'cfg(target_os="macos")']
22
# Postgres symbols won't be available until runtime
3-
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup", "-C target-feature=+aes,+sse2"]
3+
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
44

55
[target.'cfg(target_arch = "x86_64")']
66
rustflags = ["-C", "target-feature=+aes"]

.github/workflows/release.yaml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Build and Publish TypeID Extension
22

3+
permissions:
4+
contents: write
5+
36
on:
47
push:
58
tags:
@@ -12,13 +15,14 @@ env:
1215
jobs:
1316
build-and-publish:
1417
strategy:
18+
fail-fast: false # We want all of them to run, even if one fails
1519
matrix:
16-
pg_version: [11, 12, 13, 14, 15, 16]
20+
pg_version: [12, 13, 14, 15, 16]
1721
os: [ubuntu-latest, macos-latest]
1822
arch: [amd64, arm64]
1923
exclude:
2024
- os: macos-latest
21-
arch: arm64
25+
arch: amd64
2226

2327
runs-on: ${{ matrix.os }}
2428

@@ -40,26 +44,46 @@ jobs:
4044
sudo apt-get update -y -qq --fix-missing
4145
sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
4246
47+
sudo chmod a+rwx `/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config --pkglibdir` `/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config --sharedir`/extension /var/run/postgresql/
48+
4349
- name: Install PostgreSQL (macOS)
4450
if: runner.os == 'macOS'
4551
run: |
4652
brew install postgresql@${{ matrix.pg_version }}
4753
echo "/usr/local/opt/postgresql@${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
4854
49-
- name: Build Extension
55+
- name: Install cargo-pgrx
5056
run: |
51-
cargo pgrx init
52-
cargo pgrx package --pg-config /usr/bin/pg_config-${{ matrix.pg_version }}
57+
if [ "${{ runner.os }}" == "Linux" ]; then
58+
PG_CONFIG_PATH="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
59+
else
60+
PG_CONFIG_PATH="/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin/pg_config"
61+
fi
62+
PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
63+
cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
64+
cargo pgrx init --pg${{ matrix.pg_version }} $PG_CONFIG_PATH
65+
66+
- name: Build
67+
run: |
68+
if [ "${{ runner.os }}" == "Linux" ]; then
69+
PG_CONFIG_PATH="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
70+
else
71+
PG_CONFIG_PATH="/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin/pg_config"
72+
fi
73+
cargo pgrx package --features pg${{ matrix.pg_version }} --pg-config $PG_CONFIG_PATH
74+
75+
- name: Set lowercase OS name
76+
run: echo "LOWERCASE_OS=$(echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
5377

5478
- name: Package Extension
5579
run: |
5680
mkdir -p release
57-
tar -czvf release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ runner.os }}-${{ matrix.arch }}.tar.gz -C target/release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }} .
81+
tar -czvf release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ env.LOWERCASE_OS }}-${{ matrix.arch }}.tar.gz -C target/release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }} .
5882
5983
- name: Upload Release Asset
6084
uses: softprops/action-gh-release@v1
6185
with:
62-
files: release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ runner.os }}-${{ matrix.arch }}.tar.gz
86+
files: release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ env.LOWERCASE_OS }}-${{ matrix.arch }}.tar.gz
6387

6488
build-and-push-docker:
6589
needs: build-and-publish

Dockerfile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
ARG PG_VERSION=16
2+
13
# Stage 1: Build the extension
2-
FROM rust:latest as builder
4+
FROM rust:latest AS builder
35

46
ARG PG_VERSION=16
57

@@ -17,18 +19,21 @@ WORKDIR /usr/src/typeid
1719
COPY . .
1820

1921
RUN cargo install cargo-pgrx \
20-
&& cargo pgrx init \
21-
&& cargo pgrx package --pg-config /usr/bin/pg_config-${PG_VERSION}
22+
&& cargo pgrx init --pg${PG_VERSION} /usr/lib/postgresql/${PG_VERSION}/bin/pg_config \
23+
&& cargo pgrx package --pg-config /usr/lib/postgresql/${PG_VERSION}/bin/pg_config
24+
25+
RUN ls -R /usr/src/typeid/target/release/
2226

2327
# Stage 2: Create the final Postgres image with the extension
2428
FROM postgres:${PG_VERSION}
2529

2630
ARG PG_VERSION=16
2731

2832
# Copy the built extension files from the builder stage
29-
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid.control /usr/share/postgresql/extension/
30-
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/lib/postgresql/${PG_VERSION}/lib/typeid.so /usr/lib/postgresql/lib/
31-
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid--0.0.0.sql /usr/share/postgresql/extension/
33+
# Copy the built extension files
34+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/lib/postgresql/${PG_VERSION}/lib/typeid.so /usr/lib/postgresql/${PG_VERSION}/lib/
35+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid.control /usr/share/postgresql/${PG_VERSION}/extension/
36+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid--0.1.0.sql /usr/share/postgresql/${PG_VERSION}/extension/
3237

3338
# Enable the extension
3439
RUN echo "shared_preload_libraries = 'typeid'" >> /usr/share/postgresql/postgresql.conf.sample

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ age | Internal name | Description
8686
public | typeid_lt | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_lt_wrapper |
8787
public | typeid_ne | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_ne_wrapper |
8888
public | typeid_out | cstring | input typeid | func | immutable | safe | codespace | invoker | | c | typeid_out_wrapper |
89-
public | uuid_generate_v7 | uuid | | func | volatile | unsafe | codespace | invoker | | c | uuid_generate_v7_wrapper |
89+
public | typeid_uuid_generate_v7 | uuid | | func | volatile | unsafe | codespace | invoker | | c | uuid_generate_v7_wrapper |
9090
(11 rows)
9191
```

install.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
set -e
44

5+
# Check if a custom pg_config path is provided
6+
if [ $# -eq 1 ]; then
7+
PG_CONFIG="$1"
8+
else
9+
PG_CONFIG=$(which pg_config)
10+
fi
11+
512
# Function to get the latest release version
613
get_latest_release() {
714
curl --silent "https://api.github.com/repos/blitss/typeid-postgres/releases/latest" |
@@ -23,10 +30,10 @@ else
2330
fi
2431

2532
# Get PostgreSQL version
26-
PG_VERSION=$(psql -V | sed -n 's/^psql (PostgreSQL) \([0-9]\+\).*$/\1/p')
33+
PG_VERSION=$("$PG_CONFIG" --version | awk '{print $2}' | cut -d. -f1)
2734

2835
if [ -z "$PG_VERSION" ]; then
29-
echo "PostgreSQL not found. Please install PostgreSQL and make sure 'psql' is in your PATH."
36+
echo "PostgreSQL not found. Please install PostgreSQL and make sure 'pg_config' is in your PATH or provide the path to pg_config as an argument."
3037
exit 1
3138
fi
3239

@@ -40,11 +47,10 @@ DOWNLOAD_URL="https://github.com/blitss/typeid-postgres/releases/download/${RELE
4047
TMP_DIR=$(mktemp -d)
4148

4249
# Download and extract
43-
echo "Downloading TypeID extension..."
50+
echo "Downloading TypeID extension from $DOWNLOAD_URL"
4451
curl -L "$DOWNLOAD_URL" | tar xz -C "$TMP_DIR"
4552

4653
# Get PostgreSQL directories
47-
PG_CONFIG=$(which pg_config)
4854
EXTENSION_DIR=$("$PG_CONFIG" --sharedir)/extension
4955
LIB_DIR=$("$PG_CONFIG" --pkglibdir)
5056

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ r#"
144144

145145
/// Generate a UUID v7, producing a Postgres uuid object
146146
#[pg_extern]
147-
fn uuid_generate_v7() -> pgrx::Uuid {
147+
fn typeid_uuid_generate_v7() -> pgrx::Uuid {
148148
pgrx::Uuid::from_bytes(*Uuid::now_v7().as_bytes())
149149
}
150150

@@ -163,7 +163,7 @@ mod tests {
163163

164164
#[pg_test]
165165
fn test_uuid() {
166-
let uuid: pgrx::Uuid = crate::uuid_generate_v7();
166+
let uuid: pgrx::Uuid = crate::typeid_uuid_generate_v7();
167167
let converted: Uuid = Uuid::from_slice(uuid.as_bytes()).unwrap();
168168

169169
println!("UUID: {:?}", uuid.to_string());

0 commit comments

Comments
 (0)