supabase / pg_graphql

GraphQL support for PostgreSQL
https://supabase.github.io/pg_graphql
Apache License 2.0
2.88k stars 101 forks source link

Docker Build Size #549

Closed ayazemre closed 1 month ago

ayazemre commented 1 month ago

Summary

I just tried this extension and I like having graphql inside pg but when I build the image it comes out as 4gb. I think most of it is rust tools etc. I am not experienced with this pgrx but my question is after installing the extension can we move postgres to completely new image? I would like to use distroless images for my deployments.

Rationale

It would save up GBs of space for images

imor commented 1 month ago

Take a look at the release action, where only the .so, .control and .sql files are copied into the deb package after the build. You might be able to do something similar with your Dockerfile.

ayazemre commented 1 month ago

Thank you will try this.

ayazemre commented 1 month ago

@imor it is unrelated but wanted to ask here instead of opening a new issue. In supabase docs it says I need to add other schemas to search path and give permissions to the user for them to be visible. I tried that but even when I empty out search path, graphql resolve reads public schema only. I add other schemas to search path and give permissions to the role. I am assuming supabase does something more because it is edited through its ui. What should I do in postgres to make resolve function reveal other schemas?

imor commented 1 month ago

I'm assuming you're talking about this section of the docs. I'd agree that what the docs say is right. You'd need your schema on the search_path and proper permission to tables in that schema for them to be exposed by pg_graphql. More specifically, the schemas returned by the current_schemas Postgres function are the ones exposed (see this line in code). Are you self-hosting or are you facing these problems on the Supabase platform? If the latter, you can open a support ticket on supabase.help.

ayazemre commented 1 month ago

I'm assuming you're talking about this section of the docs. I'd agree that what the docs say is right. You'd need your schema on the search_path and proper permission to tables in that schema for them to be exposed by pg_graphql. More specifically, the schemas returned by the current_schemas Postgres function are the ones exposed (see this line in code). Are you self-hosting or are you facing these problems on the Supabase platform? If the latter, you can open a support ticket on supabase.help.

I am currently trying to learn internals of this. All my problems are direcly in postgres, I used pgrx to install. I am trying to do a full manual setup so I can get comfortable with plugin. I am planning to contribute if I can get there.

Current schemas are returning null so problem was that. When I set local search_path in a transaction block it works, meaning my user settings are incomplete, not picking up available schemas for the user.

Thank you for the help.

olirice commented 1 month ago

If you have a dedicated role that you're using for GraphQL access you can set the search path for that specific role like this

ALTER ROLE role_name SET search_path TO schema1, schema2, ...;

which would save you from having to set it in each transaction

ayazemre commented 1 month ago

If you have a dedicated role that you're using for GraphQL access you can set the search path for that specific role like this

ALTER ROLE role_name SET search_path TO schema1, schema2, ...;

which would save you from having to set it in each transaction

Thank you, just did that. Also, what is the best way to user the released deb packages? Cant I just use those packages for installing the extension or packages will install rust anyways?

ayazemre commented 1 month ago

I get this error when I try to install deb package:

E: read, still have 8 to read but none left E: Internal error, could not locate member control.tar{.zst,.lz4,.gz,.xz,.bz2,.lzma,} E: Could not read meta data from /graph.deb E: The package lists or status file could not be parsed or opened.

olirice commented 1 month ago

what is the best way to user the released deb packages?

if you're on a debian or ubuntu image, you can install with

sudo dpkg -i package.deb

drop the sudo if using it in a docker image

the relevant pg_config needs to be on your system path for it to be installed in the right place.

There's nothing specific to cargo/rust/pg_graphql with those .debs, any online guide will give you correct info

https://askubuntu.com/questions/40779/how-do-i-install-a-deb-file-via-the-command-line

olirice commented 1 month ago

I'm going to close this as complete but feel free to follow up

olirice commented 1 month ago

I get this error when I try to install deb package: E: read, still have 8 to read but none left E: Internal error, could not locate member control.tar{.zst,.lz4,.gz,.xz,.bz2,.lzma,} E: Could not read meta data from /graph.deb E: The package lists or status file could not be parsed or opened.

I'm not able to reproduce this error. Please provide reproduction steps and I'll take a look

ayazemre commented 1 month ago

I'm going to close this as complete but feel free to follow up

Sorry for too many questions but I feel like noob again :)

dpkg -i test.deb dpkg-deb: error: unexpected end of file in archive magic version number in test.deb dpkg: error processing archive test.deb (--install): dpkg-deb --control subprocess returned error exit status 2 Errors were encountered while processing: test.deb

this is the error I get with dpkg

Steps are:

docker run debian -i /bin/bash apt update -y apt install curl apt install postgresql curl -o test.deb "package link" dpkg -i test.deb

ayazemre commented 1 month ago

Sorry it was a simple mistake on url. End dockerfile is around 400mb which uses default postgres image.

FROM postgres:16

WORKDIR /home/pg_graphql
COPY ./pg_graphql-v1.5.7-pg16-arm64-linux-gnu.deb ./
RUN dpkg -i ./pg_graphql-v1.5.7-pg16-arm64-linux-gnu.deb
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=password
CMD [ "postgres" ]

This works and adds no overhead on size.