diff --git a/Makefile b/Makefile index 77a79c7..bb7bd9e 100644 --- a/Makefile +++ b/Makefile @@ -7,16 +7,16 @@ R_VERSION := 4.0.4 docker-build-%: docker build -t rstudio/shinyapps-package-dependencies:$* --build-arg R_VERSION=$(R_VERSION) -f Dockerfile.$* . -test-xenial-%: +test-xenial-%: test install Dockerfile.xenial docker run --rm --name spd-xenial-$* -v $(CURDIR):/shinyapps rstudio/shinyapps-package-dependencies:xenial /shinyapps/test $* -test-all-xenial: +test-all-xenial: test install Dockerfile.xenial docker run --rm --name spd-xenial -v $(CURDIR):/shinyapps rstudio/shinyapps-package-dependencies:xenial /shinyapps/test -test-focal-%: +test-focal-%: test install Dockerfile.focal docker run --rm --name spd-focal-$* -v $(CURDIR):/shinyapps rstudio/shinyapps-package-dependencies:focal /shinyapps/test $* -test-all-focal: +test-all-focal: test install Dockerfile.focal docker run --rm --name spd-focal -v $(CURDIR):/shinyapps rstudio/shinyapps-package-dependencies:focal /shinyapps/test test-all: test-all-focal test-all-xenial diff --git a/packages/chromote/install b/packages/chromote/install new file mode 100755 index 0000000..65b2301 --- /dev/null +++ b/packages/chromote/install @@ -0,0 +1,11 @@ +#!/bin/bash + +set -x +set -e + +apt-get update -qq + +# install chrome +curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +apt-get install -y ./google-chrome-stable_current_amd64.deb +rm google-chrome-stable_current_amd64.deb diff --git a/packages/chromote/install_chromium b/packages/chromote/install_chromium new file mode 100755 index 0000000..f9c26d4 --- /dev/null +++ b/packages/chromote/install_chromium @@ -0,0 +1,60 @@ +#!/bin/bash + +set -x +set -e + +# See https://github.com/rstudio/shinyapps-package-dependencies/pull/302 as to why this file is not used. + +apt-get update -qq + +# On Ubuntu <= 18... +if [ ${OS_CODENAME} == "xenial" ]; then + apt-get install -y chromium-browser +else + ## On Ubuntu Focal... + ## When installing chromium using ... + # apt-get install -y chromium-browser + ## When `chromium` is first ran, an error will be throw, asking you to install chromium using... + # snap install chromium + ## However, installing `snapd` on docker is not trivial. :-( + + + # Following directions similar to + # * Chromium official suggestion: https://github.com/scheib/chromium-latest-linux/blob/4f4e9b85ea02a109e071452de936389cc2fd7376/update.sh + # * GHA Virtual Environments: https://github.com/actions/virtual-environments/blob/cfffe35709dcc45d09f0a08189be5984f3f13bbb/images/linux/scripts/installers/google-chrome.sh#L69-L85 + + # Install all dependencies that are not regularly installed when using `.deb` files + # https://github.com/puppeteer/puppeteer/blob/feec588f951d8833e3b9758cde9f34c325837407/.ci/node12/Dockerfile.linux#L3-L9 + # Matches libraries installed when using xenial deb file + apt-get install -y xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \ + libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \ + libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \ + libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \ + libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget + + # Set up variables + CHROMIUM_VERSION_FILE="chromiumLastChange.txt" + CHROMIUM_ZIP_FILE="chromium.zip" + CHROMIUM_ZIP_FOLDER="/tmp/chromium" + CHROMIUM_ZIP="${CHROMIUM_ZIP_FOLDER}/${CHROMIUM_ZIP_FILE}" + + mkdir -p "${CHROMIUM_ZIP_FOLDER}" + + # Download chromium latest version. Ex: 382086 + curl -L4 "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media" -o "${CHROMIUM_VERSION_FILE}" + CHROMIUM_VERSION=`cat ${CHROMIUM_VERSION_FILE}` + curl -L4 "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${CHROMIUM_VERSION}%2Fchrome-linux.zip?alt=media" -o "${CHROMIUM_ZIP}" + + + # Unzip Chromium archive + CHROMIUM_FOLDER="/usr/local/share/chromium" + CHROMIUM_BIN="$CHROMIUM_FOLDER/chrome-linux/chrome" + + mkdir "${CHROMIUM_FOLDER}" + unzip -qq ${CHROMIUM_ZIP} -d "${CHROMIUM_FOLDER}" + + # Link binaries + ln -s "${CHROMIUM_BIN}" /usr/bin/chromium + ln -s "${CHROMIUM_BIN}" /usr/bin/chromium-browser + +fi diff --git a/packages/chromote/test.R b/packages/chromote/test.R new file mode 100644 index 0000000..76e27f7 --- /dev/null +++ b/packages/chromote/test.R @@ -0,0 +1,28 @@ +options(download.file.method = "curl") + +avail_pkgs <- unname(available.packages(repos = "https://cran.rstudio.com")[, "Package"]) +if ("chromote" %in% avail_pkgs) { + install.packages("chromote", repos = "https://cran.rstudio.com", type = "source") +} else { + options(repos = c(CRAN="https://cran.rstudio.com")) + install.packages(c("curl", "remotes")) + remotes::install_github("rstudio/chromote", dependencies = TRUE) +} + + +library(chromote) + +print(default_chrome_args()) + +# Make session +b <- ChromoteSession$new() + +# Download google.com +b$Page$navigate("https://www.rstudio.com/") + +# Get the outer HTML of the document +outerHTML <- b$DOM$getOuterHTML(b$DOM$getDocument()$root$nodeId)$outerHTML +print(outerHTML) + +# Yell if it doesn't find the close `html` tag; close tag is more consistent +stopifnot(grepl("", outerHTML, fixed = TRUE))