Puppeteer unable to run Chrome on AWS CodeBuild
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
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
});
};
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']});
...