在docker中运行playwright。错误:BrowserType.launch:/.cache/ms-playwright/chromium-1134/chrome-linux/chrome 处不存在可执行文件

问题描述 投票:0回答:1

我使用此内容创建了一个 Dockerfile

FROM python:3.11-slim

# Install requirements
RUN apt-get update && apt-get install -y wget tar openjdk-17-jre
RUN apt-get update && apt-get install gcc libsnmp-dev iputils-ping -y  \
    && pip install --upgrade pip \
    && apt-get -y install curl \
    && apt-get clean


# Install allure
RUN wget --no-check-certificate https://github.com/allure-framework/allure2/releases/download/2.30.0/allure-2.30.0.tgz && \
    tar -zxvf allure-2.30.0.tgz -C /opt/ && \
    ln -s /opt/allure-2.30.0/bin/allure /usr/bin/allure && \
    rm allure-2.30.0.tgz

# Create workdir
WORKDIR /usr/workspace

# Copy the dependencies file to the working directory
COPY ./requirements.txt /usr/workspace

# Install Python dependencies
RUN pip3 install -r requirements.txt

# Install playwright
RUN playwright install --with-deps chromium

我使用 docker-compose 来运行它。

version: "3.7"

services:
  tests:
    image: tests:v1
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./:/usr/workspace
    command: /bin/sh -c 'python3 -m pytest -v -m $MARKS --alluredir=./allure-results --node_id="$NODE_ID"'
    working_dir: /usr/workspace
    user: "997:997"

一切都在本地运行没有问题,但是当它在gitlab-runner上的CI中运行时,出现错误

playwright._impl._errors.Error: BrowserType.launch: Executable doesn't exist at /.cache/ms-playwright/chromium-1134/chrome-linux/chrome

chromium 安装在安装日志中

Chromium 129.0.6668.29 (playwright build v1134) downloaded to /root/.cache/ms-playwright/chromium-1134

我尝试用不同的方式安装chromium,结果都是一样的,本地一切正常,但是在gitlab-runner中,总是报错。 Gitlab-runner 本身只是一个 shell

RUN playwright install chromium
RUN playwright install --with-deps chromium
RUN playwright install-deps chromium
python docker-compose dockerfile playwright
1个回答
0
投票

查看这个medium帖子。可能会有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.