mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-27 07:06:42 +00:00
chore(postgres): not loading the libpq library by default & better user feedback (#2028)
* removing implicit dependency with libpq if postgres is not being used. * We only run the postgres tests when explicitly willing to, i.e. make POSTGRES=1 test. The reason is that the postgres tests expect a database instance to be running locally.
This commit is contained in:
parent
563b2b20a5
commit
e8602021b6
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -117,7 +117,7 @@ jobs:
|
|||||||
sudo docker run --rm -d -e POSTGRES_PASSWORD=test123 -p 5432:5432 postgres:9.6-alpine
|
sudo docker run --rm -d -e POSTGRES_PASSWORD=test123 -p 5432:5432 postgres:9.6-alpine
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 test testwakunode2
|
make V=1 LOG_LEVEL=DEBUG QUICK_AND_DIRTY_COMPILER=1 POSTGRES=1 test testwakunode2
|
||||||
|
|
||||||
build-docker-image:
|
build-docker-image:
|
||||||
needs: changes
|
needs: changes
|
||||||
|
6
Makefile
6
Makefile
@ -106,6 +106,10 @@ ifneq ($(USE_LIBBACKTRACE), 0)
|
|||||||
deps: | libbacktrace
|
deps: | libbacktrace
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(POSTGRES), 1)
|
||||||
|
NIM_PARAMS := $(NIM_PARAMS) -d:postgres -d:nimDebugDlOpen
|
||||||
|
endif
|
||||||
|
|
||||||
clean: | clean-libbacktrace
|
clean: | clean-libbacktrace
|
||||||
|
|
||||||
|
|
||||||
@ -218,7 +222,7 @@ docs: | build deps
|
|||||||
#####################
|
#####################
|
||||||
# -d:insecure - Necessary to enable Prometheus HTTP endpoint for metrics
|
# -d:insecure - Necessary to enable Prometheus HTTP endpoint for metrics
|
||||||
# -d:chronicles_colors:none - Necessary to disable colors in logs for Docker
|
# -d:chronicles_colors:none - Necessary to disable colors in logs for Docker
|
||||||
DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure
|
DOCKER_IMAGE_NIMFLAGS ?= -d:chronicles_colors:none -d:insecure -d:postgres
|
||||||
DOCKER_IMAGE_NIMFLAGS := $(DOCKER_IMAGE_NIMFLAGS) $(HEAPTRACK_PARAMS)
|
DOCKER_IMAGE_NIMFLAGS := $(DOCKER_IMAGE_NIMFLAGS) $(HEAPTRACK_PARAMS)
|
||||||
|
|
||||||
# build a docker image for the fleet
|
# build a docker image for the fleet
|
||||||
|
@ -21,9 +21,10 @@ import
|
|||||||
./waku_archive/test_waku_archive
|
./waku_archive/test_waku_archive
|
||||||
|
|
||||||
const os* {.strdefine.} = ""
|
const os* {.strdefine.} = ""
|
||||||
when os == "Linux":
|
when os == "Linux" and
|
||||||
# GitHub only supports container actions on Linux
|
# GitHub only supports container actions on Linux
|
||||||
# and we need to start a postgress database in a docker container
|
# and we need to start a postgress database in a docker container
|
||||||
|
defined(postgres):
|
||||||
import
|
import
|
||||||
./waku_archive/test_driver_postgres_query,
|
./waku_archive/test_driver_postgres_query,
|
||||||
./waku_archive/test_driver_postgres
|
./waku_archive/test_driver_postgres
|
||||||
|
@ -14,10 +14,6 @@ import
|
|||||||
../common/databases/dburl,
|
../common/databases/dburl,
|
||||||
../common/databases/db_sqlite,
|
../common/databases/db_sqlite,
|
||||||
./driver,
|
./driver,
|
||||||
./driver/queue_driver,
|
|
||||||
./driver/sqlite_driver,
|
|
||||||
./driver/sqlite_driver/migrations as archive_driver_sqlite_migrations,
|
|
||||||
./driver/postgres_driver/postgres_driver,
|
|
||||||
./retention_policy,
|
./retention_policy,
|
||||||
./retention_policy/retention_policy_capacity,
|
./retention_policy/retention_policy_capacity,
|
||||||
./retention_policy/retention_policy_time,
|
./retention_policy/retention_policy_time,
|
||||||
|
@ -14,13 +14,15 @@ import
|
|||||||
../../common/databases/db_sqlite,
|
../../common/databases/db_sqlite,
|
||||||
./sqlite_driver,
|
./sqlite_driver,
|
||||||
./sqlite_driver/migrations as archive_driver_sqlite_migrations,
|
./sqlite_driver/migrations as archive_driver_sqlite_migrations,
|
||||||
./queue_driver,
|
./queue_driver
|
||||||
./postgres_driver
|
|
||||||
|
|
||||||
export
|
export
|
||||||
sqlite_driver,
|
sqlite_driver,
|
||||||
queue_driver,
|
queue_driver
|
||||||
postgres_driver
|
|
||||||
|
when defined(postgres):
|
||||||
|
import ./postgres_driver ## This import adds dependency with an external libpq library
|
||||||
|
export postgres_driver
|
||||||
|
|
||||||
proc new*(T: type ArchiveDriver,
|
proc new*(T: type ArchiveDriver,
|
||||||
url: string,
|
url: string,
|
||||||
@ -78,22 +80,26 @@ proc new*(T: type ArchiveDriver,
|
|||||||
return ok(res.get())
|
return ok(res.get())
|
||||||
|
|
||||||
of "postgres":
|
of "postgres":
|
||||||
const MaxNumConns = 5 #TODO: we may need to set that from app args (maybe?)
|
when defined(postgres):
|
||||||
let res = PostgresDriver.new(url, MaxNumConns, onErrAction)
|
const MaxNumConns = 5 #TODO: we may need to set that from app args (maybe?)
|
||||||
if res.isErr():
|
let res = PostgresDriver.new(url, MaxNumConns, onErrAction)
|
||||||
return err("failed to init postgres archive driver: " & res.error)
|
if res.isErr():
|
||||||
|
return err("failed to init postgres archive driver: " & res.error)
|
||||||
|
|
||||||
let driver = res.get()
|
let driver = res.get()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# The table should exist beforehand.
|
# The table should exist beforehand.
|
||||||
let newTableRes = waitFor driver.createMessageTable()
|
let newTableRes = waitFor driver.createMessageTable()
|
||||||
if newTableRes.isErr():
|
if newTableRes.isErr():
|
||||||
return err("error creating table: " & newTableRes.error)
|
return err("error creating table: " & newTableRes.error)
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
return err("exception creating table: " & getCurrentExceptionMsg())
|
return err("exception creating table: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
return ok(driver)
|
return ok(driver)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return err("Postgres has been configured but not been compiled. Check compiler definitions.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
debug "setting up in-memory waku archive driver"
|
debug "setting up in-memory waku archive driver"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user