Skip to content

Commit

Permalink
Make chrome docker image work (fonts!)
Browse files Browse the repository at this point in the history
  • Loading branch information
owickstrom committed Nov 7, 2022
1 parent 659e350 commit 4cf045f
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 19 deletions.
47 changes: 35 additions & 12 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{ pkgs ? (import ./nix/nixpkgs.nix), specstrom ? import ./nix/specstrom.nix
, chromedriver ? pkgs.chromedriver, includeBrowsers ? true }:
let
poetry2nix = import ./nix/poetry2nix.nix { inherit pkgs; };

quickstrom = poetry2nix.mkPoetryApplication {
quickstrom = pkgs.poetry2nix.mkPoetryApplication {
projectDir = ./.;
python = pkgs.python39;
propagatedBuildInputs = [ specstrom ];
Expand All @@ -18,13 +17,18 @@ let
client-side = import ./client-side { inherit pkgs; };
html-report = import ./html-report { inherit pkgs; };

runtimeDeps = [ specstrom chromedriver ]
++ pkgs.lib.optionals includeBrowsers [ pkgs.chromium ];
runtimeDeps = [ specstrom ] ++ pkgs.lib.optionals includeBrowsers [
chromedriver
pkgs.geckodriver
pkgs.chromium
pkgs.firefox
];

quickstrom-wrapped = { includeBrowsers }:
pkgs.stdenv.mkDerivation {
name = "quickstrom-wrapped";
src = ./.;
srcs = ./.;
unpackPhase = false;
buildInputs = [ pkgs.makeWrapper ];
installPhase = ''
mkdir -p $out/share
Expand All @@ -38,16 +42,35 @@ let
'';
};

ubuntu = pkgs.dockerTools.pullImage {
imageName = "ubuntu";
imageDigest =
"sha256:edc5125bd9443ab5d5c92096cf0e481f5e8cb12db9f5461ab1ab7a936c7f7d30";
sha256 = "sha256-TZSqaLl28S71CLmfn5HEIN+/1UCPMrLlqpr5D0VcULg=";
finalImageTag = "22.10";
finalImageName = "ubuntu";
};

docker = pkgs.dockerTools.buildImage {
fromImage = ubuntu;
name = "quickstrom/quickstrom";
tag = "latest";
extraCommands = "mkdir -m 0777 tmp";
contents = [
pkgs.coreutils
pkgs.bash
(quickstrom-wrapped { includeBrowsers = true; })
];
config = { Cmd = [ "quickstrom" ]; };
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
(quickstrom-wrapped { includeBrowsers = true; })
pkgs.bashInteractive
pkgs.dockerTools.caCertificates
];
pathsToLink = [ "/bin" "/etc" ];
};
config = {
Cmd = [ "quickstrom" ];
Env = [
# Required for Chrome/Chromium rendering. It needs fallback fonts.
"FONTCONFIG_FILE=${pkgs.fontconfig.out}/etc/fonts/fonts.conf"
];
};
};
in {
quickstrom = quickstrom-wrapped { inherit includeBrowsers; };
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nix/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import (fetchTarball
"https://github.com/NixOS/nixpkgs/archive/b3a8f7ed267e0a7ed100eb7d716c9137ff120fe3.tar.gz") {
"https://github.com/NixOS/nixpkgs/archive/1f3ebb2bd1a353a42e8f833895c26d8415c7b791.tar.gz") {
config.allowUnfree = true;
}
2 changes: 0 additions & 2 deletions nix/poetry2nix.nix

This file was deleted.

4 changes: 2 additions & 2 deletions quickstrom/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ def new_driver(self):
if self.browser == 'chrome':
options = chrome_options.Options()
options.headless = self.headless
browser_path = which("chrome") or which("chromium")
browser_path = which("google-chrome-stable") or which("google-chrome") or which("chrome") or which("chromium")
options.binary_location = browser_path # type: ignore
options.add_argument('--no-sandbox')
options.add_argument("--single-process")
options.add_argument("--disable-dev-shm-usage")
# options.add_argument("--disable-dev-shm-usage")
chromedriver_path = which('chromedriver')
if not chromedriver_path:
raise Exception("chromedriver not found in PATH")
Expand Down
6 changes: 4 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? (import ./nix/nixpkgs.nix), specstrom ? import ./nix/specstrom.nix }:
let
poetry2nix = import ./nix/poetry2nix.nix { inherit pkgs; };
appEnv = poetry2nix.mkPoetryEnv {
appEnv = pkgs.poetry2nix.mkPoetryEnv {
python = pkgs.python39;
projectDir = ./.;
editablePackageSources = { my-app = ./.; };
};
Expand All @@ -14,7 +14,9 @@ in pkgs.mkShell {
pkgs.poetry

pkgs.geckodriver
pkgs.firefox
pkgs.chromedriver
pkgs.google-chrome

specstrom
pkgs.nodePackages.pyright
Expand Down

0 comments on commit 4cf045f

Please sign in to comment.