Skip to content

Docker overhaul and more #2693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 42 additions & 43 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# SeleniumBase Docker Image
FROM ubuntu:18.04
FROM ubuntu:22.04

#=======================================
# Install Python and Basic Python Tools
#=======================================
RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update
RUN apt-get install -y python3 python3-pip python3-setuptools python3-dev python-distribute
RUN alias python=python3
RUN echo "alias python=python3" >> ~/.bashrc
#============================
# Install Linux Dependencies
#============================
RUN apt-get update && apt-get install -y \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils \
libu2f-udev \
libvulkan1

#=================================
# Install Bash Command Line Tools
Expand All @@ -17,33 +35,24 @@ RUN apt-get -qy --no-install-recommends install \
unzip \
wget \
curl \
libxi6 \
libgconf-2-4 \
vim \
xvfb \
&& rm -rf /var/lib/apt/lists/*

#================
# Install Chrome
#================
RUN 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 -yqq update && \
apt-get -yqq install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb

#=================
# Install Firefox
#=================
RUN apt-get -qy --no-install-recommends install \
$(apt-cache depends firefox | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ') \
&& rm -rf /var/lib/apt/lists/* \
&& cd /tmp \
&& wget --no-check-certificate -O firefox-esr.tar.bz2 \
'https://download.mozilla.org/?product=firefox-esr-latest&os=linux64&lang=en-US' \
&& tar -xjf firefox-esr.tar.bz2 -C /opt/ \
&& ln -s /opt/firefox/firefox /usr/bin/firefox \
&& rm -f /tmp/firefox-esr.tar.bz2
#=======================================
# Install Python and Basic Python Tools
#=======================================
RUN apt-get -o Acquire::Check-Valid-Until=false -o Acquire::Check-Date=false update
RUN apt-get install -y python3 python3-pip python3-setuptools python3-dev python-distribute
RUN alias python=python3
RUN echo "alias python=python3" >> ~/.bashrc

#===========================
# Configure Virtual Display
Expand All @@ -58,9 +67,9 @@ RUN exec "$@"
# Update Python Version
#=======================
RUN apt-get update -y
RUN apt-get -qy --no-install-recommends install python3.8
RUN apt-get -qy --no-install-recommends install python3.10
RUN rm /usr/bin/python3
RUN ln -s python3.8 /usr/bin/python3
RUN ln -s python3.10 /usr/bin/python3

#=============================================
# Allow Special Characters in Python Programs
Expand All @@ -78,30 +87,20 @@ COPY integrations /SeleniumBase/integrations/
COPY requirements.txt /SeleniumBase/requirements.txt
COPY setup.py /SeleniumBase/setup.py
RUN find . -name '*.pyc' -delete
RUN find . -name __pycache__ -delete
RUN pip3 install --upgrade pip setuptools wheel
RUN cd /SeleniumBase && ls && pip3 install -r requirements.txt --upgrade
RUN cd /SeleniumBase && pip3 install .

#=====================
# Download WebDrivers
#=====================
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
RUN tar -xvzf geckodriver-v0.34.0-linux64.tar.gz
RUN chmod +x geckodriver
RUN mv geckodriver /usr/local/bin/
RUN wget https://chromedriver.storage.googleapis.com/72.0.3626.69/chromedriver_linux64.zip
RUN unzip chromedriver_linux64.zip
RUN chmod +x chromedriver
RUN mv chromedriver /usr/local/bin/
#=======================
# Download chromedriver
#=======================
RUN sbase get chromedriver --path

#==========================================
# Create entrypoint and grab example tests
#==========================================
COPY integrations/docker/docker-entrypoint.sh /
COPY integrations/docker/run_docker_test_in_firefox.sh /
COPY integrations/docker/run_docker_test_in_chrome.sh /
RUN chmod +x *.sh
COPY integrations/docker/docker_config.cfg /SeleniumBase/examples/
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/bash"]
16 changes: 16 additions & 0 deletions examples/raw_games.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""SB Manager using UC Mode for evading bot-detection."""
from seleniumbase import SB

with SB(uc=True, test=True, disable_csp=True) as sb:
url = "https://steamdb.info/"
sb.driver.uc_open_with_reconnect(url, 3)
sb.uc_click("a.header-login span", 4)
if not sb.is_text_visible("Sign in", "button#js-sign-in"):
sb.driver.uc_open_with_reconnect(url, 3)
sb.uc_click("a.header-login span", 4)
sb.assert_text("Sign in", "button#js-sign-in", timeout=3)
sb.driver.uc_click("button#js-sign-in", 2)
sb.highlight("div.page_content form")
sb.highlight('button:contains("Sign in")', scroll=False)
sb.set_messenger_theme(location="top_center")
sb.post_message("SeleniumBase wasn't detected", duration=4)
47 changes: 14 additions & 33 deletions integrations/docker/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,42 @@
## Docker setup instructions for SeleniumBase

#### 1. Install the Docker Toolbox:
#### 1. Install the Docker Desktop:

You can get that from here:
https://www.docker.com/products/docker-toolbox
https://www.docker.com/products/docker-desktop/

You might also want to install the Docker Engine:
https://docs.docker.com/engine/installation/
https://docs.docker.com/engine/install/

#### 2. Create your SeleniumBase Docker environment:
#### 2. Go to the SeleniumBase home directory on the command line, which is where [Dockerfile](https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile) is located. (This assumes you've already cloned the SeleniumBase repo.)

docker-machine create --driver virtualbox seleniumbase

##### (If your Docker environment ever goes down for any reason, you can bring it back up with a restart.)

docker-machine restart seleniumbase

#### 3. Configure your shell:

eval "$(docker-machine env seleniumbase)"

#### 4. Go to the SeleniumBase home directory on the command line, which is where [Dockerfile](https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile) is located. (This assumes you've already cloned the SeleniumBase repo.)

#### 5. Create your Docker image from your Dockerfile: (Get ready to wait awhile)
#### 3. Create your Docker image from your Dockerfile: (Get ready to wait awhile)

docker build -t seleniumbase .

If running on an Apple M1 Mac, use this instead:
If running on an Apple M1/M2 Mac, use this instead:

docker build --platform linux/amd64 -t seleniumbase .

#### 6. Run [the example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) with Chrome inside your Docker: (Once the test completes after a few seconds, you'll automatically exit the Docker shell)
M1/M2 Mac users should also see [StackOverflow.com/a/76586216/7058266](https://stackoverflow.com/a/76586216/7058266) to **Enable Rosetta in Docker Desktop**. (Otherwise **you will** encounter errors like this when Chrome tries to launch: `"Chrome failed to start: crashed."`)

docker run seleniumbase ./run_docker_test_in_chrome.sh

#### 7. Now run the same test with Firefox inside your Docker:
#### 4. Run [the example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) with Chrome inside your Docker: (Once the test completes after a few seconds, you'll automatically exit the Docker shell)

docker run seleniumbase ./run_docker_test_in_firefox.sh
docker run seleniumbase ./run_docker_test_in_chrome.sh

#### 8. You can also enter Docker and stay inside the shell:
#### 5. You can also enter Docker and stay inside the shell:

docker run -i -t seleniumbase

#### 9. Now you can run the example test from inside the Docker shell:
#### 6. Now you can run the example test from inside the Docker shell:

./run_docker_test_in_chrome.sh

#### 10. When you're satisfied, you may exit the Docker shell:
#### 7. When you're satisfied, you may exit the Docker shell:

exit

#### 11. (Optional) Since Docker images and containers take up a lot of space, you may want to clean up your machine from time to time when they’re not being used:
#### 8. (Optional) Since Docker images and containers take up a lot of space, you may want to clean up your machine from time to time when they’re not being used:

Details on that can be found here:
http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers
Expand All @@ -67,15 +53,10 @@ If you want to completely remove all of your Docker containers and images, use t
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -q)

Finally, if you want to wipe out your SeleniumBase Docker virtualbox, use these commands:

docker-machine kill seleniumbase
docker-machine rm seleniumbase

For more cleanup commands, check out:
https://codefresh.io/blog/everyday-hacks-docker/

#### 13. (Optional) More reading on Docker can be found here:
#### 9. (Optional) More reading on Docker can be found here:
* https://docs.docker.com
* https://docs.docker.com/get-started/
* https://docs.docker.com/docker-for-mac/
3 changes: 0 additions & 3 deletions integrations/docker/docker_config.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions integrations/docker/run_docker_test_in_firefox.sh

This file was deleted.

2 changes: 1 addition & 1 deletion mkdocs_build/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

regex>=2023.12.25
pymdown-extensions>=10.7.1
pipdeptree>=2.18.0
pipdeptree>=2.18.1
python-dateutil>=2.8.2
Markdown==3.6
markdown2==2.4.13
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pip>=24.0
packaging>=24.0
setuptools>=68.0.0;python_version<"3.8"
setuptools>=69.2.0;python_version>="3.8"
setuptools>=69.5.1;python_version>="3.8"
wheel>=0.42.0;python_version<"3.8"
wheel>=0.43.0;python_version>="3.8"
attrs>=23.2.0
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.25.3"
__version__ = "4.25.4"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
'pip>=24.0',
'packaging>=24.0',
'setuptools>=68.0.0;python_version<"3.8"',
'setuptools>=69.2.0;python_version>="3.8"',
'setuptools>=69.5.1;python_version>="3.8"',
'wheel>=0.42.0;python_version<"3.8"',
'wheel>=0.43.0;python_version>="3.8"',
'attrs>=23.2.0',
Expand Down