how to download chrome with apk? - google-chrome

The following Dockerfile does not build (docker build .), and causes undefined error code 199. my-app folder was created with ng new my-app. This I believe is due to protractor chrome-driver not knowing where chromium is installed. I then tried to set ENV variable, with no change.
How do I download chrome, install and set properties correctly so to build the docker container?
FROM node:alpine
ADD my-app ./my-app
RUN apk update && \
apk upgrade && \
apk add --no-cache openjdk8 && \
apk --no-cache add curl && \
apk --no-cache add bash && \
#apk --no-cache add chromium && \
npm install -g protractor && \
webdriver-manager update
ENV CHROME_BIN=/usr/bin/chromium-browser
RUN cd ./my-app && npm run e2e

Related

Use Dependabot to check Dependencies in Bash scripts and Dockerfiles

I would like some notifications from Dependabot when new versions are available. These are my two scenarios:
#1 I'm starting a docker container in a bash script like this.
local DOCKER_IMAGE="hashcorp/terraform:1.3.6"
docker run --rm \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--user "$(id -u):$(id -g)" \
--volume /etc/timezone:/etc/timezone:ro \
--volume /etc/localtime:/etc/localtime:ro \
--volume "$(pwd):$(pwd)" \
--workdir "$(pwd)" \
--env "GITHUB_TOKEN=$TOKEN" \
--env "TF_VAR_bw_client_id=$BW_CLIENT_ID" \
--env "TF_VAR_bw_client_secret=$BW_CLIENT_SECRET" \
--env "TF_VAR_bw_password=$BW_MASTER_PASS" \
"$DOCKER_IMAGE" "$#"
For other Dependencies like Docker Images I use Dependabot to raise a PR when I should update my base image. Is there a way to have Dependabot inspect bash scripts like the above snippet as well? I'd like a notification when there is a new terraform version.
#2 I'm installing Bitwarden CLI into a custom terraform image (needed for the Bitwarden Provider. This works fine. But since I pin the Bitwarden CLI version in my Dockerfile I would like Dependabot to raise PR for the Bitwarden CLI as well.
FROM hashicorp/terraform:1.3.6
LABEL maintainer="sebastian#sommerfeld.io"
# Install basics
RUN apk update \
&& apk --no-cache add curl=7.86.0-r1 \
&& apk --no-cache add unzip=6.0-r13
# Install Bitwarden CLI + dependencies
ARG BW_VERSION="2022.11.0"
RUN apk --no-cache add libc6-compat=1.2.3-r4 \
&& apk --no-cache add gcompat=1.1.0-r0 \
&& apk --no-cache add libgcc=12.2.1_git20220924-r4 \
&& apk --no-cache add libstdc++=12.2.1_git20220924-r4 \
&& rm -rf /var/cache/apk/* \
&& curl -sL https://github.com/bitwarden/clients/releases/download/cli-v${BW_VERSION}/bw-linux-${BW_VERSION}.zip -o bw.zip \
&& unzip bw.zip \
&& chmod +rx bw \
&& rm bw.zip \
&& mv bw /usr/local/bin
Is it possible to use Dependabot for these scenarios as well?

Unable to run chromedp in docker

I had installed chromedp locally using this usual way:-
$ go get -u github.com/chromedp/chromedp. I am able to run it locally but when I deployed it to my stage environment, I got below error:-
exec: \"google-chrome\": executable file not found in $PATH
What changes do I need to make in my dockerfile?
Note: I have already tried adding below code in my Dockerfile as suggested in this answer, still doesn't work
RUN apk update && apk upgrade && apk add --no-cache bash git && apk add --no-cache chromium
# Installs latest Chromium package.
RUN echo #edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
&& echo #edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
&& apk add --no-cache \
harfbuzz#edge \
nss#edge \
freetype#edge \
ttf-freefont#edge \
&& rm -rf /var/cache/* \
&& mkdir /var/cache/apk
RUN go get github.com/mafredri/cdp
CMD chromium-browser --headless --disable-gpu --remote-debugging-port=9222 --disable-web-security --safebrowsing-disable-auto-update --disable-sync --disable-default-apps --hide-scrollbars --metrics-recording-only --mute-audio --no-first-run --no-sandbox```
It took me a while to figure out this problem originally, it's not just you.
When your installing chromedp on your local machine it's grabbing the package and building for that specific distro. When you run it inside docker you need to download a specific chromium build for the distro you are running inside docker. This is because deb is different than rpm is different than alpine and you need to have the right chromium.
Here is a copy of my docker file using a basic linux distro
RUN wget -q -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.list
RUN apt-get update && apt-get -y install google-chrome-stable
RUN chrome &
WORKDIR /app/svc/worker
RUN go build -o main .
EXPOSE 6061
CMD ["./main"]
This version for Alpine might work https://pkgs.alpinelinux.org/packages?name=chromium&branch=v3.10. However, in my experience it is best not to go with a minimal distro because chrome might depend on features not included in alpine.

Robot Framework - Docker - Chromedriver

I'm trying to setup a container to test with RobotFramework on chrome.
But when I run my container I keep getting a WebDriverException.
I've searched but couldn't find any fix that actually works for me.
This is my Dockerfile
FROM python:3
RUN apt-get update -y
# Dependencies
RUN apt-get install -y \
apt-utils \
build-essential \
fonts-liberation \
gconf-service \
libappindicator1 \
libasound2 \
libcurl3 \
libffi-dev \
libgconf-2-4 \
libindicator7 \
libnspr4 \
libnss3 \
libpango1.0-0 \
libssl-dev \
libxss1 \
python-dev \
python-pip \
python-pyasn1 \
python-pyasn1-modules \
unzip \
wget \
xdg-utils \
xvfb \
libappindicator3-1 \
libatk-bridge2.0-0 \
libgtk-3-0 \
lsb-release
# Install Chrome for Selenium
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb
# Install chromedriver for Selenium
RUN curl https://chromedriver.storage.googleapis.com/2.42/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
RUN unzip -o /usr/local/bin/chromedriver -d /usr/local/bin
RUN chmod +x /usr/local/bin/chromedriver
WORKDIR /home
COPY . .
RUN pip install -e .
CMD [ "pybot","./tests/test.robot" ]
This is the error I keep getting
WebDriverException: Message: unknown error: Chrome failed to start:
exited abnormally (unknown error: DevToolsActivePort file doesn't
exist) (The process started from chrome location
/usr/bin/google-chrome is no longer running, so ChromeDriver is
assuming that Chrome has crashed.) (Driver info:
chromedriver=2.42.591071
(0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux
4.15.0-34-generic x86_64)
My test.robot:
*** Settings ***
Library Selenium2Library
*** Variables ***
*** Test Cases ***
Connect
Open Browser https://google.es Chrome
I think I am missing something but, I just dont know what to do.
On my setup.py:
install_requires=[
'robotframework',
'robotframework-selenium2library',
'selenium'
]
I ran into this issue recently using a docker container and Amazon Linux running robot tests. I found that even though I added the required arguments within the robot framework test as in the example below chrome was crashing without even starting with the same message you received. I resolved the issue by updating the python settings in the options.py within the container.
I updated my docker container with the command below to set the options in the python selenium chrome WebDriver options.py file. In my case I'm using python version 3.7 - so you want to make sure that the path you use is correct.
RUN sed -i "s/self._arguments\ =\ \[\]/self._arguments\ =\ \['--no-sandbox',\ '--disable-dev-shm-usage'\]/" /usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/options.py
Example Robot - this is what I tried within robot framework that didn't fix the problem.
${chrome_options} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument headless
Call Method ${chrome_options} add_argument disable-gpu
Call Method ${chrome_options} add_argument no-sandbox
Call Method ${chrome_options} add_argument disable-dev-sim-usage ${options}= Call Method ${chrome_options} to_capabilities
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
open browser about:blank ${BROWSER} desired_capabilities=${options}
I'm not sure if this will address your issue. You could try updating your file manually before updating your container to see if it helps. I spent a lot of time troubleshooting this. It would be great if the error was a bit more descriptive.
Good luck.
Please change modify permission , it's will work
from
RUN chmod +x /usr/local/bin/chromedriver
to
RUN chmod 777 /usr/local/bin/chromedriver
I had the same issue and the below code fixed it
*** Settings ***
Library Selenium2Library
*** Variables ***
${URL} https://www.google.com
${CHROMEDRIVER_PATH} /usr/local/bin/chromedriver
*** Keywords ***
Open Website
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --no-sandbox
Call Method ${chrome_options} add_argument --headless
Open Browser ${URl} chrome options=${chrome_options} executable_path=${CHROMEDRIVER_PATH}
*** Settings ***
Suite Setup Open Website
This is my Dockerfile have test with gitlab CI:
FROM python:3.9.6-buster
ADD ./requirements.txt /tmp/requirements.txt
RUN pip install -r /tmp/requirements.txt
RUN apt-get update && apt-get install -y xvfb wget unzip libnss3-tools
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN apt-get update && apt-get install -y google-chrome-stable
RUN wget -q https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_linux64.zip -O /tmp/chromedriver_linux64.zip \
&& unzip -qq /tmp/chromedriver_linux64.zip -d /usr/local/bin \
&& rm /tmp/chromedriver_linux64.zip \
&& chmod +x /usr/local/bin/chromedriver
You can get more information to run Robot Framework with docker:
https://github.com/dylanops/docker-robot-framework

installing chrome in docker file

I am trying to install google chrome in docker build with following standard way:
ARG CHROME_VERSION="google-chrome-stable"
RUN wget -q -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 update -qqy \
&& apt-get -qqy install \
${CHROME_VERSION:-google-chrome-stable} \
&& rm /etc/apt/sources.list.d/google-chrome.list \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
But my proxy does not allow google.com so it fails. Is there other way to install google chrome in ubuntu? I don't want to host any file in network so if there is another source (e.g. github) where I can find debian packages for chrome then I can just get that and run that with dpkg. Or, any other idea?
Thanks a lot.
I found a mirror in my network. Replacing source with my mirror, job was done!

How to configure PHP 7 - Apache with MySQL PDO driver in Debian Docker image?

I'm using official docker images for PHP 7 (7.0.3-Apache) and MySql (5.7.10).
Using docker-compose, created containers from images and linked both.
Copied php.ini from https://github.com/php/php-src/blob/php-7.0.3/php.ini-production, replaced dll extensions with so and placed that file in /usr/local/etc/php and enabled _pdo_mysql_ extension in it.
extension=php_pdo_mysql.so
phpinfo shows php.ini loaded but not pdo_mysql extension because it's not installed.
I googled and tried different extension names with apt-get install:
php-mysql, php7-mysql, php7.0-mysql, php7.0.3-mysql.
None of them works. Error says: E: Unable to locate package.
With php5-mysql, it's get installed but after restarting apache with command: docker kill --signal="USR1" <container-name>, extension doesn't show loaded in php.ini.
(Don't think it's much related to docker but I'm new to docker and trying with that now, so mentioning it here.)
Can anyone help to configure pdo_mysql extension with php7-Apache?
You need the Dotdeb repository in /etc/apt/sources.list on your docker image:
FROM php:7-apache
# Install pdo_mysql
RUN apt-get update \
&& echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& apt-get install -y wget \
&& wget https://www.dotdeb.org/dotdeb.gpg \
&& apt-key add dotdeb.gpg \
&& apt-get update \
&& apt-get install -y php7.0-mysql \
&& docker-php-ext-install pdo_mysql