diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index deb2648..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -docker/ \ No newline at end of file diff --git a/docker/citus/001-create-citus-extension.sql b/docker/citus/001-create-citus-extension.sql new file mode 100644 index 0000000..88c3d96 --- /dev/null +++ b/docker/citus/001-create-citus-extension.sql @@ -0,0 +1,7 @@ +-- wrap in transaction to ensure Docker flag always visible +BEGIN; +CREATE EXTENSION citus; + +-- add Docker flag to node metadata +UPDATE pg_dist_node_metadata SET metadata=jsonb_insert(metadata, '{docker}', 'true'); +COMMIT; diff --git a/docker/citus/Dockerfile b/docker/citus/Dockerfile index 85c0615..ca36637 100644 --- a/docker/citus/Dockerfile +++ b/docker/citus/Dockerfile @@ -27,7 +27,7 @@ RUN apt-get update \ # && apt-get purge -y --auto-remove curl \ # && rm -rf /var/lib/apt/lists/* \ -RUN curl -O https://github.com/tensorchord/pgvecto.rs/releases/download/v0.2.1/vectors-pg15_0.2.1_amd64.deb && \ +RUN curl -sfLO https://github.com/tensorchord/pgvecto.rs/releases/download/v0.2.1/vectors-pg15_0.2.1_amd64.deb && \ apt-get install ./vectors-pg15_0.2.1_amd64.deb && rm vectors-pg15_0.2.1_amd64.deb RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null \ @@ -43,10 +43,10 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | te RUN echo "shared_preload_libraries='citus,vectors.so'" >> /usr/share/postgresql/postgresql.conf.sample # add scripts to run after initdb -COPY 001-create-citus-extension.sql /docker-entrypoint-initdb.d/ +COPY docker/citus/001-create-citus-extension.sql /docker-entrypoint-initdb.d/ # add health check script -COPY pg_healthcheck wait-for-manager.sh / +COPY docker/citus/pg_healthcheck docker/citus/wait-for-manager.sh / RUN chmod +x /wait-for-manager.sh # entry point unsets PGPASSWORD, but we need it to connect to workers diff --git a/docker/citus/pg_healthcheck b/docker/citus/pg_healthcheck new file mode 100755 index 0000000..c66f4f8 --- /dev/null +++ b/docker/citus/pg_healthcheck @@ -0,0 +1,10 @@ +#!/bin/bash + +# variables adapted from https://github.com/docker-library/healthcheck +host="$(hostname -i || echo '127.0.0.1')" +user="${POSTGRES_USER:-postgres}" +db="${POSTGRES_DB:-$POSTGRES_USER}" + +pg_isready -h "${host}" -p 5432 \ + -d "${db}" -U "${user}" \ + --timeout=5 --quiet || exit 1 diff --git a/docker/citus/wait-for-manager.sh b/docker/citus/wait-for-manager.sh new file mode 100644 index 0000000..e66c975 --- /dev/null +++ b/docker/citus/wait-for-manager.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# wait-for-manager.sh + +set -e + +until test -f /healthcheck/manager-ready ; do + >&2 echo "Manager is not ready - sleeping" + sleep 1 +done + +>&2 echo "Manager is up - starting worker" + +exec gosu postgres "/usr/local/bin/docker-entrypoint.sh" "postgres" diff --git a/pkg/mongo/client_test.go b/pkg/mongo/client_test.go index bf4028e..5d85e5e 100644 --- a/pkg/mongo/client_test.go +++ b/pkg/mongo/client_test.go @@ -1,6 +1,7 @@ package mongo import ( + "bytetrade.io/web3os/tapr/pkg/apis/apr/v1alpha1" "context" "testing" ) @@ -22,7 +23,7 @@ func TestCreateUser(t *testing.T) { } defer mongo.Close(ctx) - err = mongo.CreateOrUpdateUserWithDatabase(ctx, "newUser", "pwd123", []string{"testdb1"}) + err = mongo.CreateOrUpdateUserWithDatabase(ctx, "newUser", "pwd123", []v1alpha1.MongoDatabase{{Name: "testdb1"}}) if err != nil { t.Log(err) t.Fail() @@ -49,7 +50,7 @@ func TestDropUser(t *testing.T) { } defer mongo.Close(ctx) - err = mongo.DropUserAndDatabase(ctx, "newUser", []string{"testdb1"}) + err = mongo.DropUserAndDatabase(ctx, "newUser", []v1alpha1.MongoDatabase{{Name: "testdb1"}}) if err != nil { t.Log(err) t.Fail()