Skip to content

Commit 071c39d

Browse files
Merge pull request #166 from umihico/2023-05-20-154139
PR:Version Updates Sat May 20 15:41:39 UTC 2023
2 parents 3f13572 + 8588b5e commit 071c39d

File tree

4 files changed

+188
-10
lines changed

4 files changed

+188
-10
lines changed

.github/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Github Actions
2+
3+
## Test CI locally
4+
5+
```bash
6+
act \
7+
--secret AWS_ACCESS_KEY_ID \
8+
--secret AWS_SECRET_ACCESS_KEY \
9+
--secret AWS_REGION \
10+
--job auto-update
11+
```
12+
13+
## Test in forked repository
14+
15+
### Set secrets before running
16+
17+
```bash
18+
gh secret set AWS_ACCESS_KEY_ID --body "$AWS_ACCESS_KEY_ID";
19+
gh secret set AWS_SECRET_ACCESS_KEY --body "$AWS_SECRET_ACCESS_KEY";
20+
gh secret set AWS_REGION --body "$AWS_REGION";
21+
gh secret set DOCKER_USERNAME --body "$DOCKER_USERNAME";
22+
gh secret set DOCKER_PASSWORD --body "$DOCKER_PASSWORD";
23+
```

.github/workflows/auto-update.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: auto-update
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
push:
7+
branches:
8+
- feat/github-actions
9+
10+
jobs:
11+
auto-update:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Install serverless
18+
run: npm install -g serverless
19+
- name: Note docker image digest
20+
id: docker-image-digest
21+
run: |
22+
docker pull public.ecr.aws/lambda/python:latest
23+
SHA256_DIGEST=$(docker inspect public.ecr.aws/lambda/python:latest | jq -r '.[0].RepoDigests[0] | split(":") | .[1]' )
24+
echo "SHA256_DIGEST=${SHA256_DIGEST}" >> $GITHUB_OUTPUT
25+
- name: Note Chromium versions
26+
id: chromium-versions
27+
run: |
28+
WHOLE_JSON=$(curl https://omahaproxy.appspot.com/all.json)
29+
JSON=$(echo $WHOLE_JSON | jq -r '.[] | select(.os=="linux") | .versions[] | select(.channel=="stable")')
30+
CHANNEL="stable"
31+
POSITION=$(echo $JSON | jq -r '.branch_base_position')
32+
if (( POSITION < 900000 )); then
33+
JSON=$(echo $WHOLE_JSON | jq -r '.[] | select(.os=="linux") | .versions[] | select(.channel=="beta")')
34+
CHANNEL="beta"
35+
POSITION=$(echo $JSON | jq -r '.branch_base_position')
36+
echo "CHANNEL=${CHANNEL}" >> $GITHUB_OUTPUT
37+
fi
38+
39+
MAJOR_VERSION=$(echo $JSON | jq -r '.version | split(".") | .[0]')
40+
echo "MAJOR_VERSION=${MAJOR_VERSION}" >> $GITHUB_OUTPUT
41+
42+
for _ in {1..100}; do
43+
DOWNLOAD_URL="https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${POSITION}%2Fchrome-linux.zip?alt=media"
44+
curl -I $DOWNLOAD_URL | head -1 | grep -q 404 || break
45+
POSITION=$(($POSITION-1))
46+
sleep 1
47+
done
48+
49+
echo "POSITION=${POSITION}" >> $GITHUB_OUTPUT
50+
- name: Note chromedriver version
51+
id: chromedriver-version
52+
run: |
53+
MAJOR_VERSION=${{ steps.chromium-versions.outputs.MAJOR_VERSION }}
54+
DRIVER_VERSION=$(curl "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${MAJOR_VERSION}")
55+
echo "DRIVER_VERSION=${DRIVER_VERSION}" >> $GITHUB_OUTPUT
56+
- name: Update Dockerfile
57+
run: |
58+
SHA256_DIGEST=${{ steps.docker-image-digest.outputs.SHA256_DIGEST }}
59+
POSITION=${{ steps.chromium-versions.outputs.POSITION }}
60+
DRIVER_VERSION=${{ steps.chromedriver-version.outputs.DRIVER_VERSION }}
61+
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
62+
- name: Deploy
63+
run: sls deploy
64+
env:
65+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
67+
AWS_REGION: ${{ secrets.AWS_REGION }}
68+
- name: Note chrome version
69+
id: chrome-version
70+
run: |
71+
CHROME_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img /opt/chrome/chrome --version | awk '{print $2}' | sed -e 's/^[[:space:]]*//')
72+
echo "CHROME_VERSION=${CHROME_VERSION}" >> $GITHUB_OUTPUT
73+
- name: Note selenium version
74+
id: selenium-version
75+
run: |
76+
SELENIUM_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img pip freeze | grep selenium | awk -F "==" '{print $2}')
77+
echo "SELENIUM_VERSION=${SELENIUM_VERSION}" >> $GITHUB_OUTPUT
78+
- name: Note python version
79+
id: python-version
80+
run: |
81+
PYTHON_VERSION=$(docker run --rm --entrypoint '' serverless-docker-selenium-lambda-prod:img python -V | awk '{print $2}')
82+
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_OUTPUT
83+
- name: Invoke
84+
id: invoke
85+
run: sls invoke -f demo > /tmp/scraping-result.txt
86+
env:
87+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
88+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
89+
AWS_REGION: ${{ secrets.AWS_REGION }}
90+
- name: Archive result
91+
uses: actions/upload-artifact@v3
92+
if: ${{ !env.ACT }}
93+
with:
94+
name: scraping-result
95+
path: /tmp/scraping-result.txt
96+
- name: Test
97+
run: cat /tmp/scraping-result.txt | grep -q "This domain is for use in illustrative examples in documents"
98+
- name: Update README
99+
run: |
100+
CHROME_VERSION=${{ steps.chrome-version.outputs.CHROME_VERSION }}
101+
DRIVER_VERSION=${{ steps.chromedriver-version.outputs.DRIVER_VERSION }}
102+
SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}
103+
PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}
104+
sed -r "s/- chromium [0-9.]+/- chromium ${CHROME_VERSION}/g; s/- chromedriver [0-9.]+/- chromedriver ${DRIVER_VERSION}/g; s/- selenium [0-9.]+/- selenium ${SELENIUM_VERSION}/g; s/- Python [0-9.]+/- Python ${PYTHON_VERSION}/g" -i README.md
105+
- name: Detect changes
106+
id: detect-changes
107+
run: |
108+
DO_RELEASE="yes"
109+
git --no-pager diff --name-only | grep -q "README.md" || DO_RELEASE="no"
110+
git --no-pager diff --name-only | grep -q "Dockerfile" || DO_RELEASE="no"
111+
echo "DO_RELEASE=${DO_RELEASE}" >> $GITHUB_OUTPUT
112+
- name: Setup git config
113+
run: |
114+
# https://qiita.com/thaim/items/3d1a4d09ec4a7d8844ce
115+
git config user.name "github-actions[bot]"
116+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
117+
- name: Release
118+
if: ${{ steps.detect-changes.outputs.DO_RELEASE == 'yes' && !env.ACT }}
119+
run: |
120+
BRANCH=$(date +%Y-%m-%d-%H%M%S)
121+
TITLE="Version Updates $(date)"
122+
git checkout -b $BRANCH
123+
git add Dockerfile README.md
124+
echo "SHA256_DIGEST=${{ steps.docker-image-digest.outputs.SHA256_DIGEST }}" > /tmp/body-text.txt
125+
echo "POSITION=${{ steps.chromium-versions.outputs.POSITION }}" >> /tmp/body-text.txt
126+
echo "DRIVER_VERSION=${{ steps.chromedriver-version.outputs.DRIVER_VERSION }}" >> /tmp/body-text.txt
127+
echo "PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}" >> /tmp/body-text.txt
128+
echo "SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}" >> /tmp/body-text.txt
129+
echo "CHROME_VERSION=${{ steps.chrome-version.outputs.CHROME_VERSION }}" >> /tmp/body-text.txt
130+
echo "\n```diff\n$(git diff --staged)\n```" >> /tmp/body-text.txt
131+
git commit -m "${TITLE}"
132+
git push --set-upstream origin $BRANCH
133+
gh pr create --body-file /tmp/body-text.txt --title "PR:${TITLE}"
134+
gh pr merge --delete-branch --merge $BRANCH
135+
gh release create $BRANCH --notes-file /tmp/body-text.txt --title "${TITLE}"
136+
env:
137+
GH_TOKEN: ${{ github.token }}
138+
- name: Publish image
139+
if: ${{ steps.detect-changes.outputs.DO_RELEASE == 'yes' && !env.ACT }}
140+
run: |
141+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
142+
PYTHON_VERSION=${{ steps.python-version.outputs.PYTHON_VERSION }}
143+
SELENIUM_VERSION=${{ steps.selenium-version.outputs.SELENIUM_VERSION }}
144+
CHROME_VERSION=${{ steps.chrome-version.outputs.CHROME_VERSION }}
145+
MAJOR_PYTHON_VERSION=$(echo $PYTHON_VERSION | cut -d "." -f 1)
146+
MINOR_PYTHON_VERSION=$(echo $PYTHON_VERSION | cut -d "." -f 2)
147+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:latest
148+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${MAJOR_PYTHON_VERSION}
149+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${MAJOR_PYTHON_VERSION}.${MINOR_PYTHON_VERSION}
150+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}
151+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-selenium${SELENIUM_VERSION}
152+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-chrome${CHROME_VERSION}
153+
docker image tag serverless-docker-selenium-lambda-prod:img umihico/aws-lambda-selenium-python:${PYTHON_VERSION}-selenium${SELENIUM_VERSION}-chrome${CHROME_VERSION}
154+
docker image push --all-tags umihico/aws-lambda-selenium-python

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM public.ecr.aws/lambda/python@sha256:ac758b6345b677eb6e72c2cd0f71c182eca773da5db1e17835a4ffef46dbc997 as build
1+
FROM public.ecr.aws/lambda/python@sha256:75fc5649fde271db33378885fdbfd7bf6c153b1d642d895053036b272a8160b4 as build
22
RUN yum install -y unzip && \
3-
curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/111.0.5563.64/chromedriver_linux64.zip" && \
4-
curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1097615%2Fchrome-linux.zip?alt=media" && \
3+
curl -Lo "/tmp/chromedriver.zip" "https://chromedriver.storage.googleapis.com/113.0.5672.63/chromedriver_linux64.zip" && \
4+
curl -Lo "/tmp/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1121454%2Fchrome-linux.zip?alt=media" && \
55
unzip /tmp/chromedriver.zip -d /opt/ && \
66
unzip /tmp/chrome-linux.zip -d /opt/
77

8-
FROM public.ecr.aws/lambda/python@sha256:ac758b6345b677eb6e72c2cd0f71c182eca773da5db1e17835a4ffef46dbc997
8+
FROM public.ecr.aws/lambda/python@sha256:75fc5649fde271db33378885fdbfd7bf6c153b1d642d895053036b272a8160b4
99
RUN yum install atk cups-libs gtk3 libXcomposite alsa-lib \
1010
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \
1111
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# docker-selenium-lambda
22

3-
This is minimum demo of headless chrome and selenium on container image on AWS Lambda
3+
![badge](https://github.com/umihico/docker-selenium-lambda/actions/workflows/auto-update.yml/badge.svg)
44

5-
This image goes with these versions. [These are automatically updated and tested everyday. ![CircleCI](https://circleci.com/gh/umihico/docker-selenium-lambda/tree/circleci.svg?style=svg)](https://circleci.com/gh/umihico/docker-selenium-lambda/tree/circleci)
5+
This is minimum demo of headless chrome and selenium on container image on AWS Lambda
66

7-
- Python 3.10.9
8-
- chromium 111.0.5563.0
9-
- chromedriver 111.0.5563.64
10-
- selenium 4.8.2
7+
This image goes with these versions. [These are automatically updated and tested everyday.](https://github.com/umihico/docker-selenium-lambda/actions)
118

9+
- Python 3.10.11
10+
- chromium 113.0.5672.0
11+
- chromedriver 113.0.5672.63
12+
- selenium 4.9.1
1213

1314
## Running the demo
1415

0 commit comments

Comments
 (0)