From cc7a24af02aa4673a382ebc28a2e9a828c67d2b6 Mon Sep 17 00:00:00 2001 From: Florents Tselai Date: Fri, 15 Nov 2024 09:57:41 +0200 Subject: [PATCH] Add docker support (#15) --- .dockerignore | 7 +++++++ Dockerfile | 19 +++++++++++++++++++ Makefile | 23 +++++++++++++++++++++-- README.md | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..63ae811 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +/.git/ +/dist/ +/results/ +/tmp_check/ +regression.* +*.o +*.so \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75f159b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +ARG PG_MAJOR=17 +FROM postgres:$PG_MAJOR +ARG PG_MAJOR + +COPY . /tmp/pgpdf + +RUN apt-get update && \ + apt-mark hold locales && \ + apt-get install -y --no-install-recommends libpoppler-glib-dev pkg-config wget build-essential postgresql-server-dev-$PG_MAJOR && \ + cd /tmp/pgpdf && \ + make clean && \ + make install && \ + mkdir /usr/share/doc/pgpdf && \ + cp LICENSE README.md /usr/share/doc/pgpdf && \ + rm -r /tmp/pgpdf && \ + apt-get remove -y pkg-config wget build-essential postgresql-server-dev-$PG_MAJOR && \ + apt-get autoremove -y && \ + apt-mark unhold locales && \ + rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/Makefile b/Makefile index cc3062b..dbe4b6a 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PG_CONFIG = pg_config PKG_CONFIG = pkg-config EXTENSION = pgpdf - +EXTVERSION = 0.1.0 MODULE_big = $(EXTENSION) OBJS = pgpdf.o @@ -32,4 +32,23 @@ EXTRA_CLEAN = $(TEST_FILES) PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) -dev: clean all install installcheck \ No newline at end of file +dev: clean all install installcheck + +.PHONY: dist + +dist: + mkdir -p dist + git archive --format zip --prefix=$(EXTENSION)-$(EXTVERSION)/ --output dist/$(EXTENSION)-$(EXTVERSION).zip main + +# for Docker +PG_MAJOR ?= 17 + +.PHONY: docker-build + +docker-build: + docker build --pull --no-cache --build-arg PG_MAJOR=$(PG_MAJOR) -t florents/pgpdf:pg$(PG_MAJOR) -t florents/pgpdf:$(EXTVERSION)-pg$(PG_MAJOR) . + +.PHONY: docker-release + +docker-release: + docker buildx build --push --pull --no-cache --platform linux/amd64,linux/arm64 --build-arg PG_MAJOR=$(PG_MAJOR) -t florents/pgpdf:pg$(PG_MAJOR) -t florents/pgpdf:$(EXTVERSION)-pg$(PG_MAJOR) . \ No newline at end of file diff --git a/README.md b/README.md index f6d84a9..06296e3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![build](https://github.com/Florents-Tselai/pgpdf/actions/workflows/build.yml/badge.svg)](https://github.com/Florents-Tselai/pgpdf/actions/workflows/build.yml) ![GitHub Repo stars](https://img.shields.io/github/stars/Florents-Tselai/pgpdf) +![Docker Pulls](https://img.shields.io/docker/pulls/florents/pgpdf) This extension for PostgreSQL provides a `pdf` data type and assorted functions. @@ -260,21 +261,55 @@ SELECT pdf_version('/tmp/pgintro.pdf'); ## Installation +Install [poppler](https://poppler.freedesktop.org) dependencies + +**Linux** ``` sudo apt install -y libpoppler-glib-dev pkg-config ``` + +**Homebrew/MacOS** + +``` +brew install poppler pkgconf +``` + ``` cd /tmp git clone https://github.com/Florents-Tselai/pgpdf.git cd pgpdf make -make install +make install # may need sudo ``` +After the installation, in a session: + ```tsql CREATE EXTENSION pgpdf; ``` +### Docker + +Get the [Docker image](https://hub.docker.com/r/florents/pgpdf) with: + +```sh +docker pull florents/pgpdf:pg17 +``` + +This adds pgpdf to the [Postgres image](https://hub.docker.com/_/postgres) (replace `17` with your Postgres server version, and run it the same way). + +Run the image in a container. + +```sh +docker run --name pgpdf -p 5432:5432 -e POSTGRES_PASSWORD=pass florents/pgpdf:0.1.0-pg17 +``` + +Through another terminal, connect to the running server (container). + +```sh +PGPASSWORD=pass psql -h localhost -p 5432 -U postgres +``` + > [!WARNING] > Reading arbitrary binary data (PDF) into your database can pose security risks. > Only use this for files you trust.