From d3317a16219750e1f43f3cccf7b249b218dc2ddc Mon Sep 17 00:00:00 2001 From: thiloho <123883702+thiloho@users.noreply.github.com> Date: Fri, 6 Sep 2024 19:18:36 +0200 Subject: [PATCH] Improve reliability of playwright GitHub action --- .github/workflows/playwright.yml | 32 ++++++++++++++++++++++++++++---- flake.nix | 2 +- nix/module.nix | 12 +++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 2697545..42f7764 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -18,13 +18,37 @@ jobs: - name: Run playwright tests run: | + wait_for_postgres() { + echo "Waiting for PostgreSQL to be ready..." + while ! nix shell nixpkgs#postgresql_16 -c pg_isready -h localhost -p 15432 -U postgres; do + sleep 1 + done + echo "PostgreSQL is ready." + } + + wait_for_postgrest() { + echo "Waiting for PostgREST to be live and ready..." + while ! curl -s -I "http://localhost:3001/live" | grep "OK"; do + sleep 1 + done + while ! curl -s -I "http://localhost:3001/ready" | grep "OK"; do + sleep 1 + done + echo "PostgREST is live and ready." + } + sudo mkdir -p /var/www/archtika-websites sudo chown $USER:$(id -gn) /var/www/archtika-websites + nix run .#dev-vm & - nix shell nixpkgs#netcat -c bash -c 'until nc -z localhost 15432; do sleep 1; done' + DEV_VM_PID=$! + wait_for_postgres + nix run .#api & - nix shell nixpkgs#netcat -c bash -c 'until nc -z localhost 3000; do sleep 1; done' + wait_for_postgrest + cd web-app nix develop .#web --command bash -c 'npm install && npm run test' - pkill -f "nix run .#dev-vm" || echo "No dev-vm processes found" - pkill -f "nix run .#api" || echo "No api processes found" + + pkill -e postgrest || echo "No api process found" + kill $DEV_VM_PID || echo "No dev-vm process found" diff --git a/flake.nix b/flake.nix index 7fc0357..e1dcdd7 100644 --- a/flake.nix +++ b/flake.nix @@ -64,7 +64,7 @@ ${pkgs.dbmate}/bin/dbmate --url postgres://postgres@localhost:15432/archtika?sslmode=disable --migrations-dir ${self.outPath}/rest-api/db/migrations up - PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:15432/archtika" PGRST_JWT_SECRET="a42kVyAhTImYxZeebZkApoAZLmf0VtDA" ${pkgs.postgrest}/bin/postgrest + PGRST_ADMIN_SERVER_PORT=3001 PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:15432/archtika" PGRST_JWT_SECRET="a42kVyAhTImYxZeebZkApoAZLmf0VtDA" ${pkgs.postgrest}/bin/postgrest ''}/bin/api-setup"; }; } diff --git a/nix/module.nix b/nix/module.nix index 5865077..02e07a6 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -39,12 +39,18 @@ in description = "JWT secret for archtika. Can be a string or a path to a file containing the secret"; }; - port = mkOption { + apiPort = mkOption { type = types.port; default = 5000; description = "Port on which the API runs."; }; + apiAdminPort = mkOption { + type = types.port; + default = 7500; + description = "Port on which the API admin server runs."; + }; + webAppPort = mkOption { type = types.port; default = 10000; @@ -111,7 +117,7 @@ in ${pkgs.dbmate}/bin/dbmate --url postgres://postgres@localhost:5432/archtika?sslmode=disable --migrations-dir ${cfg.package}/rest-api/db/migrations up - PGRST_SERVER_PORT=${toString cfg.port} PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:5432/${cfg.databaseName}" PGRST_JWT_SECRET="$JWT_SECRET" ${pkgs.postgrest}/bin/postgrest + PGRST_ADMIN_SERVER_PORT=${toString cfg.apiAdminPort} PGRST_SERVER_PORT=${toString cfg.apiPort} PGRST_DB_SCHEMAS="api" PGRST_DB_ANON_ROLE="anon" PGRST_OPENAPI_MODE="ignore-privileges" PGRST_DB_URI="postgres://authenticator@localhost:5432/${cfg.databaseName}" PGRST_JWT_SECRET="$JWT_SECRET" ${pkgs.postgrest}/bin/postgrest ''; }; @@ -166,7 +172,7 @@ in tryFiles = "$uri $uri/ $uri/index.html =404"; }; "/api/" = { - proxyPass = "http://localhost:${toString cfg.port}/"; + proxyPass = "http://localhost:${toString cfg.apiPort}/"; extraConfig = '' default_type application/json; proxy_hide_header Content-Location;