Skip to content

Commit

Permalink
补充java环境
Browse files Browse the repository at this point in the history
  • Loading branch information
includeno committed Mar 6, 2023
1 parent fc84c0a commit 13ac495
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 2 deletions.
155 changes: 155 additions & 0 deletions .github/workflows/build_java_firefox_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# https://docs.github.com/en/actions/guides
# CI name , it will display on github's action page menu
name: Build Java Firefox Image
# trigger on which this CI should be run
on: # push operation is operate
push:
# here since my repository branch is named `main` , you should follow your own repository like `master`
branches: [main]
schedule:
- cron: "0 0 * * *"
release:
types: [published]
# CI enviroment settings
env:
TAG_NAME: "javafirefox"
jobs:
release:
name: 发布新版本
runs-on: ubuntu-latest # use latest ubuntu to run the job
permissions:
contents: write
outputs:
output1: ${{ steps.step1.outputs.firstword }}
output2: ${{ steps.step2.outputs.secondword }}
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
# here are some step followed , each step must have `uses` or `run` key , for CI to run
# other key like `name`,`with`,`env` is optional
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest requests
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Get latest version
run: |
python -m pip install requests
python latest_version_firefox.py
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: tail from FIREFOX_ESR_VERSION to GITHUB_ENV
run: tail ./FIREFOX_ESR_VERSION >> $GITHUB_ENV
- name: set tag GECKODRIVER_VERSION version
run: tail ./GECKODRIVER_VERSION >> $GITHUB_ENV
#zip the project files
- name: Zip project # This would actually build your project, using zip for an example artifact
run: |
zip -q -r firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip *
- name: check firefox_version
run: |
echo ${{env.FIREFOX_ESR_VERSION}}
- name: check geckodriver_version
run: |
echo ${{env.GECKODRIVER_VERSION}}
# https://github.com/marketplace/actions/create-release
- uses: ncipollo/release-action@v1
id: create_release
with:
tag: java_firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}
continue-on-error: false

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1 #https://github.com/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip
asset_name: firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip
asset_content_type: application/zip
continue-on-error: false

- name: The job has succeeded
id: success_step
if: ${{ steps.create_release.outputs.upload_url }}
run: echo "result1=0" >> $GITHUB_OUTPUT && echo "::set-output name=my_output::success"
- name: The job has failed
id: failure_step
if: ${{ failure() }}
run: echo "result2=1" >> $GITHUB_OUTPUT && echo "::set-output name=my_output::failure" # job1 将失败
build:
name: 新版本已建立,构建,发布镜像
needs: release
if: ${{ needs.release.my_output == 'success' }}
runs-on: ubuntu-latest # use latest ubuntu to run the job
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
strategy:
matrix:
java_version: ["11.0.16","11.0-jdk","17.0.2-jdk","17.0.2", "17.0-jdk","8u342-jdk","8u342" ]
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
# here are some step followed , each step must have `uses` or `run` key , for CI to run
# other key like `name`,`with`,`env` is optional
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest requests
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Get latest version
run: |
python -m pip install requests
python latest_version_firefox.py
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: tail from FIREFOX_ESR_VERSION to GITHUB_ENV
run: tail ./FIREFOX_ESR_VERSION >> $GITHUB_ENV
- name: set tag GECKODRIVER_VERSION version
run: tail ./GECKODRIVER_VERSION >> $GITHUB_ENV

- name: check firefox_version
run: |
echo ${{env.FIREFOX_ESR_VERSION}}
- name: check geckodriver_version
run: |
echo ${{env.GECKODRIVER_VERSION}}
- name: check java_version
run: |
echo ${{matrix.java_version}}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
#版本号第一位不允许空格 https://github.com/docker/build-push-action
- name: Push to Docker Hub
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
file: ./java/Dockerfile
#构造环境变量传入list https://github.com/docker/build-push-action
build-args: |
JAVA_VERSION=${{matrix.java_version}}
FIREFOX_ESR_VERSION=${{env.FIREFOX_ESR_VERSION}}
GECKODRIVER_VERSION=${{env.GECKODRIVER_VERSION}}
# tag 不允许出现-
tags: "includeno/${{ env.TAG_NAME }}:${{matrix.java_version}}.latest,includeno/${{ env.TAG_NAME }}:${{matrix.java_version}}.firefox${{env.FIREFOX_ESR_VERSION}}"
push: true
- name: The job has succeeded
if: ${{ success() }}
run: echo "success"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.github.com/en/actions/guides
# CI name , it will display on github's action page menu
name: Build Python+Firefox Image
name: Build Python Firefox Image
# trigger on which this CI should be run
on: # push operation is operate
push:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- uses: ncipollo/release-action@v1
id: create_release
with:
tag: firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}
tag: python_firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}
continue-on-error: false

- name: Upload Release Asset
Expand Down Expand Up @@ -141,6 +141,7 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
file: ./python/Dockerfile
#构造环境变量传入list https://github.com/docker/build-push-action
build-args: |
PYTHON_VERSION=${{matrix.python_version}}
Expand Down
84 changes: 84 additions & 0 deletions java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
ARG JAVA_VERSION=11.0-jdk
FROM openjdk:${JAVA_VERSION}-slim-buster

WORKDIR /app

#debian https://packages.debian.org/bullseye/chromium
RUN apt-get update && apt-get install -y \
wget \
git \
unzip \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatomic1 \
libatspi2.0-0 \
libbrotli1 \
libc6 \
libexpat1 \
libflac8 \
libfontconfig1 \
libfreetype6 \
libjpeg62-turbo \
liblcms2-2 \
libminizip1 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
libcairo2 \
# libgtk-4-1 \
libnspr4 \
libnss3 \
libopenjp2-7 \
libopus0 \
libpng16-16 \
libpulse0 \
libsnappy1v5 \
libstdc++6 \
libwebp6 \
libwebpdemux2 \
libwebpmux3 \
libwoff1 \
libx11-6 \
libxcb1 \
libxcomposite1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxkbcommon0 \
libxml2 \
libxnvctrl0 \
libxrandr2 \
libxslt1.1 \
libxtst6 \
zlib1g \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils \
libu2f-udev \
libvulkan1 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libpango-1.0-0 \
libxshmfence1

ARG GECKODRIVER_VERSION=v0.32.2

# 安装 Firefox 和驱动
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl firefox-esr \
&& rm -fr /var/lib/apt/lists/* \
&& curl -L https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz | tar xz -C /usr/local/bin \
&& apt-get purge -y ca-certificates curl

# 设置无头模式
ENV MOZ_HEADLESS=1

84 changes: 84 additions & 0 deletions python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
ARG PYTHON_VERSION=3.9.16
FROM python:${PYTHON_VERSION}-slim-buster

WORKDIR /app

#debian https://packages.debian.org/bullseye/chromium
RUN apt-get update && apt-get install -y \
wget \
git \
unzip \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatomic1 \
libatspi2.0-0 \
libbrotli1 \
libc6 \
libexpat1 \
libflac8 \
libfontconfig1 \
libfreetype6 \
libjpeg62-turbo \
liblcms2-2 \
libminizip1 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
libcairo2 \
# libgtk-4-1 \
libnspr4 \
libnss3 \
libopenjp2-7 \
libopus0 \
libpng16-16 \
libpulse0 \
libsnappy1v5 \
libstdc++6 \
libwebp6 \
libwebpdemux2 \
libwebpmux3 \
libwoff1 \
libx11-6 \
libxcb1 \
libxcomposite1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxkbcommon0 \
libxml2 \
libxnvctrl0 \
libxrandr2 \
libxslt1.1 \
libxtst6 \
zlib1g \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils \
libu2f-udev \
libvulkan1 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libpango-1.0-0 \
libxshmfence1

ARG GECKODRIVER_VERSION=v0.32.2

# 安装 Firefox 和驱动
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl firefox-esr \
&& rm -fr /var/lib/apt/lists/* \
&& curl -L https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz | tar xz -C /usr/local/bin \
&& apt-get purge -y ca-certificates curl

# 设置无头模式
ENV MOZ_HEADLESS=1

0 comments on commit 13ac495

Please sign in to comment.