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

[Docs] Add Docker COPY from Example #31

Open
yordis opened this issue Mar 22, 2024 · 5 comments · May be fixed by #32
Open

[Docs] Add Docker COPY from Example #31

yordis opened this issue Mar 22, 2024 · 5 comments · May be fixed by #32

Comments

@yordis
Copy link

yordis commented Mar 22, 2024

Hey there, I wonder if we could "merge" the pg_uuidv7 image into the base image.

  • Why would you do that?

I have other extension requirements aside from pg_uuidv7, and I am hoping that such a pattern becomes familiar enough so Extension Authors could provide a straightforward image to COPY from instead of relying on tools like pgxn or pgxman, or deal with "complex" (unfamiliar) installations steps and instead take advantage of Official Docker Image.

FROM postgres:latest

COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0 /[help here] /[help here]

I appreciate any help you can provide.

@yordis
Copy link
Author

yordis commented Mar 22, 2024

Ideally, create a ghcr.io/fboulnois/pg_uuidv7:1.5.0-extension image so that it is safe to copy everything from it:

FROM postgres:latest

COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0-extension /PGEXTENSION/${PG_MAJOR} /

Where that tree under /PGEXTENSION has ONLY the files required to copy into my image

@heyztb
Copy link

heyztb commented Mar 23, 2024

Edit: maybe it's not exactly what was asked for, leaving it here anyways. if you need this alongside other extensions, it might not be the most ergonomic way of doing it, but it does work.

Hey there, while I'm not the maintainer for this extension, I did see this and figured this could be done pretty easily.

Here's an example I put together

FROM postgres:alpine3.18@sha256:354a818d8a1e94707704902edb8c4e98b0eb64de3ee0354c4d94b4e2905c63ee

RUN apk update && apk add curl \
    && cd $(mktemp -d) \
    && curl -LO "https://github.com/fboulnois/pg_uuidv7/releases/download/v1.5.0/pg_uuidv7.tar.gz" \
    && curl -LO "https://github.com/fboulnois/pg_uuidv7/releases/download/v1.5.0/SHA256SUMS" \
    && tar xf pg_uuidv7.tar.gz \
    && sha256sum -c SHA256SUMS \
    && if [ $? -ne 0 ]; then echo "Checksum verification failed" && exit 1; fi \
    && cp "$PG_MAJOR/pg_uuidv7.so" "$(pg_config --pkglibdir)" \
    && cp pg_uuidv7--1.5.sql pg_uuidv7.control "$(pg_config --sharedir)/extension"

RUN echo "CREATE EXTENSION pg_uuidv7;" > /docker-entrypoint-initdb.d/create_pg_uuidv7.sql
db=# select uuid_generate_v7();
           uuid_generate_v7           
--------------------------------------
 018e68a2-cab5-79d6-8f57-f7c0e7694dc4
(1 row)

I'm using this alongside Docker Compose, so I've got the environment variables that Postgres needs during setup defined there instead of in this Dockerfile. That looks like this:

services:
  db:
    build: 
      context: .
      dockerfile: pg-Dockerfile
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: ${DATABASE_USER}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      POSTGRES_DB: ${DATABASE_NAME}

@fboulnois
Copy link
Owner

Here are two other ways to accomplish this directly using the ghcr.io image.

v1:

FROM postgres:16

COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0 /srv/* /srv/

RUN cd /srv \
    && tar xf pg_uuidv7.tar.gz \
    && sha256sum -c SHA256SUMS \
    && cp /srv/${PG_MAJOR}/pg_uuidv7.so /usr/lib/postgresql/${PG_MAJOR}/lib \
    && cp /srv/pg_uuidv7.control /usr/share/postgresql/${PG_MAJOR}/extension \
    && cp /srv/pg_uuidv7--1.5.sql /usr/share/postgresql/${PG_MAJOR}/extension

v2:

FROM postgres:16

COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0 /usr/lib/postgresql/${PG_MAJOR}/lib/pg_uuidv7.so /usr/lib/postgresql/${PG_MAJOR}/lib
COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0 /usr/share/postgresql/${PG_MAJOR}/extension/pg_uuidv7.control /usr/share/postgresql/${PG_MAJOR}/extension
COPY --from=ghcr.io/fboulnois/pg_uuidv7:1.5.0 /usr/share/postgresql/${PG_MAJOR}/extension/pg_uuidv7--1.5.sql /usr/share/postgresql/${PG_MAJOR}/extension

@yordis
Copy link
Author

yordis commented Mar 23, 2024

@fboulnois I am doing the V2, but I wish I didn't have to know all file names (for example, 1.5.sql may change in the future) and there was a "safe" way to copy everything into my existing container. Therefore, the files under a given directory must be clean and only include the extension-required code; otherwise, the container that was built may unintentionally override things.

I know I am asking for extra work on your end (I can try to contribute with your support to the feature), but honestly, the ecosystem would benefit from this. I am just learning about so many tools to manage PG Extensions that barely take advantage of Docker.

yordis added a commit to yordis/pg_uuidv7 that referenced this issue Mar 23, 2024
closes [Docs] Add Docker COPY from Example fboulnois#31

Signed-off-by: Yordis Prieto <[email protected]>
@yordis yordis linked a pull request Mar 23, 2024 that will close this issue
yordis added a commit to yordis/pg_uuidv7 that referenced this issue Mar 23, 2024
@yordis
Copy link
Author

yordis commented Mar 23, 2024

I made a PR showcasing more and less what I mean. Hopefully, I set the CI correctly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants