From e16f3c46b461b94722d5e8afdde80f4f5c1bbc02 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 16 Mar 2022 14:51:39 -0600 Subject: [PATCH] docs: always keep docker references up-to-date in documentation (#12795) References #12796 --- docs/src/ci.md | 10 +++++----- docs/src/docker.md | 24 ++++++++++++------------ docs/src/test-snapshots-js.md | 2 +- utils/doclint/cli.js | 33 ++++++++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/docs/src/ci.md b/docs/src/ci.md index b925f11b98..fd88d778a1 100644 --- a/docs/src/ci.md +++ b/docs/src/ci.md @@ -176,7 +176,7 @@ For Linux agents, you can use [our Docker container](./docker.md) with Azure Pip pool: vmImage: 'ubuntu-20.04' -container: mcr.microsoft.com/playwright:focal +container: mcr.microsoft.com/playwright:v1.21.0-focal steps: ... @@ -244,7 +244,7 @@ Running Playwright on CircleCI requires the following steps: ```yml docker: - - image: mcr.microsoft.com/playwright:focal + - image: mcr.microsoft.com/playwright:v1.21.0-focal environment: NODE_ENV: development # Needed if playwright is in `devDependencies` ``` @@ -266,7 +266,7 @@ to run tests on Jenkins. ```groovy pipeline { - agent { docker { image 'mcr.microsoft.com/playwright:focal' } } + agent { docker { image 'mcr.microsoft.com/playwright:v1.21.0-focal' } } stages { stage('e2e-tests') { steps { @@ -283,7 +283,7 @@ pipeline { Bitbucket Pipelines can use public [Docker images as build environments](https://confluence.atlassian.com/bitbucket/use-docker-images-as-build-environments-792298897.html). To run Playwright tests on Bitbucket, use our public Docker image ([see Dockerfile](./docker.md)). ```yml -image: mcr.microsoft.com/playwright:focal +image: mcr.microsoft.com/playwright:v1.21.0-focal ``` While the Docker image supports sandboxing for Chromium, it does not work in the Bitbucket Pipelines environment. To launch Chromium on Bitbucket Pipelines, use the `chromiumSandbox: false` launch argument. @@ -341,7 +341,7 @@ stages: tests: stage: test - image: mcr.microsoft.com/playwright:focal + image: mcr.microsoft.com/playwright:v1.21.0-focal script: ... ``` diff --git a/docs/src/docker.md b/docs/src/docker.md index e1e23df226..e3c2b264b8 100644 --- a/docs/src/docker.md +++ b/docs/src/docker.md @@ -16,19 +16,19 @@ This image is published on [Docker Hub]. Replace 1.20.0 with your Playwright version: ```bash js -docker pull mcr.microsoft.com/playwright:v1.20.0-focal +docker pull mcr.microsoft.com/playwright:v1.21.0-focal ``` ```bash python -docker pull mcr.microsoft.com/playwright/python:v1.20.0-focal +docker pull mcr.microsoft.com/playwright/python:v1.21.0-focal ``` ```bash csharp -docker pull mcr.microsoft.com/playwright:v1.20.0-focal +docker pull mcr.microsoft.com/playwright:v1.21.0-focal ``` ```bash java -docker pull mcr.microsoft.com/playwright/java:v1.20.0-focal +docker pull mcr.microsoft.com/playwright/java:v1.21.0-focal ``` ### Run the image @@ -40,19 +40,19 @@ By default, the Docker image will use the `root` user to run the browsers. This On trusted websites, you can avoid creating a separate user and use root for it since you trust the code which will run on the browsers. ```bash js -docker run -it --rm --ipc=host mcr.microsoft.com/playwright:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright:v1.21.0-focal /bin/bash ``` ```bash python -docker run -it --rm --ipc=host mcr.microsoft.com/playwright/python:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright/python:v1.21.0-focal /bin/bash ``` ```bash csharp -docker run -it --rm --ipc=host mcr.microsoft.com/playwright/dotnet:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright/dotnet:v1.21.0-focal /bin/bash ``` ```bash java -docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.21.0-focal /bin/bash ``` #### Crawling and scraping @@ -60,19 +60,19 @@ docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.20.0-focal / On untrusted websites, it's recommended to use a separate user for launching the browsers in combination with the seccomp profile. Inside the container or if you are using the Docker image as a base image you have to use `adduser` for it. ```bash js -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:v1.21.0-focal /bin/bash ``` ```bash python -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/python:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/python:v1.21.0-focal /bin/bash ``` ```bash csharp -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/dotnet:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/dotnet:v1.21.0-focal /bin/bash ``` ```bash java -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/java:v1.20.0-focal /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/java:v1.21.0-focal /bin/bash ``` [`seccomp_profile.json`](https://github.com/microsoft/playwright/blob/main/utils/docker/seccomp_profile.json) is needed to run Chromium with sandbox. This is a [default Docker seccomp profile](https://github.com/docker/engine/blob/d0d99b04cf6e00ed3fc27e81fc3d94e7eda70af3/profiles/seccomp/default.json) with extra user namespace cloning permissions: diff --git a/docs/src/test-snapshots-js.md b/docs/src/test-snapshots-js.md index 10c45db94c..8550dec2d5 100644 --- a/docs/src/test-snapshots-js.md +++ b/docs/src/test-snapshots-js.md @@ -56,7 +56,7 @@ The snapshot name `example-test-1-chromium-darwin.png` consists of a few parts: If you are not on the same operating system as your CI system, you can use Docker to generate/update the screenshots: ```bash -docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.20.0-focal /bin/bash +docker run --rm --network host -v $(pwd):/work/ -w /work/ -it mcr.microsoft.com/playwright:v1.21.0-focal /bin/bash npm install npx playwright test --update-snapshots ``` diff --git a/utils/doclint/cli.js b/utils/doclint/cli.js index 7d20796de3..553ca37d88 100755 --- a/utils/doclint/cli.js +++ b/utils/doclint/cli.js @@ -36,6 +36,16 @@ run().catch(e => { process.exit(1); });; +function getAllMarkdownFiles(dirPath, filePaths = []) { + for (const entry of fs.readdirSync(dirPath, { withFileTypes: true })) { + if (entry.isFile() && entry.name.toLowerCase().endsWith('.md')) + filePaths.push(path.join(dirPath, entry.name)); + else if (entry.isDirectory()) + getAllMarkdownFiles(path.join(dirPath, entry.name), filePaths); + } + return filePaths; +} + async function run() { // Patch README.md const versions = await getBrowserVersions(); @@ -60,6 +70,21 @@ async function run() { writeAssumeNoop(path.join(PROJECT_DIR, 'README.md'), content, dirtyFiles); } + // Patch docker version in docs + { + let playwrightVersion = require(path.join(PROJECT_DIR, 'package.json')).version; + if (playwrightVersion.endsWith('-next')) + playwrightVersion = playwrightVersion.substring(0, playwrightVersion.indexOf('-next')); + const regex = new RegExp("(mcr.microsoft.com/playwright[^: ]*):?([^ ]*)"); + for (const filePath of getAllMarkdownFiles(path.join(PROJECT_DIR, 'docs'))) { + let content = fs.readFileSync(filePath).toString(); + content = content.replace(new RegExp('(mcr.microsoft.com/playwright[^:]*):([\\w\\d-.]+)', 'ig'), (match, imageName, imageVersion) => { + return `${imageName}:v${playwrightVersion}-focal`; + }); + writeAssumeNoop(filePath, content, dirtyFiles); + } + } + // Update device descriptors { const devicesDescriptorsSourceFile = path.join(PROJECT_DIR, 'packages', 'playwright-core', 'src', 'server', 'deviceDescriptorsSource.json') @@ -112,12 +137,10 @@ async function run() { // This validates member links. documentation.setLinkRenderer(() => undefined); - for (const file of fs.readdirSync(path.join(PROJECT_DIR, 'docs', 'src'))) { - if (!file.endsWith('.md')) + for (const filePath of getAllMarkdownFiles(path.join(PROJECT_DIR, 'docs', 'src'))) { + if (langs.some(other => other !== lang && filePath.endsWith(`-${other}.md`))) continue; - if (langs.some(other => other !== lang && file.endsWith(`-${other}.md`))) - continue; - const data = fs.readFileSync(path.join(PROJECT_DIR, 'docs', 'src', file)).toString(); + const data = fs.readFileSync(filePath, 'utf-8'); documentation.renderLinksInText(md.filterNodesForLanguage(md.parse(data), lang)); } } catch (e) {