Tirinoarim
Tirinoarim

Reputation: 664

Puppeteer unable to run Chrome on AWS CodeBuild

I'm using Karma to test an Angular4 project using ChromeHeadless and all works fine locally. I've then tried to get this running on AWS CodeBuild. The initial problem was that the CodeBuild VM does not include chrome headless and so I included the Puppeteer npm package and set the ENV Var accordingly in the Karma conf. This still works fine locally, but on AWS CodeBuild I get the error ...

puppeteer/.local-chromium/linux-526987/chrome-linux/chrome: error while loading shared libraries: libXss.so.1: cannot open shared object file: No such file or directory

The build is triggered from standard buildspec.yml executing maven mvn -B package. The angular build/test is done from maven using the eislett/frontend-maven-plugin (v1.4).

Puppeteer v1.0.0 Node v6.10.1 Karma v1.7.1 AWS CodeBuild - Ubuntu / Java / OpenJDK 8

I've seen other posts about additional installs onto the CI machines but CodeBuild spins up a clean VM on each run so thats not an option. Any suggestions!?

Upvotes: 9

Views: 6282

Answers (4)

Elad
Elad

Reputation: 1144

You can simply use aws docker image with chrome - aws/codebuild/standard:3.0. Edit it in the environment panel in your build.

Upvotes: 3

Tirinoarim
Tirinoarim

Reputation: 664

I finally (after over a year!) got this working (without puppeteer).

buildspec.yml - install chrome stable

phases:
  pre_build:
    commands:
      - curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
      - echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list
      - apt-get -y update
      - apt-get -y install google-chrome-stable

karma.conf.js - specify port, hostname, listenaddress, disable random, extend timeouts & tolerances

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false, // leave Jasmine Spec Runner output visible in browser
      jasmine: {
        random: false
      }
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    captureTimeout: 210000,
    browserDisconnectTolerance: 3,
    browserDisconnectTimeout : 210000,
    browserNoActivityTimeout : 210000,
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    listenAddress: 'localhost',
    hostname: 'localhost',
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: [
          '--headless',
          '--no-sandbox',
          '--password-store=basic',
          '--enable-logging',
          '--v=1'
        ],
      },
    },
    singleRun: true
  });
};

Upvotes: 9

araleius
araleius

Reputation: 51

I ran into the same problem using Jest & React, using the aws/codebuild/nodejs:7.0.0 CodeBuild image. Here's how I solved it:

In buildspec.yml:

# install chromium after updating apt-get (this will install dependencies)
phases:
  install:
    commands:
      - sudo apt-get update
      - sudo apt-get --assume-yes install chromium-browser
...

In test code:

// launch puppeteer with the --no-sandbox option
...
var browser = await puppeteer.launch({args: ['--no-sandbox']});
...

Upvotes: 5

Clare Liguori
Clare Liguori

Reputation: 1650

I work on the CodeBuild team. You can either install the missing package during each build as part of your buildspec:

  install:
    - apt-get install missing-package

Or build a custom environment for use with CodeBuild that contains the missing package: https://aws.amazon.com/blogs/devops/extending-aws-codebuild-with-custom-build-environments/

CodeBuild's environments are open-sourced to help you get started with custom environments: https://github.com/aws/aws-codebuild-docker-images

Upvotes: 6

Related Questions