Skip to content

Commit

Permalink
Merge pull request #6 from beclab/fix/docker-citus
Browse files Browse the repository at this point in the history
fix: citus image build
  • Loading branch information
hysyeah authored Jun 7, 2024
2 parents efc7f03 + 63eb163 commit caa2d11
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

7 changes: 7 additions & 0 deletions docker/citus/001-create-citus-extension.sql
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions docker/citus/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions docker/citus/pg_healthcheck
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker/citus/wait-for-manager.sh
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions pkg/mongo/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mongo

import (
"bytetrade.io/web3os/tapr/pkg/apis/apr/v1alpha1"
"context"
"testing"
)
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit caa2d11

Please sign in to comment.