如何在 gitlab yml 中使用 k6 docker 图像 运行 curl 命令

How to run curl commands with k6 docker image in gitlab yml

我想 运行 一个 curl 请求作为我的 K6 负载测试的预请求脚本。这是我的 YML 文件:

  - loadtest-local

image:
  name: ubuntu:latest

loadtest-local:
  image:
    name: loadimpact/k6:latest
    entrypoint: ['']
  stage: loadtest-local
  before_script:
    - apk add --no-cache curl jq
  script:
    - echo "executing local k6 in k6 container..."
    - >
      curl google.com
    - k6 run ./tests/script.js

当我在管道中 运行 时,出现以下错误:

$ apk add --no-cache curl jq
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

如何在我的 YML 中添加 curl 请求作为预请求脚本?

k6 Docker 图像 运行s 作为非特权用户,这就是为什么您无法安装 curljq

我建议您使用 loadimpact/k6 作为基础构建您自己的自定义图像,或者从另一个基础构建一个图像,该图像使用 COPY --from=loadimpact/k6:latest /usr/bin/k6 /usr/bin/k6 复制 k6 二进制文件,安装任何东西您需要在其中 运行 代替 CI 中的图像。