Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pgsodium Postgres extension #11

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [ main ]
workflow_dispatch:
jobs:
core_build_and_test:
test_core:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -19,7 +19,7 @@ jobs:
- name: Run tests
run: |
cargo test -- --skip smoke_memory
core_memory_consumption:
test_memory_consumption:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -34,7 +34,7 @@ jobs:
if [ $MEM_KB -gt 550000 ]; then
exit 1
fi
service_build_and_test:
test_service:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -47,7 +47,7 @@ jobs:
run: |
export MERITRANK_NUM_WALK=50
cargo test
connector_build_and_test:
test_psql_connector:
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -79,3 +79,27 @@ jobs:
run: |
export RUST_TEST_THREADS=1
cargo pgrx test --runas postgres --pgdata /var/lib/postgresql/pgrx
test_docker_service:
needs: [ test_core, test_memory_consumption, test_service, test_psql_connector ]
if: success()
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./service
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: |
docker build -f ./Dockerfile ..
test_docker_psql_connector:
needs: [ test_core, test_memory_consumption, test_service, test_psql_connector ]
if: success()
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./psql-connector
steps:
- uses: actions/checkout@v4
- name: Build docker image
run: |
docker build -f ./Dockerfile ..
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
export MERITRANK_NUM_WALK=50
cargo test
test_connector:
test_psql_connector:
runs-on: ubuntu-latest
defaults:
run:
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
export RUST_TEST_THREADS=1
cargo pgrx test --runas postgres --pgdata /var/lib/postgresql/pgrx
publish_service:
needs: [ test_core, test_service, test_connector ]
needs: [ test_core, test_service, test_psql_connector ]
if: success()
runs-on: ubuntu-latest
defaults:
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
docker login -u vbulavintsev -p ${{ secrets.DOCKERHUB_TOKEN }}
docker image push vbulavintsev/meritrank-service:$TAG
publish_connector:
needs: [ test_core, test_service, test_connector ]
needs: [ test_core, test_service, test_psql_connector ]
if: success()
runs-on: ubuntu-latest
defaults:
Expand Down
1 change: 1 addition & 0 deletions psql-connector/20_pgmer2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export PGUSER="$POSTGRES_USER"
echo "Loading pgmer2 extension into $POSTGRES_DB"
"${psql[@]}" --dbname="$POSTGRES_DB" <<-'EOSQL'
CREATE EXTENSION IF NOT EXISTS pgmer2;
CREATE EXTENSION IF NOT EXISTS pgsodium;
EOSQL
2 changes: 1 addition & 1 deletion psql-connector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmer2"
version = "0.3.15"
version = "0.3.16"
edition = "2021"

[lib]
Expand Down
18 changes: 16 additions & 2 deletions psql-connector/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
FROM rust:1.75.0-alpine as compile

RUN apk add jq cmake make gcc llvm15 clang15 musl-dev postgresql16 postgresql16-dev openssl-dev curl git
WORKDIR /usr/project
COPY . .

#
# Build libsodium and pgsodium
#
RUN curl -s -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz | tar zxvf - && cd libsodium-1.0.18 && ./configure && make check && make -j 4 install
RUN git clone --depth 1 --branch v3.1.9 https://github.com/michelp/pgsodium.git && cd pgsodium && make -j 4

#
# Build meritrank psql connector
#
WORKDIR /usr/project/psql-connector
RUN apk add jq cmake make gcc clang15 musl-dev postgresql16 postgresql16-dev openssl-dev
ENV RUSTFLAGS="-Ctarget-feature=-crt-static"
RUN cargo install --locked --version 0.11.4 cargo-pgrx
RUN cargo pgrx init --pg16 pg_config
RUN cargo pgrx package
RUN sh generate_scripts.sh target/release/pgmer2-pg16/usr/share/postgresql16/extension
RUN ls -la extension

FROM postgres:16-alpine

ENV MERITRANK_SERVICE_URL=tcp://127.0.0.1:10234
ENV MERITRANK_RECV_TIMEOUT_MSEC=10000

COPY --from=compile /usr/local/lib/libsodium.so.23.3.0 /usr/local/lib/libsodium.so.23.3.0
RUN cd /usr/local/lib && ln -s -f libsodium.so.23.3.0 libsodium.so.23
COPY --from=compile /usr/project/pgsodium/pgsodium.so /usr/local/lib/postgresql/pgsodium.so
COPY --from=compile /usr/project/pgsodium/pgsodium.control /usr/local/share/postgresql/extension/pgsodium.control
COPY --from=compile /usr/project/pgsodium/sql /usr/local/share/postgresql/extension
COPY --from=compile /usr/project/psql-connector/target/release/pgmer2-pg16/usr/lib/postgresql16/pgmer2.so /usr/local/lib/postgresql/pgmer2.so
COPY --from=compile /usr/project/psql-connector/extension /usr/local/share/postgresql/extension
COPY psql-connector/20_pgmer2.sh /docker-entrypoint-initdb.d/20_pgmer2.sh
8 changes: 4 additions & 4 deletions psql-connector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ If you prefer not to read through all the steps and copy-paste commands, here’
sudo apt install docker git && \
git clone https://github.com/Intersubjective/meritrank-service-rust.git && \
cd meritrank-service-rust && \
docker build -t mr-service . && \
docker build -t mr-service -f ./Dockerfile .. && \
cd .. && \
git clone https://github.com/Intersubjective/meritrank-psql-connector.git && \
cd meritrank-psql-connector && \
docker build -t mr-psql-connector . && \
docker build -t mr-psql-connector -f ./Dockerfile .. && \
docker network create my-network && \
docker run --network my-network -p 10234:10234 -e MERITRANK_SERVICE_URL=tcp://0.0.0.0:10234 --detach --name container1 mr-service && \
docker run --network my-network -e POSTGRES_PASSWORD=postgres -e MERITRANK_SERVICE_URL=tcp://container1:10234 --detach --name container2 -p 5432:5432 mr-psql-connector:latest
Expand All @@ -52,7 +52,7 @@ Before executing any commands, ensure that you have `git` and `docker` installed
```bash
git clone https://github.com/Intersubjective/meritrank-service-rust.git
cd meritrank-service-rust/
docker build -t mr-service .
docker build -t mr-service -f ./Dockerfile ..
```

### Clone `meritrank-psql-connector` and Build It
Expand All @@ -61,7 +61,7 @@ docker build -t mr-service .
cd ..
git clone https://github.com/Intersubjective/meritrank-psql-connector.git
cd meritrank-psql-connector/
docker build -t mr-psql-connector .
docker build -t mr-psql-connector -f ./Dockerfile ..
```

## Creating a Network
Expand Down