diff --git a/devcontainer-features/npm-playwright/README.md b/devcontainer-features/npm-playwright/README.md new file mode 100644 index 0000000..bbccaa2 --- /dev/null +++ b/devcontainer-features/npm-playwright/README.md @@ -0,0 +1,13 @@ +# npm-playwright devcontainer feature + +This feature will be install playwright via npm with os dependencies and browser binaries + +## Example Usage + +Install latest version + +```json +"features": { + "ghcr.io/ebizbase/devcontainer-features/npm-playwright:1": {} +} +``` \ No newline at end of file diff --git a/devcontainer-features/npm-playwright/project.json b/devcontainer-features/npm-playwright/project.json new file mode 100644 index 0000000..5f9eafe --- /dev/null +++ b/devcontainer-features/npm-playwright/project.json @@ -0,0 +1,15 @@ +{ + "name": "npm-playwright", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "devcontainer-features/npm-playwright/src", + "projectType": "application", + "tags": [], + "targets": { + "test": { + "executor": "@ebizbase/nx-internal:test-devcontainer-feature" + }, + "publish": { + "executor": "@ebizbase/nx-internal:publish-devcontainer-feature" + } + } +} diff --git a/devcontainer-features/npm-playwright/src/npm-playwright/devcontainer-feature.json b/devcontainer-features/npm-playwright/src/npm-playwright/devcontainer-feature.json new file mode 100644 index 0000000..11a17db --- /dev/null +++ b/devcontainer-features/npm-playwright/src/npm-playwright/devcontainer-feature.json @@ -0,0 +1,18 @@ +{ + "id": "npm-playwright", + "version": "0.0.0", + "name": "Playwright (via npm)", + "description": "Install playwright via npm with os dependencies and browser binaries", + "documentationURL": "https://github.com/ebizbase/dev-infras/tree/main/devcontainer-features/npm-playwright/README.md", + "options": { + "debug": { + "type": "boolean", + "default": false, + "description": "Enable debug mode (Internal use)" + } + }, + "dependsOn": { + "ghcr.io/devcontainers/features/common-utils": {}, + "ghcr.io/devcontainers/features/node": {} + } +} diff --git a/devcontainer-features/npm-playwright/src/npm-playwright/install.sh b/devcontainer-features/npm-playwright/src/npm-playwright/install.sh new file mode 100644 index 0000000..76f994b --- /dev/null +++ b/devcontainer-features/npm-playwright/src/npm-playwright/install.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -e + +DEBUG=${DEBUG:-false} + +debug() { + if [[ ${DEBUG} == true ]]; then + echo "$1" >> /tmp/npm-playwright.log + fi +} + +if [[ -n ${_REMOTE_USER_HOME} ]]; then + USER_HOME="${_REMOTE_USER_HOME}" +elif [[ ${_REMOTE_USER} == "root" ]]; then + USER_HOME="/root" +# Check if user already has a home directory other than /home/${USERNAME} +elif [[ "/home/${_REMOTE_USER}" != $(getent passwd "${_REMOTE_USER}" | cut -d: -f6) ]]; then + USER_HOME=$(getent passwd "${_REMOTE_USER}" | cut -d: -f6) +else + USER_HOME="/home/${_REMOTE_USER}" +fi + +debug "===============================" +debug "REMOTE_USER: ${_REMOTE_USER}" +debug "USER_GROUP: ${_REMOTE_USER}" +debug "USER_HOME: ${USER_HOME}" +debug "===============================" + +PLAYWRIGHT_BROWSERS_PATH="${USER_HOME}/.cache/ms-playwright" npx --yes playwright install --with-deps +chown -R ${_REMOTE_USER}:${_REMOTE_USER} "${USER_HOME}/.cache" diff --git a/devcontainer-features/npm-playwright/test/npm-playwright/default.sh b/devcontainer-features/npm-playwright/test/npm-playwright/default.sh new file mode 100644 index 0000000..c034847 --- /dev/null +++ b/devcontainer-features/npm-playwright/test/npm-playwright/default.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +check "LOG" cat /tmp/npm-playwright.log +check "Should have os dependencies" dpkg -l | grep xserver-common && dpkg -l | grep x11-common && dpkg -l | grep xvfb +check "Should browser binary avaiable in cache directory" ls -al /home/vscode/.cache/ms-playwright + +reportResults diff --git a/devcontainer-features/npm-playwright/test/npm-playwright/scenarios.json b/devcontainer-features/npm-playwright/test/npm-playwright/scenarios.json new file mode 100644 index 0000000..d9fa193 --- /dev/null +++ b/devcontainer-features/npm-playwright/test/npm-playwright/scenarios.json @@ -0,0 +1,11 @@ +{ + "default": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "remoteUser": "vscode", + "features": { + "npm-playwright": { + "debug": true + } + } + } +} diff --git a/release-config.json b/release-config.json index 6154b24..b153c2a 100644 --- a/release-config.json +++ b/release-config.json @@ -47,6 +47,16 @@ } ] }, + "devcontainer-features/npm-playwright": { + "package-name": "npm-playwright", + "extra-files": [ + { + "type": "json", + "path": "src/npm-playwright/devcontainer-feature.json", + "jsonpath": "$.version" + } + ] + }, "devcontainer-images/base-devcontainer": { "release-type": "node", "extra-files": [ diff --git a/release-manifest.json b/release-manifest.json index 8fde275..5f81e48 100644 --- a/release-manifest.json +++ b/release-manifest.json @@ -6,6 +6,7 @@ "devcontainer-features/powerlevel10k": "1.0.0", "devcontainer-features/omz-plugin": "1.0.0", "devcontainer-features/install-npm-package-globally": "1.0.0", + "devcontainer-features/npm-playwright": "1.0.0", "devcontainer-images/base-devcontainer": "1.0.0", "devcontainer-images/node-devcontainer": "1.0.0", "devcontainer-images/nx-devcontainer": "0.0.0",