From ca0554728f8cd89fb4989b57f5b5d06b6eba01ed Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 20 Aug 2024 14:09:44 +0200 Subject: [PATCH 1/3] Fix - run playwright install as root Run Playwright installation commands as root, install Chromium by default. Install Chromium as it's the most cross-compatible one. --- changelog.md | 4 ++++ slic.php | 2 +- src/commands/playwright.php | 48 ++++++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/changelog.md b/changelog.md index c70da38..88dab8c 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [1.7.1] - 2024-08-20 +* Fixed - Run the `playwright install` command as root +* Change - The `playwright intall` command will now install only the Chromium browser and its dependencies. + # [1.7.0] - 2024-06-06 * Fixed - Properly read changes and restart stack after using the `slic php-version set` command. * Added - PHP 8.3 docker images. diff --git a/slic.php b/slic.php index 27ed35d..69829a6 100644 --- a/slic.php +++ b/slic.php @@ -34,7 +34,7 @@ ] ); $cli_name = 'slic'; -const CLI_VERSION = '1.7.0'; +const CLI_VERSION = '1.7.1'; // If the run-time option `-q`, for "quiet", is specified, then do not print the header. if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) { diff --git a/src/commands/playwright.php b/src/commands/playwright.php index 111da13..3281a5f 100644 --- a/src/commands/playwright.php +++ b/src/commands/playwright.php @@ -44,20 +44,40 @@ setup_id(); $playwright_args = $args( '...' ); -$status = slic_realtime()( - array_merge( - [ - 'exec', - '--user', - sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ), - '--workdir', - escapeshellarg( get_project_container_path() ), - 'slic', - 'node_modules/.bin/playwright', - ], - $playwright_args - ) -); +$is_install_command = $playwright_args[0] === 'install'; + +if ( $is_install_command ) { + // Install commands will need to run as root. + $user = '--user 0:0'; +} else { + // Other commands will run as the current user. + $user = sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ); +} + +if ( $playwright_args === ['install'] ) { + // It's exactly the `playwright install` command and nothing more. + $command = [ + 'exec', + '--user', + '0:0', + '--workdir', + escapeshellarg( get_project_container_path() ), + 'slic', + 'node_modules/.bin/playwright install chromium --with-deps', + ]; +} else { + $command = array_merge( [ + 'exec', + '--user', + $user, + '--workdir', + escapeshellarg( get_project_container_path() ), + 'slic', + 'node_modules/.bin/playwright', + ], $playwright_args ); +} + +$status = slic_realtime()( $command ); // If there is a status other than 0, we have an error. Bail. if ( $status ) { From c6040829bdca1b0093b207d598ecfb980b7834bc Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 20 Aug 2024 14:17:12 +0200 Subject: [PATCH 2/3] fix(commands/playwright) use the user var --- src/commands/playwright.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/playwright.php b/src/commands/playwright.php index 3281a5f..3fc9734 100644 --- a/src/commands/playwright.php +++ b/src/commands/playwright.php @@ -48,7 +48,7 @@ if ( $is_install_command ) { // Install commands will need to run as root. - $user = '--user 0:0'; + $user = '0:0'; } else { // Other commands will run as the current user. $user = sprintf( '"%s:%s"', getenv( 'SLIC_UID' ), getenv( 'SLIC_GID' ) ); From e6f05fa1c675a0cf1f4a630095a96e6089cb8a0d Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 20 Aug 2024 14:35:02 +0200 Subject: [PATCH 3/3] doc(changelog.md) fix typo --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 88dab8c..9dca1a4 100644 --- a/changelog.md +++ b/changelog.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # [1.7.1] - 2024-08-20 * Fixed - Run the `playwright install` command as root -* Change - The `playwright intall` command will now install only the Chromium browser and its dependencies. +* Change - The `playwright install` command will now install only the Chromium browser and its dependencies. # [1.7.0] - 2024-06-06 * Fixed - Properly read changes and restart stack after using the `slic php-version set` command.