Skip to content
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

Suggestion: Dockerization #15

Open
tomek7667 opened this issue Feb 26, 2024 · 1 comment
Open

Suggestion: Dockerization #15

tomek7667 opened this issue Feb 26, 2024 · 1 comment

Comments

@tomek7667
Copy link

I would be most appreciative if an example in docs or in practical implementation would be shown on how to run code from the library inside a docker container (preferably with docker-compose).

When running it on a desktop computer seems no problem at all, I have spent an entire day on trying to dockerize the lib but I still didn't manage to run it on a ubuntu server.

@tomek7667
Copy link
Author

If anyone struggle with similar issue, I have managed to setup the containerization properly and this is my Dockerfile:

FROM python:3.11

USER root

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
    apt-get install -y --no-install-recommends wget gnupg2 curl libssl-dev openssl \
    && rm -rf /var/lib/apt/lists/
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 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

COPY main.py /app/main.py
COPY lidlplus /app/lidlplus
COPY requirements.txt /app/requirements.txt
WORKDIR /app

# RUN pip3 install selenium webdriver_manager getuseragent oic selenium-wire pocketbase
RUN pip3 install -r requirements.txt --no-cache-dir
# print "Hello world"
RUN bash -c 'echo "Hello world"'

CMD ["python3", "main.py"]

I had to also change the lidl-plus source code a little bit. The api.py file, method _init_chrome:

	def _init_chrome(self, headless=True):
		user_agent = UserAgent(self._OS.lower()).Random()
		logging.getLogger("WDM").setLevel(logging.CRITICAL)
		options = webdriver.ChromeOptions()
		options.add_argument("--headless")
		options.add_argument("--no-sandbox")
		options.add_experimental_option("mobileEmulation", {"userAgent": user_agent})
		service = Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE).install())
		chrm = webdriver.Chrome(service=service, options=options)
		return chrm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant