diff --git a/Dockerfile b/Dockerfile index af31342..e61cb27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,64 +1,139 @@ -FROM python:3.10 as base +FROM ubuntu:20.04 +#FROM python:3.10 MAINTAINER Zdenek Lapes ENV DEBIAN_FRONTEND noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN true -ENV PYTHONDONTWRITEBYTECODE=1 -ENV PYTHONUNBUFFERED=1 # Update the repositories -RUN apt-get -yqq update && apt-get -yqq upgrade - -# install all packages for chromedriver: https://gist.github.com/varyonic/dea40abcf3dd891d204ef235c6e8dd79 -RUN set -ex && \ - apt-get install -y \ - xvfb \ - gnupg \ - wget \ - curl \ - unzip \ - cron \ - vim \ +RUN apt-get -yqq update + +# Upgrade packages +RUN apt-get -yqq upgrade + +# Set locale and reconfigure +ENV LANGUAGE en_US.UTF-8 +ENV LANG en_US.UTF-8 +RUN apt-get install -y locales language-pack-en tzdata +#RUN apt-get install -y locales tzdata +RUN locale-gen en_US.UTF-8 +RUN dpkg-reconfigure --frontend noninteractive locales +RUN apt-get -yqq install language-pack-en + +# Set timezone +ENV TZ "US/Eastern" +#RUN echo "US/Eastern" | sudo tee /etc/timezone +RUN echo "US/Eastern" | tee /etc/timezone +RUN dpkg-reconfigure --frontend noninteractive tzdata + +# Install utilities +RUN apt-get -yqq install ca-certificates curl dnsutils man openssl unzip wget + +# Install xvfb and fonts +RUN apt-get -yqq install xvfb fonts-ipafont-gothic xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic + +# Install Fluxbox (window manager) +RUN apt-get -yqq install fluxbox + +# Install VNC +RUN apt-get -yqq install x11vnc +RUN mkdir -p ~/.vnc + +# Install Supervisor +RUN apt-get -yqq install supervisor +RUN mkdir -p /var/log/supervisor + +# Install Java +RUN apt-get -yqq install openjdk-11-jre-headless + +# Install Selenium +RUN mkdir -p /opt/selenium +RUN wget --no-verbose -O /opt/selenium/selenium-server-standalone-2.43.1.jar http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar +RUN ln -fs /opt/selenium/selenium-server-standalone-2.43.1.jar /opt/selenium/selenium-server-standalone.jar + +# Install Chrome WebDriver +RUN wget --no-verbose -O /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip +RUN mkdir -p /opt/chromedriver-2.10 +RUN unzip /tmp/chromedriver_linux64.zip -d /opt/chromedriver-2.10 +RUN chmod +x /opt/chromedriver-2.10/chromedriver +RUN rm /tmp/chromedriver_linux64.zip +RUN ln -fs /opt/chromedriver-2.10/chromedriver /usr/local/bin/chromedriver + +# Install Google Chrome +RUN apt-get -yqq install gnupg2 +RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - +RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list +RUN apt-get -yqq update + +RUN apt-get -yqq install google-chrome-stable +#ARG CHROME_VERSION="116.0.5845.187-1" +#RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \ +# && apt install -y /tmp/chrome.deb \ +# && rm /tmp/chrome.deb + +# Install Firefox +RUN apt-get -yqq install firefox + +# Configure Supervisor +ADD ./etc/supervisor/conf.d /etc/supervisor/conf.d +#ADD ./etc/supervisord.conf /etc/supervisor/conf.d + +# Configure VNC Password +RUN x11vnc -storepasswd selenium ~/.vnc/passwd + +# Create a default user with sudo access +RUN useradd selenium --shell /bin/bash --create-home +RUN usermod -a -G sudo selenium +RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers + +# Default configuration +ENV SCREEN_GEOMETRY "1440x900x24" +ENV SELENIUM_PORT 4444 +ENV DISPLAY :20.0 + +# Disable the SUID sandbox so that Chrome can launch without being in a privileged container. +# One unfortunate side effect is that `google-chrome --help` will no longer work. +RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome +RUN echo "#!/bin/bash\nexec /opt/google/chrome/google-chrome.real --disable-setuid-sandbox \"\$@\"" > /opt/google/chrome/google-chrome +RUN chmod 755 /opt/google/chrome/google-chrome + +RUN apt-get install -y \ fish \ - python3-dev \ bat \ - --no-install-recommends && \ - 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 && \ - apt-get update -y - -# ca-certificates \ -# dnsutils \ -# man \ -# openssl \ -# xvfb \ -# fonts-ipafont-gothic \ -# xfonts-100dpi \ -# xfonts-75dpi \ -# xfonts-scalable \ -# xfonts-cyrillic \ -# fluxbox \ - -ARG CHROME_VERSION="116.0.5845.187-1" -RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \ - && apt install -y /tmp/chrome.deb \ - && rm /tmp/chrome.deb - -#ENV DISPLAY=:99 - -COPY requirements.txt setup.py README.md /app/ + vim + +# Install python3.10 +RUN apt install software-properties-common -y && \ + add-apt-repository ppa:deadsnakes/ppa -y && \ + apt install -y \ + python3-pip \ + python3-dev \ + python3.10 \ + python3.10-distutils \ + python3.10-venv \ + python3.10-dev + +# PyCairo +RUN apt-get install -y \ + pkg-config \ + libcairo2-dev \ + libffi-dev + +RUN ln -s /usr/bin/python3.10 /usr/local/bin/python3 + +# Install pip for python3.10 +RUN curl https://bootstrap.pypa.io/get-pip.py | python3 + +COPY requirements.txt setup.py README.md make.sh /app/ COPY bazos /app/bazos -WORKDIR /app -RUN set -ex && \ - pip install --upgrade pip && \ - pip install -r /app/requirements.txt +RUN pip install -r /app/requirements.txt +#RUN pip install -e /app -RUN set -ex && \ - pip install -e /app +# Ports +EXPOSE 4444 5900 -# Add user -# RUN useradd -ms /bin/bash user1 && echo 'user1:user1' | chpasswd -# USER user1 +ENV DISPLAY=:99 -CMD ["fish"] +WORKDIR /app +CMD ["/app/make.sh", "entrypoint"] diff --git a/Dockerfile_selenium b/Dockerfile_selenium deleted file mode 100644 index 532e9d1..0000000 --- a/Dockerfile_selenium +++ /dev/null @@ -1,43 +0,0 @@ -# Use the official Selenium Grid Base image as the base image -FROM selenium/standalone-chrome:latest - -# install google chrome -RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - -RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' -RUN apt-get -y update -RUN apt-get install -y google-chrome-stable - -# install chromedriver -RUN apt-get install -yqq unzip -RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip -RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ - -# set display port to avoid crash -ENV DISPLAY=:99 - -# install selenium -RUN pip install selenium==3.8.0 - - -RUN set -ex && \ - apt-get update && \ - apt-get install -y \ - python3-dev \ - --no-install-recommends - -# wget \ -# curl \ -# unzip \ -# cron \ -# vim \ -# fish \ -# bat \ -# xvfb \ -# gnupg \ -# rm -rf /var/lib/apt/lists/* - -RUN set -ex && \ - pip install --upgrade pip && \ - pip install --no-cache-dir -r /app/requirements.txt - -RUN pip install -e . diff --git a/Dockerfile_selenium2 b/Dockerfile_selenium2 deleted file mode 100644 index e61cb27..0000000 --- a/Dockerfile_selenium2 +++ /dev/null @@ -1,139 +0,0 @@ -FROM ubuntu:20.04 -#FROM python:3.10 -MAINTAINER Zdenek Lapes - -ENV DEBIAN_FRONTEND noninteractive -ENV DEBCONF_NONINTERACTIVE_SEEN true - -# Update the repositories -RUN apt-get -yqq update - -# Upgrade packages -RUN apt-get -yqq upgrade - -# Set locale and reconfigure -ENV LANGUAGE en_US.UTF-8 -ENV LANG en_US.UTF-8 -RUN apt-get install -y locales language-pack-en tzdata -#RUN apt-get install -y locales tzdata -RUN locale-gen en_US.UTF-8 -RUN dpkg-reconfigure --frontend noninteractive locales -RUN apt-get -yqq install language-pack-en - -# Set timezone -ENV TZ "US/Eastern" -#RUN echo "US/Eastern" | sudo tee /etc/timezone -RUN echo "US/Eastern" | tee /etc/timezone -RUN dpkg-reconfigure --frontend noninteractive tzdata - -# Install utilities -RUN apt-get -yqq install ca-certificates curl dnsutils man openssl unzip wget - -# Install xvfb and fonts -RUN apt-get -yqq install xvfb fonts-ipafont-gothic xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic - -# Install Fluxbox (window manager) -RUN apt-get -yqq install fluxbox - -# Install VNC -RUN apt-get -yqq install x11vnc -RUN mkdir -p ~/.vnc - -# Install Supervisor -RUN apt-get -yqq install supervisor -RUN mkdir -p /var/log/supervisor - -# Install Java -RUN apt-get -yqq install openjdk-11-jre-headless - -# Install Selenium -RUN mkdir -p /opt/selenium -RUN wget --no-verbose -O /opt/selenium/selenium-server-standalone-2.43.1.jar http://selenium-release.storage.googleapis.com/2.43/selenium-server-standalone-2.43.1.jar -RUN ln -fs /opt/selenium/selenium-server-standalone-2.43.1.jar /opt/selenium/selenium-server-standalone.jar - -# Install Chrome WebDriver -RUN wget --no-verbose -O /tmp/chromedriver_linux64.zip http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip -RUN mkdir -p /opt/chromedriver-2.10 -RUN unzip /tmp/chromedriver_linux64.zip -d /opt/chromedriver-2.10 -RUN chmod +x /opt/chromedriver-2.10/chromedriver -RUN rm /tmp/chromedriver_linux64.zip -RUN ln -fs /opt/chromedriver-2.10/chromedriver /usr/local/bin/chromedriver - -# Install Google Chrome -RUN apt-get -yqq install gnupg2 -RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - -RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list -RUN apt-get -yqq update - -RUN apt-get -yqq install google-chrome-stable -#ARG CHROME_VERSION="116.0.5845.187-1" -#RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \ -# && apt install -y /tmp/chrome.deb \ -# && rm /tmp/chrome.deb - -# Install Firefox -RUN apt-get -yqq install firefox - -# Configure Supervisor -ADD ./etc/supervisor/conf.d /etc/supervisor/conf.d -#ADD ./etc/supervisord.conf /etc/supervisor/conf.d - -# Configure VNC Password -RUN x11vnc -storepasswd selenium ~/.vnc/passwd - -# Create a default user with sudo access -RUN useradd selenium --shell /bin/bash --create-home -RUN usermod -a -G sudo selenium -RUN echo "ALL ALL = (ALL) NOPASSWD: ALL" >> /etc/sudoers - -# Default configuration -ENV SCREEN_GEOMETRY "1440x900x24" -ENV SELENIUM_PORT 4444 -ENV DISPLAY :20.0 - -# Disable the SUID sandbox so that Chrome can launch without being in a privileged container. -# One unfortunate side effect is that `google-chrome --help` will no longer work. -RUN dpkg-divert --add --rename --divert /opt/google/chrome/google-chrome.real /opt/google/chrome/google-chrome -RUN echo "#!/bin/bash\nexec /opt/google/chrome/google-chrome.real --disable-setuid-sandbox \"\$@\"" > /opt/google/chrome/google-chrome -RUN chmod 755 /opt/google/chrome/google-chrome - -RUN apt-get install -y \ - fish \ - bat \ - vim - -# Install python3.10 -RUN apt install software-properties-common -y && \ - add-apt-repository ppa:deadsnakes/ppa -y && \ - apt install -y \ - python3-pip \ - python3-dev \ - python3.10 \ - python3.10-distutils \ - python3.10-venv \ - python3.10-dev - -# PyCairo -RUN apt-get install -y \ - pkg-config \ - libcairo2-dev \ - libffi-dev - -RUN ln -s /usr/bin/python3.10 /usr/local/bin/python3 - -# Install pip for python3.10 -RUN curl https://bootstrap.pypa.io/get-pip.py | python3 - -COPY requirements.txt setup.py README.md make.sh /app/ -COPY bazos /app/bazos - -RUN pip install -r /app/requirements.txt -#RUN pip install -e /app - -# Ports -EXPOSE 4444 5900 - -ENV DISPLAY=:99 - -WORKDIR /app -CMD ["/app/make.sh", "entrypoint"] diff --git a/docker-compose.yml b/docker-compose.yml index 175d067..d92fd21 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: image: zdeneklapes/${COMPOSE_PROJECT_NAME}:latest build: context: . - dockerfile: Dockerfile_selenium2 + dockerfile: Dockerfile volumes: - ./:/app/ # Mount the project directory to the container - ./tmp/fish/:/root/.local/share/fish/ # Mount the fish shell history, to remain files when docker container is rebuild: This will create ./tmp/fish/ folder in the project directory if it doesn't exist already @@ -21,3 +21,13 @@ services: - 9050:9050 stdin_open: true tty: true + depends_on: + - selenium-chrome + selenium-chrome: + image: selenium/standalone-chrome:latest + ports: + - "4444:4444" + - "7900:7900" + shm_size: "2g" + container_name: selenium-chrome-container + restart: unless-stopped