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

Multi platform docker build #201

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
185 changes: 185 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---

name: build
on:
push:
branches:
- master
pull_request:

env:
IMAGE_REPOSITORY: zenika/alpine-chrome
IMAGE_TAG: latest

jobs:
docker:
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
context:
- folder: .
tag: latest
- folder: with-node
tag: with-node
- folder: with-deno
tag: with-deno
- folder: with-chromedriver
tag: with-chromedriver
- folder: with-playwright # needs with-node
tag: with-playwright
- folder: with-puppeteer # needs with-node
tag: with-puppeteer
- folder: with-puppeteer-xvfb # needs with-puppeteer
tag: with-puppeteer-xvfb
- folder: with-selenoid # needs with-chromedriver
tag: with-selenoid
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Get current date
id: date
run: |
echo "::set-output name=date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')"

- name: Build and export to Docker
uses: docker/build-push-action@v3
with:
context: ${{ matrix.context.folder }}
load: true
build-args: |
BUILD_DATE=${{ steps.date.outputs.date }}
VCS_REF=${{ github.sha }}
tags: ${{ env.IMAGE_REPOSITORY }}:${{ matrix.context.tag }}

- name: Test
env:
IMAGE_NAME: ${{ env.IMAGE_REPOSITORY }}:${{ matrix.context.tag }}
run: |
docker container run --rm --entrypoint '' ${IMAGE_NAME} cat /etc/alpine-release
docker container run --rm --entrypoint '' ${IMAGE_NAME} chromium-browser --version
mkdir src/ && chmod a+rwX src/
if [[ '${{ matrix.context.folder }}' == 'with-node' ]]; then
docker container run --rm --entrypoint '' ${IMAGE_NAME} node --version
elif [[ '${{ matrix.context.folder }}' == 'with-deno' ]]; then
docker container run --rm --entrypoint '' ${IMAGE_NAME} deno --version
elif [[ '${{ matrix.context.folder }}' == 'with-chromedriver' ]]; then
docker container run --rm --entrypoint '' ${IMAGE_NAME} chromedriver --version
elif [[ '${{ matrix.context.folder }}' == 'with-playwright' ]]; then
docker container run --rm --volume $PWD:/work --workdir /work ${IMAGE_NAME}
[ -f src/example-chromium.png ]
elif [[ '${{ matrix.context.folder }}' == 'with-puppeteer' ]]; then
docker container run --rm --volume $PWD:/work --workdir /work --cap-add=SYS_ADMIN ${IMAGE_NAME}
[ -f src/devfest.pdf ]
elif [[ '${{ matrix.context.folder }}' == 'with-puppeteer-xvfb' ]]; then
docker container run --rm --volume $PWD:/work --workdir /work --cap-add=SYS_ADMIN ${IMAGE_NAME}
[ -f src/screenshot.png ]
elif [[ '${{ matrix.context.folder }}' == 'with-selenoid' ]]; then
docker container run --rm --entrypoint '' ${IMAGE_NAME} selenoid -version
fi

- name: Compute versioned tag
if: ${{ github.event_name == 'push' }}
id: tag
env:
IMAGE_NAME: ${{ env.IMAGE_REPOSITORY }}:${{ matrix.context.tag }}
CHROMIUM_VERSION_REGEXP: 'Chromium ([0-9]+)\.'
CHROMEDRIVER_VERSION_REGEXP: 'ChromeDriver ([0-9]+)\.'
run: |
CURRENT_CHROMIUM_VERSION=$(docker container run --rm --entrypoint '' ${IMAGE_NAME} chromium-browser --version)
if [[ ${CURRENT_CHROMIUM_VERSION} =~ ${CHROMIUM_VERSION_REGEXP} ]]; then
echo "ℹ Successfully extracted Chromium major version of ${BASH_REMATCH[1]} from '${CURRENT_CHROMIUM_VERSION}'"
else
echo "❌ Cannot extract Chromium major version from '${CURRENT_CHROMIUM_VERSION}'" >&2
exit 1
fi
CHROMIUM_VERSION=${BASH_REMATCH[1]}
TAG=${CHROMIUM_VERSION}
if [[ '${{ matrix.context.folder }}' != '.' ]]; then
TAG=${TAG}-${{ matrix.context.tag }}
fi
if [[ '${{ matrix.context.folder }}' == 'with-chromedriver' ]]; then
CURRENT_CHROMEDRIVER_VERSION=$(docker container run --rm --entrypoint "" ${IMAGE_NAME} chromedriver --version)
if [[ ${CURRENT_CHROMEDRIVER_VERSION} =~ ${CHROMEDRIVER_VERSION_REGEXP} ]]; then
CHROMEDRIVER_MAJOR_VERSION=${BASH_REMATCH[1]}
fi
if [ "${CHROMIUM_VERSION}" != "${CHROMEDRIVER_MAJOR_VERSION}" ]; then
echo "Skipping image pushing because of incompatible chromium (${CHROMIUM_VERSION}) and chromedriver (${CHROMEDRIVER_MAJOR_VERSION}) versions" >&2
exit 1
fi
elif [[ '${{ matrix.context.folder }}' == 'with-selenoid' ]]; then
CURRENT_SELENOID_VERSION=$(docker container run --rm --entrypoint "" ${IMAGE_NAME} selenoid -version)
TAG=${TAG}-${CURRENT_SELENOID_VERSION:14:4}
fi
echo "::set-output name=value::${TAG}"

- name: Login to DockerHub
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GCR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key_base64
password: ${{ secrets.GCR_JSON_KEY }}

- name: Login to US GCR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: us.gcr.io
username: _json_key_base64
password: ${{ secrets.GCR_JSON_KEY }}

- name: Login to EU GCR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: eu.gcr.io
username: _json_key_base64
password: ${{ secrets.GCR_JSON_KEY }}

- name: Login to Asia GCR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: asia.gcr.io
username: _json_key_base64
password: ${{ secrets.GCR_JSON_KEY }}

- name: Build and push
if: ${{ github.event_name == 'push' }}
env:
IMAGE_NAME: ${{ env.IMAGE_REPOSITORY }}:${{ matrix.context.tag }}
IMAGE_VERSIONED_NAME: ${{ env.IMAGE_REPOSITORY }}:${{ steps.tag.outputs.value }}
uses: docker/build-push-action@v3
with:
context: ${{ matrix.context.folder }}
platforms: linux/amd64,linux/arm64
build-args: |
BUILD_DATE=${{ steps.date.outputs.date }}
VCS_REF=${{ github.sha }}
tags: |
${{ env.IMAGE_NAME }}
${{ env.IMAGE_VERSIONED_NAME }}
gcr.io/zenika-hub/${{ env.IMAGE_NAME }}
gcr.io/zenika-hub/${{ env.IMAGE_VERSIONED_NAME }}
us.gcr.io/zenika-hub/${{ env.IMAGE_NAME }}
us.gcr.io/zenika-hub/${{ env.IMAGE_VERSIONED_NAME }}
eu.gcr.io/zenika-hub/${{ env.IMAGE_NAME }}
eu.gcr.io/zenika-hub/${{ env.IMAGE_VERSIONED_NAME }}
asia.gcr.io/zenika-hub/${{ env.IMAGE_NAME }}
asia.gcr.io/zenika-hub/${{ env.IMAGE_VERSIONED_NAME }}
push: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![GitHub Stars](https://img.shields.io/github/stars/zenika/alpine-chrome)](https://github.com/Zenika/alpine-chrome/) [![Docker Build Status](https://img.shields.io/docker/cloud/build/zenika/alpine-chrome.svg)](https://hub.docker.com/r/zenika/alpine-chrome/) [![Docker Pulls](https://img.shields.io/docker/pulls/zenika/alpine-chrome.svg)](https://hub.docker.com/r/zenika/alpine-chrome/) [![Docker Stars](https://img.shields.io/docker/stars/zenika/alpine-chrome.svg)](https://hub.docker.com/r/zenika/alpine-chrome/)
[![GitHub Stars](https://img.shields.io/github/stars/zenika/alpine-chrome)](https://github.com/Zenika/alpine-chrome/) [![Docker Build Status](https://img.shields.io/github/workflow/status/zenika/alpine-chrome/build.svg)](https://hub.docker.com/r/zenika/alpine-chrome/) [![Docker Pulls](https://img.shields.io/docker/pulls/zenika/alpine-chrome.svg)](https://hub.docker.com/r/zenika/alpine-chrome/) [![Docker Stars](https://img.shields.io/docker/stars/zenika/alpine-chrome.svg)](https://hub.docker.com/r/zenika/alpine-chrome/)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-39-orange.svg?style=flat-square)](#-contributors)
Expand Down
4 changes: 0 additions & 4 deletions hooks/build

This file was deleted.

33 changes: 0 additions & 33 deletions hooks/post_push

This file was deleted.

10 changes: 0 additions & 10 deletions hooks/test

This file was deleted.

30 changes: 0 additions & 30 deletions with-chromedriver/hooks/post_push

This file was deleted.

23 changes: 0 additions & 23 deletions with-node/hooks/post_push

This file was deleted.

2 changes: 1 addition & 1 deletion with-playwright/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ COPY --chown=chrome package.json package-lock.json ./
RUN npm install
COPY --chown=chrome . ./
ENTRYPOINT ["tini", "--"]
CMD ["node", "src/useragent"]
CMD ["node", "/usr/src/app/src/useragent"]
19 changes: 0 additions & 19 deletions with-playwright/hooks/post_push

This file was deleted.

2 changes: 1 addition & 1 deletion with-puppeteer-xvfb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ENV DISPLAY :99
COPY --chown=chrome . ./
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]
CMD ["node", "src/extension.js"]
CMD ["node", "/usr/src/app/src/extension.js"]
19 changes: 0 additions & 19 deletions with-puppeteer-xvfb/hooks/post_push

This file was deleted.

2 changes: 1 addition & 1 deletion with-puppeteer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ COPY --chown=chrome package.json package-lock.json ./
RUN npm install
COPY --chown=chrome . ./
ENTRYPOINT ["tini", "--"]
CMD ["node", "src/pdf"]
CMD ["node", "/usr/src/app/src/pdf"]
19 changes: 0 additions & 19 deletions with-puppeteer/hooks/post_push

This file was deleted.

23 changes: 0 additions & 23 deletions with-selenoid/hooks/post_push

This file was deleted.