From ef06319e78dbcff5ded2f2302ce88d377524c629 Mon Sep 17 00:00:00 2001 From: Kasper Marstal Date: Sun, 13 Oct 2024 08:38:43 +0200 Subject: [PATCH] build: Add dockerfile (#78) --- .github/workflows/package.yml | 2 +- README.md | 23 ++++++++++++++++++++++- docker/plprql.Dockerfile | 10 ++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 docker/plprql.Dockerfile diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index c13563b..f5ccddf 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -54,7 +54,7 @@ jobs: -t "plprql-$PLPRQL_VERSION-pg-${{ matrix.pg }}-${{ matrix.os.distribution }}-${{ matrix.os.release }}" \ -f ".github/docker/Dockerfile.${{ matrix.os.distribution }}" \ . - - name: Extract .deb + - name: Copy .deb from docker image to runner run: | CONTAINER_ID=$(docker create plprql-$PLPRQL_VERSION-pg-${{ matrix.pg }}-${{ matrix.os.distribution }}-${{ matrix.os.release }}) docker cp $CONTAINER_ID:/artifacts /home/runner diff --git a/README.md b/README.md index 83ba9b8..fa2284f 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,14 @@ For more information on PRQL, visit the PRQL [website](https://prql-lang.org/), ## Getting Started -You can install the PL/PRQL extension in three ways: +You can install the PL/PRQL extension in four ways: - [Install Deb File](#install-deb-file): Download .deb file from releases page. - [Install From Source](#install-from-source): Clone the repository and build the extension on your own machine. +- [Run Dockerfile](#run-dockerfile): Build a docker image with PostgreSQL and the extension. - [Run Shell Script](#run-shell-script): Download and run a shell script builds the extension on your own machine for you. + The instruction assume you use Ubuntu or Debian. ### Install Deb File @@ -167,6 +169,25 @@ PL/PRQL is built on top of the [pgrx](https://github.com/pgcentralfoundation/pgr $$ language plprql psql> select match_stats(1); ``` + +### Run Dockerfile + +The `docker/plprql.Dockerfile` builds the `postgres:16-bookworm` docker image with the extension installed. You run this Dockerfile on your own machine with the following commands: + +```cmd +curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/kaspermarstal/plprql/main/docker/plprql.Dockerfile > plprql.Dockerfile +docker build --tag 'plprql' . -f plprql.Dockerfile +``` + +The dockerfile downloads a .deb file from the releases page and installs it into the official `postgres:16-bookworm` image. + +You can quickly test that the extension is installed and works as expected: + +```cmd +CONTAINER_ID=$(docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust plprql) +docker exec $CONTAINER_ID psql -U postgres -c "create extension plprql;" +docker exec $CONTAINER_ID psql -U postgres -c "select prql_to_sql1('from table')" +``` ### Run Shell Script Run the following command to download and execute the shell script in [scripts/install.sh](scripts/install.sh): diff --git a/docker/plprql.Dockerfile b/docker/plprql.Dockerfile new file mode 100644 index 0000000..3b4db58 --- /dev/null +++ b/docker/plprql.Dockerfile @@ -0,0 +1,10 @@ +FROM postgres:16-bookworm AS builder + +RUN apt-get update && apt-get install -y wget +RUN wget -P /tmp https://github.com/kaspermarstal/plprql/releases/download/v1.0.0/plprql-1.0.0-postgresql-16-debian-bookworm-amd64.deb + +FROM postgres:16-bookworm + +COPY --from=builder /tmp/plprql-1.0.0-postgresql-16-debian-bookworm-amd64.deb /tmp/plprql-1.0.0-postgresql-16-debian-bookworm-amd64.deb +RUN dpkg -i /tmp/plprql-1.0.0-postgresql-16-debian-bookworm-amd64.deb && \ + rm /tmp/plprql-1.0.0-postgresql-16-debian-bookworm-amd64.deb