diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 9d7544b..60227a2 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -60,12 +60,17 @@ jobs: MAJOR_VERSION=${{ steps.chromium-versions.outputs.MAJOR_VERSION }} DRIVER_VERSION=$(curl "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${MAJOR_VERSION}") echo "DRIVER_VERSION=${DRIVER_VERSION}" >> $GITHUB_OUTPUT + - name: Update Selenium + id: selenium-version + run: | + echo "SELENIUM_VERSION=$(curl -s https://pypi.org/pypi/selenium/json | jq -r .info.version)" >> $GITHUB_OUTPUT - name: Update Dockerfile run: | SHA256_DIGEST=${{ steps.docker-image-digest.outputs.SHA256_DIGEST }} POSITION=${{ steps.chromium-versions.outputs.POSITION }} DRIVER_VERSION=${{ steps.chromedriver-version.outputs.DRIVER_VERSION }} - sed -r "s/public.ecr.aws\/lambda\/python[:@a-z0-9]+/public.ecr.aws\/lambda\/python\@sha256\:${SHA256_DIGEST}/g; s/chromedriver.storage.googleapis.com\/[0-9.]+/chromedriver.storage.googleapis.com\/${DRIVER_VERSION}/g; s/Linux_x64%2F[0-9]+%2Fchrome-linux.zip/Linux_x64%2F${POSITION}%2Fchrome-linux.zip/g" -i Dockerfile + SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }} + sed -r "s/public.ecr.aws\/lambda\/python[:@a-z0-9]+/public.ecr.aws\/lambda\/python\@sha256\:${SHA256_DIGEST}/g; s/chromedriver.storage.googleapis.com\/[0-9.]+/chromedriver.storage.googleapis.com\/${DRIVER_VERSION}/g; s/Linux_x64%2F[0-9]+%2Fchrome-linux.zip/Linux_x64%2F${POSITION}%2Fchrome-linux.zip/g; s/selenium==[0-9\.]*/selenium==${SELENIUM_VERSION}/g" -i Dockerfile - name: Deploy run: sls deploy env: @@ -77,11 +82,6 @@ jobs: run: | CHROME_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img /opt/chrome/chrome --version | awk '{print $2}' | sed -e 's/^[[:space:]]*//') echo "CHROME_VERSION=${CHROME_VERSION}" >> $GITHUB_OUTPUT - - name: Note selenium version - id: selenium-version - run: | - SELENIUM_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img pip freeze | grep selenium | awk -F "==" '{print $2}') - echo "SELENIUM_VERSION=${SELENIUM_VERSION}" >> $GITHUB_OUTPUT - name: Note python version id: python-version run: | diff --git a/Dockerfile b/Dockerfile index 9ac3cd2..832613a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ -FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67 as build +FROM public.ecr.aws/lambda/python@sha256:489d4abc8644060e2e16db2ffaaafa157359761feaf9438bf26ed88e37e43d9c as build RUN yum install -y unzip && \ curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip" && \ curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1135561%2Fchrome-linux.zip?alt=media" && \ unzip /tmp/chromedriver.zip -d /opt/ && \ unzip /tmp/chrome-linux.zip -d /opt/ -FROM public.ecr.aws/lambda/python@sha256:10dbb67ede15b5fd516be87dd71c3f7968904b0b840235720486476b34ef9b67 +FROM public.ecr.aws/lambda/python@sha256:489d4abc8644060e2e16db2ffaaafa157359761feaf9438bf26ed88e37e43d9c RUN yum install atk cups-libs gtk3 libXcomposite alsa-lib \ libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \ libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \ xorg-x11-xauth dbus-glib dbus-glib-devel -y -RUN pip install selenium==4.9.1 +RUN pip install selenium==4.11.2 COPY --from=build /opt/chrome-linux /opt/chrome COPY --from=build /opt/chromedriver /opt/ COPY main.py ./ diff --git a/README.md b/README.md index 9cdc5f4..344a795 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ This image goes with these versions. [These are automatically updated and tested - Python 3.11.4 - chromium 114.0.5735.0 - chromedriver 114.0.5735.90 -- selenium 4.9.1 +- selenium 4.11.2 ## Running the demo diff --git a/main.py b/main.py index 05c6ab9..2ec4e50 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,8 @@ def handler(event=None, context=None): options = webdriver.ChromeOptions() + service = webdriver.ChromeService("/opt/chromedriver") + options.binary_location = '/opt/chrome/chrome' options.add_argument('--headless') options.add_argument('--no-sandbox') @@ -18,7 +20,8 @@ def handler(event=None, context=None): options.add_argument(f"--data-path={mkdtemp()}") options.add_argument(f"--disk-cache-dir={mkdtemp()}") options.add_argument("--remote-debugging-port=9222") - chrome = webdriver.Chrome("/opt/chromedriver", - options=options) + + chrome = webdriver.Chrome(options=options, service=service) chrome.get("https://example.com/") + return chrome.find_element(by=By.XPATH, value="//html").text