Merge pull request #1 from archtika/devel

Improve reliability of playwright GitHub action
This commit is contained in:
Thilo Hohlt
2024-09-06 19:20:33 +02:00
committed by GitHub
3 changed files with 38 additions and 8 deletions

View File

@@ -18,13 +18,37 @@ jobs:
- name: Run playwright tests - name: Run playwright tests
run: | 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 mkdir -p /var/www/archtika-websites
sudo chown $USER:$(id -gn) /var/www/archtika-websites sudo chown $USER:$(id -gn) /var/www/archtika-websites
nix run .#dev-vm & 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 run .#api &
nix shell nixpkgs#netcat -c bash -c 'until nc -z localhost 3000; do sleep 1; done' wait_for_postgrest
cd web-app cd web-app
nix develop .#web --command bash -c 'npm install && npm run test' 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"

View File

@@ -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 ${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"; ''}/bin/api-setup";
}; };
} }

View File

@@ -39,12 +39,18 @@ in
description = "JWT secret for archtika. Can be a string or a path to a file containing the secret"; 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; type = types.port;
default = 5000; default = 5000;
description = "Port on which the API runs."; 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 { webAppPort = mkOption {
type = types.port; type = types.port;
default = 10000; 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 ${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"; tryFiles = "$uri $uri/ $uri/index.html =404";
}; };
"/api/" = { "/api/" = {
proxyPass = "http://localhost:${toString cfg.port}/"; proxyPass = "http://localhost:${toString cfg.apiPort}/";
extraConfig = '' extraConfig = ''
default_type application/json; default_type application/json;
proxy_hide_header Content-Location; proxy_hide_header Content-Location;