From 4676f507381b8c62d66dd654dffed8910936c798 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Fri, 26 Jul 2024 22:42:14 +0200 Subject: [PATCH 01/11] Add Github actions --- .github/workflows/action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/action.yml diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..47b94cd --- /dev/null +++ b/.github/workflows/action.yml @@ -0,0 +1,9 @@ +steps: + - uses: actions/checkout@v4 + - uses: shogo82148/actions-setup-perl@v1 + with: + perl-version: "5.32" + install-modules-with: cpanm + install-modules-args: --with-develop --with-configure --installdeps --skip-satisfied + + - run: prove -lv t From 690b57a39e4335683baccea97599e6b86a06c21a Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Fri, 26 Jul 2024 22:59:01 +0200 Subject: [PATCH 02/11] Github actions --- .github/workflows/action.yml | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 47b94cd..6662243 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -1,9 +1,20 @@ -steps: - - uses: actions/checkout@v4 - - uses: shogo82148/actions-setup-perl@v1 - with: - perl-version: "5.32" - install-modules-with: cpanm - install-modules-args: --with-develop --with-configure --installdeps --skip-satisfied +name: Mailnesia Perl unittests - - run: prove -lv t +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: shogo82148/actions-setup-perl@v1 + with: + perl-version: "5.32" + install-modules-with: cpanm + install-modules-args: --with-develop --with-configure --installdeps --skip-satisfied + + - run: prove -lv t From 14cf7f9eeb4d0851d7fb9cb2eee1004e49725d16 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Fri, 26 Jul 2024 23:16:37 +0200 Subject: [PATCH 03/11] Github actions 3.0 --- .github/workflows/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 6662243..daabb8d 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -17,4 +17,5 @@ jobs: install-modules-with: cpanm install-modules-args: --with-develop --with-configure --installdeps --skip-satisfied + - run: perl -v - run: prove -lv t From 5450446f52d5e75fe67fe98990f2c4a31a7fa514 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Fri, 26 Jul 2024 23:32:40 +0200 Subject: [PATCH 04/11] Github actions part 4 --- .github/workflows/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index daabb8d..7d3d118 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -15,7 +15,7 @@ jobs: with: perl-version: "5.32" install-modules-with: cpanm - install-modules-args: --with-develop --with-configure --installdeps --skip-satisfied + install-modules-args: --installdeps . --skip-satisfied - run: perl -v - run: prove -lv t From 66e2792ffd1ea735c9542904da9e88438771d765 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Fri, 26 Jul 2024 23:47:55 +0200 Subject: [PATCH 05/11] GA5 --- .github/workflows/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 7d3d118..86da4d3 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -14,8 +14,8 @@ jobs: - uses: shogo82148/actions-setup-perl@v1 with: perl-version: "5.32" - install-modules-with: cpanm - install-modules-args: --installdeps . --skip-satisfied + - run: pwd + - run: cpanm --installdeps . --skip-satisfied - run: perl -v - run: prove -lv t From e8a7fb97e142d255832190c9c96fffd12561d298 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Mon, 8 Dec 2025 00:36:02 +0100 Subject: [PATCH 06/11] add Redis&Psql services to the testing workflow --- .github/workflows/action.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 86da4d3..5d0d6ce 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -2,9 +2,9 @@ name: Mailnesia Perl unittests on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: build: @@ -19,3 +19,30 @@ jobs: - run: cpanm --installdeps . --skip-satisfied - run: perl -v - run: prove -lv t + + # Service containers to start + services: + # Label used to access the service container + redis: + # Docker Hub image + image: redis + # + ports: + # Opens tcp port 6379 on the host and service container + - 6379:6379 + + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 From feac8a407d8cc13cfd5dc7e47863fbe9c03a9bae Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Sat, 21 Feb 2026 22:22:20 +0100 Subject: [PATCH 07/11] add option to specify Redis & Postgres via env postgres_host postgres_user postgres_password redis_host --- .github/workflows/action.yml | 27 ++++++++++++++++++++------- lib/Mailnesia/Config.pm | 13 ++++++++----- lib/Mailnesia/SQL.pm | 33 ++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 5d0d6ce..7f92d75 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -10,15 +10,26 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: shogo82148/actions-setup-perl@v1 + - name: checkout code + uses: actions/checkout@v4 + - name: set up Perl + uses: shogo82148/actions-setup-perl@v1 with: perl-version: "5.32" - - run: pwd - - run: cpanm --installdeps . --skip-satisfied - - run: perl -v - - run: prove -lv t + - name: print working directory + run: pwd + - name: install dependencies + run: cpanm --installdeps . --skip-satisfied + - name: perl -v + run: perl -v + - name: execute unit/function tests + run: prove -lv t + env: + postgres_host: localhost + postgres_user: mailnesia + postgres_password: test + redis_host: localhost # Service containers to start services: @@ -26,6 +37,7 @@ jobs: redis: # Docker Hub image image: redis + # TODO: password? # ports: # Opens tcp port 6379 on the host and service container @@ -36,7 +48,8 @@ jobs: image: postgres # Provide the password for postgres env: - POSTGRES_PASSWORD: postgres + POSTGRES_USER: mailnesia + POSTGRES_PASSWORD: test # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready diff --git a/lib/Mailnesia/Config.pm b/lib/Mailnesia/Config.pm index b143ea5..2323fea 100644 --- a/lib/Mailnesia/Config.pm +++ b/lib/Mailnesia/Config.pm @@ -44,14 +44,14 @@ Parameters: - if true, indicates development (testing) version; does not load any values from the private.conf to %mailnesia_private (e.g. ad code, Google Analytics, Recaptcha etc) - - false: connect to Redis, true: don't connect =cut sub new { my $package = shift; my $devel = shift; - my $dont_connect_to_redis = shift; + + my $redis_host = $ENV{redis_host}; # loading private configuration items # ex: recaptcha private key - without the correct key every captcha solution will be invalid @@ -140,9 +140,12 @@ sub new { abuse => 'peter@localhost' }, - redis => $dont_connect_to_redis ? undef : Redis->new( - encoding => undef, - sock => '/var/run/redis/redis.sock' + redis => $redis_host ? Redis->new( + server => "$redis_host:6379", + reconnect => 1, + every => 500_000, + ) : Redis->new( + sock => '/var/run/redis/redis.sock', ), # name of used redis databases diff --git a/lib/Mailnesia/SQL.pm b/lib/Mailnesia/SQL.pm index b68ea54..dbbdd57 100644 --- a/lib/Mailnesia/SQL.pm +++ b/lib/Mailnesia/SQL.pm @@ -64,22 +64,29 @@ sub connect ($;\$$&) { { # warn "connecting to SQL, warn: $warn\n"; my $db = "Pg"; - my $db_database = "mailnesia"; + my $db_database = $ENV{postgres_database} || "mailnesia"; my $db_table = "emails"; - my $user = "mailnesia"; - my $password = ""; + my $user = $ENV{postgres_user} || "mailnesia"; + my $password = $ENV{postgres_password} || ""; + my $host = $ENV{postgres_host} || "localhost"; + my $connection_string = "dbi:$db:database=$db_database;"; # connect on socket + + if ($password) { + # connect on TCP + $connection_string += "host=$host;port=5432"; + } $dbh = DBI->connect_cached( - "dbi:$db:dbname=$db_database", - $user, - $password, - { - RaiseError => 0, - AutoCommit => 1, - PrintWarn=>1, - pg_enable_utf8 => 1 # to get the data already decoded - } - ); + $connection_string, + $user, + $password, + { + RaiseError => 0, + AutoCommit => 1, + PrintWarn=>1, + pg_enable_utf8 => 1 # to get the data already decoded + } + ); if (ref $dbh) { From 7f16ac3f80e96f0b009d97c1f8896262cb832149 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Sat, 21 Feb 2026 23:01:26 +0100 Subject: [PATCH 08/11] fix SQL connection string --- lib/Mailnesia/SQL.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Mailnesia/SQL.pm b/lib/Mailnesia/SQL.pm index dbbdd57..1677316 100644 --- a/lib/Mailnesia/SQL.pm +++ b/lib/Mailnesia/SQL.pm @@ -73,7 +73,7 @@ sub connect ($;\$$&) { if ($password) { # connect on TCP - $connection_string += "host=$host;port=5432"; + $connection_string .= "host=$host;port=5432"; } $dbh = DBI->connect_cached( From d7c23fc8c3d0825e7ac3ffa7a7581f112f27de5e Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Sun, 22 Feb 2026 00:01:28 +0100 Subject: [PATCH 09/11] add create tables step --- .github/workflows/action.yml | 8 ++++++-- tools/psql-connection-arguments.sh | 17 +++++++++++++++++ tools/psql-create-tables.sh | 2 +- tools/psql-partition-update.sh | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tools/psql-connection-arguments.sh diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 7f92d75..4872168 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -21,8 +21,12 @@ jobs: run: pwd - name: install dependencies run: cpanm --installdeps . --skip-satisfied - - name: perl -v - run: perl -v + - name: create tables in postgres + run: bash ./tools/psql-create-tables.sh + env: + postgres_host: localhost + postgres_user: mailnesia + postgres_password: test - name: execute unit/function tests run: prove -lv t env: diff --git a/tools/psql-connection-arguments.sh b/tools/psql-connection-arguments.sh new file mode 100644 index 0000000..d7ca0d2 --- /dev/null +++ b/tools/psql-connection-arguments.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# This script can be sourced to get the connection arguments for psql in the variable `psqlArgs`. +# If a password has to be provided, it should be set in the environment variable +# `PGPASSWORD` before running this script. The same applies to the username, +# host and database name, which can be set in `postgres_user`, `postgres_host` +# and `postgres_db` respectively. If these variables are not set, the script +# will use the default values of "mailnesia" for the username and database, +# and "localhost" for the host. + +username="${postgres_user:-mailnesia}" +database="${postgres_db:-mailnesia}" +#arguments to psql +psqlArgs="--tuples-only --no-psqlrc --username=$username --quiet --dbname=$database"; +if [[ -n "$postgres_host" ]]; then + psqlArgs="$psqlArgs --host=$postgres_host --port=5432"; +fi diff --git a/tools/psql-create-tables.sh b/tools/psql-create-tables.sh index a6ab3e6..bfc7c56 100644 --- a/tools/psql-create-tables.sh +++ b/tools/psql-create-tables.sh @@ -3,7 +3,7 @@ # This script can be run initially to create all tables and necessary relations. #arguments to psql -psqlArgs="--tuples-only --no-psqlrc --username=mailnesia --quiet"; +source psql-connection-arguments.sh # Partitioning is used, the key being the id because that's the only # value that needs to be unique in the whole table across the partitions. diff --git a/tools/psql-partition-update.sh b/tools/psql-partition-update.sh index 8b8d8f9..a8aafd8 100755 --- a/tools/psql-partition-update.sh +++ b/tools/psql-partition-update.sh @@ -13,7 +13,7 @@ new_partition_rows=300000; #arguments to psql -psqlArgs="--tuples-only --no-psqlrc --username=mailnesia --quiet"; +source psql-connection-arguments.sh #number of partitions to keep partition_count=30 From 0bf1d2ee81ca107d6bec15eaa7fafdb49154f918 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Sun, 22 Feb 2026 00:23:08 +0100 Subject: [PATCH 10/11] resolve full path of the psql script --- tools/psql-create-tables.sh | 5 ++++- tools/psql-partition-update.sh | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/psql-create-tables.sh b/tools/psql-create-tables.sh index bfc7c56..bfb4c69 100644 --- a/tools/psql-create-tables.sh +++ b/tools/psql-create-tables.sh @@ -2,8 +2,11 @@ # This script can be run initially to create all tables and necessary relations. +# Resolve the full path of the script +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") + #arguments to psql -source psql-connection-arguments.sh +source $SCRIPT_DIR/psql-connection-arguments.sh # Partitioning is used, the key being the id because that's the only # value that needs to be unique in the whole table across the partitions. diff --git a/tools/psql-partition-update.sh b/tools/psql-partition-update.sh index a8aafd8..ae89929 100755 --- a/tools/psql-partition-update.sh +++ b/tools/psql-partition-update.sh @@ -12,8 +12,11 @@ #create new partition after this many rows: new_partition_rows=300000; +# Resolve the full path of the script +SCRIPT_DIR=$(dirname "$(readlink -f "$0")") + #arguments to psql -source psql-connection-arguments.sh +source $SCRIPT_DIR/psql-connection-arguments.sh #number of partitions to keep partition_count=30 From a32496d7f6ab06bf69cd7fa322321d9adac996c3 Mon Sep 17 00:00:00 2001 From: Peter Baranyi Date: Sun, 22 Feb 2026 00:40:44 +0100 Subject: [PATCH 11/11] fix PG password --- .github/workflows/action.yml | 2 +- tools/psql-create-tables.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 4872168..8c9134b 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -26,7 +26,7 @@ jobs: env: postgres_host: localhost postgres_user: mailnesia - postgres_password: test + PGPASSWORD: test - name: execute unit/function tests run: prove -lv t env: diff --git a/tools/psql-create-tables.sh b/tools/psql-create-tables.sh index bfb4c69..3a14387 100644 --- a/tools/psql-create-tables.sh +++ b/tools/psql-create-tables.sh @@ -80,7 +80,7 @@ createEmailPerDayTable() startPartitioning() { echo "running psql-partition-update.sh" - /bin/bash psql-partition-update.sh + /bin/bash $SCRIPT_DIR/psql-partition-update.sh echo "starting partitioning the emails table" echo "