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

Example Dockerfile with Pylenium #91

Open
ElSnoMan opened this issue May 11, 2020 · 2 comments
Open

Example Dockerfile with Pylenium #91

ElSnoMan opened this issue May 11, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@ElSnoMan
Copy link
Owner

ElSnoMan commented May 11, 2020

Description

Like the name suggests, we need to create some Dockerfile documentation. Users have requested that we add documentation for "What does a Dockerfile look like for my repo that uses Pylenium?"

This will be helpful for Users looking to containerize their Test Automation Solution 😄

We could probably just add it to the TESTING or GUIDES section of the documentation found here:

https://elsnoman.gitbook.io/pylenium/

@ElSnoMan ElSnoMan added documentation Improvements or additions to documentation enhancement New feature or request and removed enhancement New feature or request labels May 11, 2020
@ElSnoMan ElSnoMan added hacktoberfest-accepted Hacktoberfest! and removed hacktoberfest-accepted Hacktoberfest! labels Oct 6, 2020
@HoverHell
Copy link
Contributor

I propose an example Dockerfile like this:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND="teletype" \
    DEBIAN_FRONTEND=noninteractive \
    INITRD=no \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1

RUN echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen && \
    apt-get -y update && \
    apt-get dist-upgrade -y --no-install-recommends -o Dpkg::Options::="--force-confold" && \
    apt-get -y install \
        language-pack-en \
        firefox-geckodriver tigervnc-standalone-server python3 python3-dev python3-pip && \
    locale-gen en_US && update-locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

ENV LANG="en_US.UTF-8" \
    LANGUAGE="en_US:en" \
    LC_ALL="en_US.UTF-8"

RUN pip3 install --upgrade pip setuptools wheel && \
    pip3 install --upgrade pyleniumio pyvirtualdisplay && \
    rm -rf /root/.cache

and an example script for running inside it:

#!/usr/bin/env python3

import contextlib
import logging

import pylenium.config  # `pip install pyleniumio`
import pylenium.driver
import pyvirtualdisplay


@contextlib.contextmanager
def manage_pylenium():
    manage_display = pyvirtualdisplay.Display(
        backend="xvnc",
        rfbport=5910,
        size=(1920, 1080),
        visible=False,
    )
    pylenium_cfg = pylenium.config.PyleniumConfig(
        driver=dict(
            browser="firefox",
        ),
        viewport=dict(width=1920, height=1080),
    )
    with manage_display:  # sets `os.environ["DISPLAY"]`
        pyle = pylenium.driver.Pylenium(pylenium_cfg)
        pyle.init_webdriver()
        yield pyle


def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    with manage_pylenium() as pyle:
        pyle.visit('https://example.com')
        page_html = pyle.webdriver.page_source
    print("Page size:", len(page_html))


if __name__ == '__main__':
    main()

@eformo
Copy link

eformo commented May 31, 2022

Here's mine:

FROM python:3.9.10-slim-bullseye

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /app

RUN apt-get update && apt-get upgrade -y && apt-get install -y gcc

COPY conf/pip.conf /etc/pip.conf
COPY requirements.txt .

RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements.txt
RUN adduser --disabled-password simpleuser
RUN chown simpleuser:simpleuser /app

COPY --chown=simpleuser:simpleuser . .
USER qauser

RUN mkdir test_artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants