Skip to content

Commit

Permalink
[HYD-175] Add pgsql-http extension (#5)
Browse files Browse the repository at this point in the history
* Add `pgsql-http` extension

* Enable `http` fdw by default for spilo

* Rename files/default to files/spilo

* Enable http for postgres images

* Add http ext acceptance tests

* Fix lint

* Pin pgsql_http to v1.5.0
  • Loading branch information
owenthereal authored Oct 24, 2022
1 parent 416bd10 commit dae1e07
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 5 deletions.
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

FROM postgres_base

# columnar ext
COPY --from=columnar /pg_ext /

RUN mkdir -p /docker-entrypoint-initdb.d && echo 'CREATE EXTENSION IF NOT EXISTS columnar;\nALTER EXTENSION columnar UPDATE;' > /docker-entrypoint-initdb.d/columnar.sql
# http deps
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
libcurl4-gnutls-dev \
; \
rm -rf /var/lib/apt/lists/*
# http ext
COPY --from=http /pg_ext /

COPY files/postgres/docker-entrypoint-initdb.d /docker-entrypoint-initdb.d/
5 changes: 4 additions & 1 deletion Dockerfile.spilo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ FROM spilo_base

COPY --from=columnar_13 /pg_ext /
COPY --from=columnar_14 /pg_ext /
COPY files/default/postgres-appliance/scripts /scripts/
COPY files/spilo/postgres-appliance/scripts /scripts/

COPY --from=http_13 /pg_ext /
COPY --from=http_14 /pg_ext /

ARG POSTGRES_BASE_VERSION
# Default envs
Expand Down
80 changes: 78 additions & 2 deletions acceptance/shared/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Case struct {
// images.
var AcceptanceCases = []Case{
{
Name: "columnar ext",
Name: "columnar ext available",
SQL: `
SELECT count(1) FROM pg_available_extensions WHERE name = 'columnar';
`,
Expand All @@ -31,7 +31,23 @@ SELECT count(1) FROM pg_available_extensions WHERE name = 'columnar';
}

if want, got := 1, count; want != got {
t.Errorf("columnar ext should exist")
t.Error("columnar ext should exist")
}
},
},
{
Name: "columnar ext enabled",
SQL: `
SELECT count(1) FROM pg_extension WHERE extname = 'columnar';
`,
Validate: func(t *testing.T, row pgx.Row) {
var count int
if err := row.Scan(&count); err != nil {
t.Fatal(err)
}

if want, got := 1, count; want != got {
t.Error("columnar ext should exist")
}
},
},
Expand Down Expand Up @@ -182,5 +198,65 @@ CREATE TABLE columnar_table2
}
},
},
{
Name: "http ext available",
SQL: `
SELECT count(1) FROM pg_available_extensions WHERE name = 'http';
`,
Validate: func(t *testing.T, row pgx.Row) {
var count int
if err := row.Scan(&count); err != nil {
t.Fatal(err)
}

if want, got := 1, count; want != got {
t.Errorf("columnar ext should exist")
}
},
},
{
Name: "http ext enabled",
SQL: `
SELECT count(1) FROM pg_extension WHERE extname = 'http';
`,
Validate: func(t *testing.T, row pgx.Row) {
var count int
if err := row.Scan(&count); err != nil {
t.Fatal(err)
}

if want, got := 1, count; want != got {
t.Errorf("columnar ext should exist")
}
},
},
{
Name: "http put",
SQL: `
SELECT status, content_type, content::json->>'data' AS data
FROM http_put('http://httpbin.org/put', 'some text', 'text/plain');
`,
Validate: func(t *testing.T, row pgx.Row) {
var result struct {
Status int
ContentType string
Data string
}

if err := row.Scan(&result.Status, &result.ContentType, &result.Data); err != nil {
t.Fatal(err)
}

if want, got := 200, result.Status; want != got {
t.Errorf("http put response status should match: want=%d got=%d", want, got)
}
if want, got := "application/json", result.ContentType; want != got {
t.Errorf("http put response content type should match: want=%s got=%s", want, got)
}
if want, got := "some text", result.Data; want != got {
t.Errorf("http put response data should match: want=%s got=%s", want, got)
}
},
},
}
)
35 changes: 35 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target "postgres" {
postgres_base = "docker-image://postgres:${POSTGRES_BASE_VERSION}"

columnar = "target:columnar_${POSTGRES_BASE_VERSION}"
http = "target:http_${POSTGRES_BASE_VERSION}"
}

tags = [
Expand All @@ -60,6 +61,8 @@ target "spilo" {
spilo_base = "target:spilo_base"
columnar_13 = "target:columnar_13"
columnar_14 = "target:columnar_14"
http_13 = "target:http_13"
http_14 = "target:http_14"
}

args = {
Expand Down Expand Up @@ -90,6 +93,38 @@ target "spilo_base" {
cache-from = ["type=local,src=tmp/bake_cache/spilo_base"]
}

target "http" {
inherits = ["shared"]
context = "http"
target = "output"

args = {
PGSQL_HTTP_TAG = "v1.5.0"
}
}

target "http_13" {
inherits = ["http"]

args = {
POSTGRES_BASE_VERSION = 13
}

cache-to = ["type=local,dest=tmp/bake_cache/http_13"]
cache-from = ["type=local,src=tmp/bake_cache/http_13"]
}

target "http_14" {
inherits = ["http"]

args = {
POSTGRES_BASE_VERSION = 14
}

cache-to = ["type=local,dest=tmp/bake_cache/http_14"]
cache-from = ["type=local,src=tmp/bake_cache/http_14"]
}

target "columnar" {
inherits = ["shared"]
context = "columnar"
Expand Down
2 changes: 2 additions & 0 deletions files/postgres/docker-entrypoint-initdb.d/columnar.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE EXTENSION IF NOT EXISTS columnar;
ALTER EXTENSION columnar UPDATE;
2 changes: 2 additions & 0 deletions files/postgres/docker-entrypoint-initdb.d/http.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE EXTENSION IF NOT EXISTS http;
ALTER EXTENSION http UPDATE;
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def deep_update(a, b):
{{/SSL_CRL_FILE}}
ssl_cert_file: {{SSL_CERTIFICATE_FILE}}
ssl_key_file: {{SSL_PRIVATE_KEY_FILE}}
shared_preload_libraries: 'bg_mon,pg_stat_statements,pgextwlist,pg_auth_mon,set_user,columnar,pg_cron'
shared_preload_libraries: 'bg_mon,pg_stat_statements,pgextwlist,pg_auth_mon,set_user,columnar,http,pg_cron'
bg_mon.listen_address: '{{BGMON_LISTEN_IP}}'
bg_mon.history_buckets: 120
pg_stat_statements.track_utility: 'off'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ UPDATE pg_catalog.pg_extension SET extname = 'columnar' WHERE extname = 'citus_c
UPDATE pg_catalog.pg_proc SET probin = '\$libdir/columnar' WHERE probin = '\$libdir/citus_columnar';
CREATE EXTENSION IF NOT EXISTS columnar;
ALTER EXTENSION columnar UPDATE;
CREATE EXTENSION IF NOT EXISTS http;
ALTER EXTENSION http UPDATE;
GRANT EXECUTE ON FUNCTION public.set_user(text) TO admin;
GRANT EXECUTE ON FUNCTION public.pg_stat_statements_reset($RESET_ARGS) TO admin;"
if [ "$PGVER" -lt 10 ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# (min_version, max_version, shared_preload_libraries, extwlist.extensions)
extensions = {
'columnar': (13, 14, True, True),
'http': (13, 14, True, True),
'pg_cron': (9.5, 14, True, True),
'pg_stat_kcache': (9.4, 14, True, False),
'pg_partman': (9.4, 14, False, True)
Expand Down
20 changes: 20 additions & 0 deletions http/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:22.04 as setup

ARG PGSQL_HTTP_TAG
ARG POSTGRES_BASE_VERSION=13

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install gnupg postgresql-common git -y
RUN sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get upgrade -y && apt-get install lsb-release gcc make libssl-dev autoconf pkg-config postgresql-${POSTGRES_BASE_VERSION} postgresql-server-dev-${POSTGRES_BASE_VERSION} libcurl4-gnutls-dev liblz4-dev libzstd-dev -y

FROM setup as builder

RUN git clone https://github.com/pramsey/pgsql-http && \
cd pgsql-http && \
git checkout ${PGSQL_HTTP_TAG} && \
DESTDIR=/pg_ext make && \
DESTDIR=/pg_ext make install

FROM scratch as output

COPY --from=builder /pg_ext /pg_ext

0 comments on commit dae1e07

Please sign in to comment.