Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

ubuntu - Ho do I solve chrome error for karma tests for Angular with gitlab CI?

I try to run karma tests for Angular with gitlab CI.

The .gitlab-ci.yml:

image: node:14.0.0

cache:
  paths:
    - node_modules/

before_script:
  - npm install
  - apt-get update -qq
  - apt-get install -y -qq rsync
  - apt-get install -y -qq sshpass
  - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  - apt install ./google-chrome-stable_current_amd64.deb -y

stages:
  - testing_deploy


build_and_deploy_testing:
  stage: testing_deploy
  script:
    - echo "============== ADD DEVELOP SSH KEY =============="
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '
' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo -e "Host *
StrictHostKeyChecking no

" > ~/.ssh/config
    - echo "============== START BUILD AND DEPLOY TESTING =============="
    - ./node_modules/@angular/cli/bin/ng test --progress false --watch=false

And I get a failed job message:

12 01 2021 16:25:31.828:ERROR [launcher]: Cannot start Chrome
    [2172:2172:0112/162531.552480:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

12 01 2021 16:25:31.829:ERROR [launcher]: Chrome stdout: 
12 01 2021 16:25:31.829:ERROR [launcher]: Chrome stderr: [2172:2172:0112/162531.552480:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

12 01 2021 16:25:31.840:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
Cleaning up file based variables
ERROR: Job failed: exit code 1

How to solve ERROR:zygote_host_impl_linux.cc Running as root without --no-sandbox is not supported?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When using the Docker executor, the container runs as whatever user the image creators defined, which is almost always root; the gitlab runner doesn't set the user to root. There have been requests to make this configurable in the step configuration, but a maintainer pointed out that you can create a custom image based on the image you need.

So for example, let's say the user defined for the image mysql:8 is root, but I need to run something as the mysql user. Here's an example Dockerfile:

FROM mysql:8

USER mysql

This image is build on top of mysql:8, but we change the user it runs as. You can build the image by running docker build mysql_custom_image. If successful, at the end of the output you'll get something like Successfully built h47841j5285. Then you can give it a more friendly name: docker tag h47841j5285 my_org/mysql_custom_image.

If you're using Gitlab's built-in registry, you can then push it up there, or to hub.docker.com. If not, you can copy the Dockerfile to your runners and build it on each of them.

Your new .gitlab-ci.yml file would look something like:

image: my_org/mysql_custom_image
...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...